Skip to content

Commit

Permalink
feat: Add support for apiEndpoint and deprecate serviceAddress… (#2230)
Browse files Browse the repository at this point in the history
* [CHANGE ME] Re-generated WebRisk to pick up changes in the API or client library generator.

* Fix examples
  • Loading branch information
yoshi-automation authored and jdpedrie committed Aug 7, 2019
1 parent 367becf commit 8f12412
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
33 changes: 18 additions & 15 deletions WebRisk/src/V1beta1/Gapic/WebRiskServiceV1Beta1GapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
* calls that map to API methods. Sample code to get started:
*
* ```
* $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();
* $webRiskServiceV1Beta1Client = new Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client();
* try {
* $threatType = ThreatType::THREAT_TYPE_UNSPECIFIED;
* $constraints = new ComputeThreatListDiffRequest\Constraints();
* $threatType = Google\Cloud\WebRisk\V1beta1\ThreatType::THREAT_TYPE_UNSPECIFIED;
* $constraints = new Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest\Constraints();
* $response = $webRiskServiceV1Beta1Client->computeThreatListDiff($threatType, $constraints);
* } finally {
* $webRiskServiceV1Beta1Client->close();
Expand Down Expand Up @@ -97,7 +97,7 @@ private static function getClientDefaults()
{
return [
'serviceName' => self::SERVICE_NAME,
'serviceAddress' => self::SERVICE_ADDRESS.':'.self::DEFAULT_SERVICE_PORT,
'apiEndpoint' => self::SERVICE_ADDRESS.':'.self::DEFAULT_SERVICE_PORT,
'clientConfig' => __DIR__.'/../resources/web_risk_service_v1_beta1_client_config.json',
'descriptorsConfigPath' => __DIR__.'/../resources/web_risk_service_v1_beta1_descriptor_config.php',
'gcpApiConfigPath' => __DIR__.'/../resources/web_risk_service_v1_beta1_grpc_config.json',
Expand All @@ -119,6 +119,9 @@ private static function getClientDefaults()
* Optional. Options for configuring the service API wrapper.
*
* @type string $serviceAddress
* **Deprecated**. This option will be removed in a future major release. Please
* utilize the `$apiEndpoint` option instead.
* @type string $apiEndpoint
* The address of the API remote host. May optionally include the port, formatted
* as "<uri>:<port>". Default 'webrisk.googleapis.com:443'.
* @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials
Expand Down Expand Up @@ -146,7 +149,7 @@ private static function getClientDefaults()
* or `grpc`. Defaults to `grpc` if gRPC support is detected on the system.
* *Advanced usage*: Additionally, it is possible to pass in an already instantiated
* {@see \Google\ApiCore\Transport\TransportInterface} object. Note that when this
* object is provided, any settings in $transportConfig, and any $serviceAddress
* object is provided, any settings in $transportConfig, and any `$apiEndpoint`
* setting, will be ignored.
* @type array $transportConfig
* Configuration options that will be used to construct the transport. Options for
Expand Down Expand Up @@ -175,21 +178,21 @@ public function __construct(array $options = [])
*
* Sample code:
* ```
* $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();
* $webRiskServiceV1Beta1Client = new Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client();
* try {
* $threatType = ThreatType::THREAT_TYPE_UNSPECIFIED;
* $constraints = new ComputeThreatListDiffRequest\Constraints();
* $threatType = Google\Cloud\WebRisk\V1beta1\ThreatType::THREAT_TYPE_UNSPECIFIED;
* $constraints = new Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest\Constraints();
* $response = $webRiskServiceV1Beta1Client->computeThreatListDiff($threatType, $constraints);
* } finally {
* $webRiskServiceV1Beta1Client->close();
* }
* ```
*
* @param int $threatType Required. The ThreatList to update.
* For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1beta1\ThreatType}
* @param ComputeThreatListDiffRequest\Constraints $constraints The constraints associated with this request.
* @param array $optionalArgs {
* Optional.
* @param int $threatType Required. The ThreatList to update.
* For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1beta1\ThreatType}
* @param Constraints $constraints The constraints associated with this request.
* @param array $optionalArgs {
* Optional.
*
* @type string $versionToken
* The current version token of the client for the requested list (the
Expand Down Expand Up @@ -228,7 +231,7 @@ public function computeThreatListDiff($threatType, $constraints, array $optional
*
* Sample code:
* ```
* $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();
* $webRiskServiceV1Beta1Client = new Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client();
* try {
* $uri = '';
* $threatTypes = [];
Expand Down Expand Up @@ -279,7 +282,7 @@ public function searchUris($uri, $threatTypes, array $optionalArgs = [])
*
* Sample code:
* ```
* $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();
* $webRiskServiceV1Beta1Client = new Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client();
* try {
* $response = $webRiskServiceV1Beta1Client->searchHashes();
* } finally {
Expand Down
16 changes: 8 additions & 8 deletions WebRisk/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"updateTime": "2019-04-02T18:38:47.962347Z",
"updateTime": "2019-08-07T19:10:34.033660Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.16.22",
"dockerImage": "googleapis/artman@sha256:e7f9554322a8aa1416c122c918fdc4cdec8cfe816f027fc948dec0be7edef320"
"version": "0.29.1",
"dockerImage": "googleapis/artman@sha256:b2a73f4dda03ef8fcaa973e3ba26d0cf34091f6c22c70add663af325931aef4d"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "4b6f2b11e341b51d11442aa430fb15b888facc7a",
"internalRef": "241570196"
"sha": "3a1b46a6668194a527e532a2c355b404c79b0e6a",
"internalRef": "262167956"
}
}
],
"destinations": [
{
"client": {
"source": "googleapis",
"apiName": "talent",
"apiVersion": "v4beta1",
"apiName": "webrisk",
"apiVersion": "v1beta1",
"language": "php",
"generator": "gapic",
"config": "google/cloud/webrisk/artman_webrisk.yaml"
"config": "google/cloud/webrisk/artman_webrisk_v1beta1.yaml"
}
}
]
Expand Down
20 changes: 16 additions & 4 deletions WebRisk/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@
r'Copyright \d{4}',
r'Copyright 2019')

s.replace(
'src/V1beta1/Gapic/*.php',
r'ComputeThreatListDiffRequest_',
r'ComputeThreatListDiffRequest\\')
# Fix class references in gapic samples
for version in ['V1beta1']:
pathExpr = 'src/' + version + '/Gapic/WebRiskServiceV1Beta1GapicClient.php'

types = {
'new Constraints': r'new Google\\Cloud\\WebRisk\\' + version + r'\\ComputeThreatListDiffRequest\\Constraints',
'= ThreatType::': r'= Google\\Cloud\\WebRisk\\' + version + r'\\ThreatType::',
'= new WebRiskServiceV1Beta1Client': r'= new Google\\Cloud\\WebRisk\\' + version + r'\\WebRiskServiceV1Beta1Client'
}

for search, replace in types.items():
s.replace(
pathExpr,
search,
replace
)
20 changes: 14 additions & 6 deletions WebRisk/tests/Unit/V1beta1/WebRiskServiceV1Beta1ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use Google\ApiCore\CredentialsWrapper;
use Google\ApiCore\Testing\GeneratedTest;
use Google\ApiCore\Testing\MockTransport;
use Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest_Constraints;
use Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest\Constraints;
use Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffResponse;
use Google\Cloud\WebRisk\V1beta1\SearchHashesResponse;
use Google\Cloud\WebRisk\V1beta1\SearchUrisResponse;
Expand All @@ -50,15 +50,23 @@ private function createTransport($deserialize = null)
return new MockTransport($deserialize);
}

/**
* @return CredentialsWrapper
*/
private function createCredentials()
{
return $this->getMockBuilder(CredentialsWrapper::class)
->disableOriginalConstructor()
->getMock();
}

/**
* @return WebRiskServiceV1Beta1Client
*/
private function createClient(array $options = [])
{
$options += [
'credentials' => $this->getMockBuilder(CredentialsWrapper::class)
->disableOriginalConstructor()
->getMock(),
'credentials' => $this->createCredentials(),
];

return new WebRiskServiceV1Beta1Client($options);
Expand All @@ -82,7 +90,7 @@ public function computeThreatListDiffTest()

// Mock request
$threatType = ThreatType::THREAT_TYPE_UNSPECIFIED;
$constraints = new ComputeThreatListDiffRequest_Constraints();
$constraints = new Constraints();

$response = $client->computeThreatListDiff($threatType, $constraints);
$this->assertEquals($expectedResponse, $response);
Expand Down Expand Up @@ -126,7 +134,7 @@ public function computeThreatListDiffExceptionTest()

// Mock request
$threatType = ThreatType::THREAT_TYPE_UNSPECIFIED;
$constraints = new ComputeThreatListDiffRequest_Constraints();
$constraints = new Constraints();

try {
$client->computeThreatListDiff($threatType, $constraints);
Expand Down

0 comments on commit 8f12412

Please sign in to comment.