From d5629fcd4e0e1953a20055487b19a64bdcd65248 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 11:32:48 -0700 Subject: [PATCH] feat: [Eventarc] Add Provider resources (#5285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add Provider resources PiperOrigin-RevId: 449653329 Source-Link: https://github.com/googleapis/googleapis/commit/a167db13ec9e73c1f6812526d64c27dad1c71558 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4183d84217dec636dfc8acac8d991379ffe84c73 Copy-Tag: eyJwIjoiRXZlbnRhcmMvLk93bEJvdC55YW1sIiwiaCI6IjQxODNkODQyMTdkZWM2MzZkZmM4YWNhYzhkOTkxMzc5ZmZlODRjNzMifQ== * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- Eventarc/metadata/V1/Discovery.php | 44 ++++ Eventarc/metadata/V1/Eventarc.php | 27 ++- Eventarc/src/V1/EventType.php | 201 ++++++++++++++++ Eventarc/src/V1/EventarcGrpcClient.php | 30 +++ Eventarc/src/V1/FilteringAttribute.php | 178 ++++++++++++++ Eventarc/src/V1/Gapic/EventarcGapicClient.php | 180 ++++++++++++++ Eventarc/src/V1/GetProviderRequest.php | 67 ++++++ Eventarc/src/V1/ListProvidersRequest.php | 227 ++++++++++++++++++ Eventarc/src/V1/ListProvidersResponse.php | 139 +++++++++++ Eventarc/src/V1/Provider.php | 139 +++++++++++ Eventarc/src/V1/gapic_metadata.json | 10 + .../V1/resources/eventarc_client_config.json | 10 + .../resources/eventarc_descriptor_config.php | 10 + .../resources/eventarc_rest_client_config.php | 22 ++ Eventarc/tests/Unit/V1/EventarcClientTest.php | 140 +++++++++++ 15 files changed, 1419 insertions(+), 5 deletions(-) create mode 100644 Eventarc/metadata/V1/Discovery.php create mode 100644 Eventarc/src/V1/EventType.php create mode 100644 Eventarc/src/V1/FilteringAttribute.php create mode 100644 Eventarc/src/V1/GetProviderRequest.php create mode 100644 Eventarc/src/V1/ListProvidersRequest.php create mode 100644 Eventarc/src/V1/ListProvidersResponse.php create mode 100644 Eventarc/src/V1/Provider.php diff --git a/Eventarc/metadata/V1/Discovery.php b/Eventarc/metadata/V1/Discovery.php new file mode 100644 index 00000000000..e15c6352f9b --- /dev/null +++ b/Eventarc/metadata/V1/Discovery.php @@ -0,0 +1,44 @@ +internalAddGeneratedFile( + ' +ÿ +(google/cloud/eventarc/v1/discovery.protogoogle.cloud.eventarc.v1google/api/resource.proto"ñ +Provider +name ( BàA + display_name ( BàA= + event_types ( 2#.google.cloud.eventarc.v1.EventTypeBàA:xêAu + eventarc.googleapis.com/ProviderinternalAddGeneratedFile( ' -0 -\'google/cloud/eventarc/v1/eventarc.protogoogle.cloud.eventarc.v1google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.proto&google/cloud/eventarc/v1/channel.proto1google/cloud/eventarc/v1/channel_connection.proto&google/cloud/eventarc/v1/trigger.proto#google/longrunning/operations.proto google/protobuf/field_mask.protogoogle/protobuf/timestamp.proto"J +‚6 +\'google/cloud/eventarc/v1/eventarc.protogoogle.cloud.eventarc.v1google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.proto&google/cloud/eventarc/v1/channel.proto1google/cloud/eventarc/v1/channel_connection.proto(google/cloud/eventarc/v1/discovery.proto&google/cloud/eventarc/v1/trigger.proto#google/longrunning/operations.proto google/protobuf/field_mask.protogoogle/protobuf/timestamp.proto"J GetTriggerRequest5 name ( B\'àAúA! eventarc.googleapis.com/Trigger"‡ @@ -84,7 +85,21 @@ public static function initOnce() { DeleteChannelRequest5 name ( B\'àAúA! eventarc.googleapis.com/Channel - validate_only (BàA"^ + validate_only (BàA"L +GetProviderRequest6 +name ( B(àAúA" + eventarc.googleapis.com/Provider"™ +ListProvidersRequest8 +parent ( B(àAúA" eventarc.googleapis.com/Provider + page_size ( + +page_token (  +order_by (  +filter ( "| +ListProvidersResponse5 + providers ( 2".google.cloud.eventarc.v1.Provider +next_page_token (  + unreachable ( "^ GetChannelConnectionRequest? name ( B1àAúA+ )eventarc.googleapis.com/ChannelConnection"‰ @@ -111,7 +126,7 @@ public static function initOnce() { verb ( BàA status_message ( BàA# requested_cancellation (BàA - api_version ( BàA2™ + api_version ( BàA2ì Eventarc™ GetTrigger+.google.cloud.eventarc.v1.GetTriggerRequest!.google.cloud.eventarc.v1.Trigger";‚Óä“.,/v1/{name=projects/*/locations/*/triggers/*}ÚAname¬ @@ -130,7 +145,9 @@ public static function initOnce() { UpdateChannel..google.cloud.eventarc.v1.UpdateChannelRequest.google.longrunning.Operation"z‚Óä“?24/v1/{channel.name=projects/*/locations/*/channels/*}:channelÚAchannel,update_maskÊA ChannelOperationMetadataº DeleteChannel..google.cloud.eventarc.v1.DeleteChannelRequest.google.longrunning.Operation"Z‚Óä“.*,/v1/{name=projects/*/locations/*/channels/*}ÚAnameÊA -ChannelOperationMetadataÁ +ChannelOperationMetadata + GetProvider,.google.cloud.eventarc.v1.GetProviderRequest".google.cloud.eventarc.v1.Provider"<‚Óä“/-/v1/{name=projects/*/locations/*/providers/*}ÚAname° + ListProviders..google.cloud.eventarc.v1.ListProvidersRequest/.google.cloud.eventarc.v1.ListProvidersResponse">‚Óä“/-/v1/{parent=projects/*/locations/*}/providersÚAparentÁ GetChannelConnection5.google.cloud.eventarc.v1.GetChannelConnectionRequest+.google.cloud.eventarc.v1.ChannelConnection"E‚Óä“86/v1/{name=projects/*/locations/*/channelConnections/*}ÚAnameÔ ListChannelConnections7.google.cloud.eventarc.v1.ListChannelConnectionsRequest8.google.cloud.eventarc.v1.ListChannelConnectionsResponse"G‚Óä“86/v1/{parent=projects/*/locations/*}/channelConnectionsÚAparent¢ CreateChannelConnection8.google.cloud.eventarc.v1.CreateChannelConnectionRequest.google.longrunning.Operation"­‚Óä“L"6/v1/{parent=projects/*/locations/*}/channelConnections:channel_connectionÚA/parent,channel_connection,channel_connection_idÊA& diff --git a/Eventarc/src/V1/EventType.php b/Eventarc/src/V1/EventType.php new file mode 100644 index 00000000000..4a50bd9ba8a --- /dev/null +++ b/Eventarc/src/V1/EventType.php @@ -0,0 +1,201 @@ +google.cloud.eventarc.v1.EventType + */ +class EventType extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The full name of the event type (for example, + * "google.cloud.storage.object.v1.finalized"). In the form of + * {provider-specific-prefix}.{resource}.{version}.{verb}. Types MUST be + * versioned and event schemas are guaranteed to remain backward compatible + * within one version. Note that event type versions and API versions do not + * need to match. + * + * Generated from protobuf field string type = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $type = ''; + /** + * Output only. Human friendly description of what the event type is about. + * For example "Bucket created in Cloud Storage". + * + * Generated from protobuf field string description = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $description = ''; + /** + * Output only. Filtering attributes for the event type. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.FilteringAttribute filtering_attributes = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $filtering_attributes; + /** + * Output only. URI for the event schema. + * For example + * "https://github.com/googleapis/google-cloudevents/blob/master/proto/google/events/cloud/storage/v1/events.proto" + * + * Generated from protobuf field string event_schema_uri = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $event_schema_uri = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $type + * Output only. The full name of the event type (for example, + * "google.cloud.storage.object.v1.finalized"). In the form of + * {provider-specific-prefix}.{resource}.{version}.{verb}. Types MUST be + * versioned and event schemas are guaranteed to remain backward compatible + * within one version. Note that event type versions and API versions do not + * need to match. + * @type string $description + * Output only. Human friendly description of what the event type is about. + * For example "Bucket created in Cloud Storage". + * @type \Google\Cloud\Eventarc\V1\FilteringAttribute[]|\Google\Protobuf\Internal\RepeatedField $filtering_attributes + * Output only. Filtering attributes for the event type. + * @type string $event_schema_uri + * Output only. URI for the event schema. + * For example + * "https://github.com/googleapis/google-cloudevents/blob/master/proto/google/events/cloud/storage/v1/events.proto" + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\V1\Discovery::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The full name of the event type (for example, + * "google.cloud.storage.object.v1.finalized"). In the form of + * {provider-specific-prefix}.{resource}.{version}.{verb}. Types MUST be + * versioned and event schemas are guaranteed to remain backward compatible + * within one version. Note that event type versions and API versions do not + * need to match. + * + * Generated from protobuf field string type = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Output only. The full name of the event type (for example, + * "google.cloud.storage.object.v1.finalized"). In the form of + * {provider-specific-prefix}.{resource}.{version}.{verb}. Types MUST be + * versioned and event schemas are guaranteed to remain backward compatible + * within one version. Note that event type versions and API versions do not + * need to match. + * + * Generated from protobuf field string type = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setType($var) + { + GPBUtil::checkString($var, True); + $this->type = $var; + + return $this; + } + + /** + * Output only. Human friendly description of what the event type is about. + * For example "Bucket created in Cloud Storage". + * + * Generated from protobuf field string description = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Output only. Human friendly description of what the event type is about. + * For example "Bucket created in Cloud Storage". + * + * Generated from protobuf field string description = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setDescription($var) + { + GPBUtil::checkString($var, True); + $this->description = $var; + + return $this; + } + + /** + * Output only. Filtering attributes for the event type. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.FilteringAttribute filtering_attributes = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFilteringAttributes() + { + return $this->filtering_attributes; + } + + /** + * Output only. Filtering attributes for the event type. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.FilteringAttribute filtering_attributes = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Cloud\Eventarc\V1\FilteringAttribute[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFilteringAttributes($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Eventarc\V1\FilteringAttribute::class); + $this->filtering_attributes = $arr; + + return $this; + } + + /** + * Output only. URI for the event schema. + * For example + * "https://github.com/googleapis/google-cloudevents/blob/master/proto/google/events/cloud/storage/v1/events.proto" + * + * Generated from protobuf field string event_schema_uri = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getEventSchemaUri() + { + return $this->event_schema_uri; + } + + /** + * Output only. URI for the event schema. + * For example + * "https://github.com/googleapis/google-cloudevents/blob/master/proto/google/events/cloud/storage/v1/events.proto" + * + * Generated from protobuf field string event_schema_uri = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setEventSchemaUri($var) + { + GPBUtil::checkString($var, True); + $this->event_schema_uri = $var; + + return $this; + } + +} + diff --git a/Eventarc/src/V1/EventarcGrpcClient.php b/Eventarc/src/V1/EventarcGrpcClient.php index fd3115d63c4..1f0e2168962 100644 --- a/Eventarc/src/V1/EventarcGrpcClient.php +++ b/Eventarc/src/V1/EventarcGrpcClient.php @@ -183,6 +183,36 @@ public function DeleteChannel(\Google\Cloud\Eventarc\V1\DeleteChannelRequest $ar $metadata, $options); } + /** + * Get a single Provider. + * @param \Google\Cloud\Eventarc\V1\GetProviderRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function GetProvider(\Google\Cloud\Eventarc\V1\GetProviderRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.eventarc.v1.Eventarc/GetProvider', + $argument, + ['\Google\Cloud\Eventarc\V1\Provider', 'decode'], + $metadata, $options); + } + + /** + * List providers. + * @param \Google\Cloud\Eventarc\V1\ListProvidersRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListProviders(\Google\Cloud\Eventarc\V1\ListProvidersRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.eventarc.v1.Eventarc/ListProviders', + $argument, + ['\Google\Cloud\Eventarc\V1\ListProvidersResponse', 'decode'], + $metadata, $options); + } + /** * Get a single ChannelConnection. * @param \Google\Cloud\Eventarc\V1\GetChannelConnectionRequest $argument input argument diff --git a/Eventarc/src/V1/FilteringAttribute.php b/Eventarc/src/V1/FilteringAttribute.php new file mode 100644 index 00000000000..6f64b95fe37 --- /dev/null +++ b/Eventarc/src/V1/FilteringAttribute.php @@ -0,0 +1,178 @@ +google.cloud.eventarc.v1.FilteringAttribute + */ +class FilteringAttribute extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. Attribute used for filtering the event type. + * + * Generated from protobuf field string attribute = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $attribute = ''; + /** + * Output only. Description of the purpose of the attribute. + * + * Generated from protobuf field string description = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $description = ''; + /** + * Output only. If true, the triggers for this provider should always specify a filter + * on these attributes. Trigger creation will fail otherwise. + * + * Generated from protobuf field bool required = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $required = false; + /** + * Output only. If true, the attribute accepts matching expressions in the Eventarc + * PathPattern format. + * + * Generated from protobuf field bool path_pattern_supported = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $path_pattern_supported = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $attribute + * Output only. Attribute used for filtering the event type. + * @type string $description + * Output only. Description of the purpose of the attribute. + * @type bool $required + * Output only. If true, the triggers for this provider should always specify a filter + * on these attributes. Trigger creation will fail otherwise. + * @type bool $path_pattern_supported + * Output only. If true, the attribute accepts matching expressions in the Eventarc + * PathPattern format. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\V1\Discovery::initOnce(); + parent::__construct($data); + } + + /** + * Output only. Attribute used for filtering the event type. + * + * Generated from protobuf field string attribute = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getAttribute() + { + return $this->attribute; + } + + /** + * Output only. Attribute used for filtering the event type. + * + * Generated from protobuf field string attribute = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setAttribute($var) + { + GPBUtil::checkString($var, True); + $this->attribute = $var; + + return $this; + } + + /** + * Output only. Description of the purpose of the attribute. + * + * Generated from protobuf field string description = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Output only. Description of the purpose of the attribute. + * + * Generated from protobuf field string description = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setDescription($var) + { + GPBUtil::checkString($var, True); + $this->description = $var; + + return $this; + } + + /** + * Output only. If true, the triggers for this provider should always specify a filter + * on these attributes. Trigger creation will fail otherwise. + * + * Generated from protobuf field bool required = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return bool + */ + public function getRequired() + { + return $this->required; + } + + /** + * Output only. If true, the triggers for this provider should always specify a filter + * on these attributes. Trigger creation will fail otherwise. + * + * Generated from protobuf field bool required = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param bool $var + * @return $this + */ + public function setRequired($var) + { + GPBUtil::checkBool($var); + $this->required = $var; + + return $this; + } + + /** + * Output only. If true, the attribute accepts matching expressions in the Eventarc + * PathPattern format. + * + * Generated from protobuf field bool path_pattern_supported = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return bool + */ + public function getPathPatternSupported() + { + return $this->path_pattern_supported; + } + + /** + * Output only. If true, the attribute accepts matching expressions in the Eventarc + * PathPattern format. + * + * Generated from protobuf field bool path_pattern_supported = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param bool $var + * @return $this + */ + public function setPathPatternSupported($var) + { + GPBUtil::checkBool($var); + $this->path_pattern_supported = $var; + + return $this; + } + +} + diff --git a/Eventarc/src/V1/Gapic/EventarcGapicClient.php b/Eventarc/src/V1/Gapic/EventarcGapicClient.php index 4a449b49b17..a39978d25b7 100644 --- a/Eventarc/src/V1/Gapic/EventarcGapicClient.php +++ b/Eventarc/src/V1/Gapic/EventarcGapicClient.php @@ -47,13 +47,17 @@ use Google\Cloud\Eventarc\V1\DeleteTriggerRequest; use Google\Cloud\Eventarc\V1\GetChannelConnectionRequest; use Google\Cloud\Eventarc\V1\GetChannelRequest; +use Google\Cloud\Eventarc\V1\GetProviderRequest; use Google\Cloud\Eventarc\V1\GetTriggerRequest; use Google\Cloud\Eventarc\V1\ListChannelConnectionsRequest; use Google\Cloud\Eventarc\V1\ListChannelConnectionsResponse; use Google\Cloud\Eventarc\V1\ListChannelsRequest; use Google\Cloud\Eventarc\V1\ListChannelsResponse; +use Google\Cloud\Eventarc\V1\ListProvidersRequest; +use Google\Cloud\Eventarc\V1\ListProvidersResponse; use Google\Cloud\Eventarc\V1\ListTriggersRequest; use Google\Cloud\Eventarc\V1\ListTriggersResponse; +use Google\Cloud\Eventarc\V1\Provider; use Google\Cloud\Eventarc\V1\Trigger; use Google\Cloud\Eventarc\V1\UpdateChannelRequest; use Google\Cloud\Eventarc\V1\UpdateTriggerRequest; @@ -147,6 +151,8 @@ class EventarcGapicClient private static $locationNameTemplate; + private static $providerNameTemplate; + private static $serviceAccountNameTemplate; private static $triggerNameTemplate; @@ -213,6 +219,17 @@ private static function getLocationNameTemplate() return self::$locationNameTemplate; } + private static function getProviderNameTemplate() + { + if (self::$providerNameTemplate == null) { + self::$providerNameTemplate = new PathTemplate( + 'projects/{project}/locations/{location}/providers/{provider}' + ); + } + + return self::$providerNameTemplate; + } + private static function getServiceAccountNameTemplate() { if (self::$serviceAccountNameTemplate == null) { @@ -242,6 +259,7 @@ private static function getPathTemplateMap() 'channel' => self::getChannelNameTemplate(), 'channelConnection' => self::getChannelConnectionNameTemplate(), 'location' => self::getLocationNameTemplate(), + 'provider' => self::getProviderNameTemplate(), 'serviceAccount' => self::getServiceAccountNameTemplate(), 'trigger' => self::getTriggerNameTemplate(), ]; @@ -308,6 +326,25 @@ public static function locationName($project, $location) ]); } + /** + * Formats a string containing the fully-qualified path to represent a provider + * resource. + * + * @param string $project + * @param string $location + * @param string $provider + * + * @return string The formatted provider resource. + */ + public static function providerName($project, $location, $provider) + { + return self::getProviderNameTemplate()->render([ + 'project' => $project, + 'location' => $location, + 'provider' => $provider, + ]); + } + /** * Formats a string containing the fully-qualified path to represent a * service_account resource. @@ -351,6 +388,7 @@ public static function triggerName($project, $location, $trigger) * - channel: projects/{project}/locations/{location}/channels/{channel} * - channelConnection: projects/{project}/locations/{location}/channelConnections/{channel_connection} * - location: projects/{project}/locations/{location} + * - provider: projects/{project}/locations/{location}/providers/{provider} * - serviceAccount: projects/{project}/serviceAccounts/{service_account} * - trigger: projects/{project}/locations/{location}/triggers/{trigger} * @@ -1102,6 +1140,55 @@ public function getChannelConnection($name, array $optionalArgs = []) )->wait(); } + /** + * Get a single Provider. + * + * Sample code: + * ``` + * $eventarcClient = new EventarcClient(); + * try { + * $formattedName = $eventarcClient->providerName('[PROJECT]', '[LOCATION]', '[PROVIDER]'); + * $response = $eventarcClient->getProvider($formattedName); + * } finally { + * $eventarcClient->close(); + * } + * ``` + * + * @param string $name Required. The name of the provider to get. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Eventarc\V1\Provider + * + * @throws ApiException if the remote call fails + */ + public function getProvider($name, array $optionalArgs = []) + { + $request = new GetProviderRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'GetProvider', + Provider::class, + $optionalArgs, + $request + )->wait(); + } + /** * Get a single trigger. * @@ -1316,6 +1403,99 @@ public function listChannels($parent, array $optionalArgs = []) ); } + /** + * List providers. + * + * Sample code: + * ``` + * $eventarcClient = new EventarcClient(); + * try { + * $formattedParent = $eventarcClient->locationName('[PROJECT]', '[LOCATION]'); + * // Iterate over pages of elements + * $pagedResponse = $eventarcClient->listProviders($formattedParent); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $eventarcClient->listProviders($formattedParent); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $eventarcClient->close(); + * } + * ``` + * + * @param string $parent Required. The parent of the provider to get. + * @param array $optionalArgs { + * Optional. + * + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type string $orderBy + * The sorting order of the resources returned. Value should be a + * comma-separated list of fields. The default sorting oder is ascending. To + * specify descending order for a field, append a `desc` suffix; for example: + * `name desc, _id`. + * @type string $filter + * The filter field that the list request will filter on. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\ApiCore\PagedListResponse + * + * @throws ApiException if the remote call fails + */ + public function listProviders($parent, array $optionalArgs = []) + { + $request = new ListProvidersRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + if (isset($optionalArgs['orderBy'])) { + $request->setOrderBy($optionalArgs['orderBy']); + } + + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } + + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->getPagedListResponse( + 'ListProviders', + $optionalArgs, + ListProvidersResponse::class, + $request + ); + } + /** * List triggers. * diff --git a/Eventarc/src/V1/GetProviderRequest.php b/Eventarc/src/V1/GetProviderRequest.php new file mode 100644 index 00000000000..c76b5556695 --- /dev/null +++ b/Eventarc/src/V1/GetProviderRequest.php @@ -0,0 +1,67 @@ +google.cloud.eventarc.v1.GetProviderRequest + */ +class GetProviderRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the provider to get. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the provider to get. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\V1\Eventarc::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the provider to get. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The name of the provider to get. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/Eventarc/src/V1/ListProvidersRequest.php b/Eventarc/src/V1/ListProvidersRequest.php new file mode 100644 index 00000000000..cde4f0023df --- /dev/null +++ b/Eventarc/src/V1/ListProvidersRequest.php @@ -0,0 +1,227 @@ +google.cloud.eventarc.v1.ListProvidersRequest + */ +class ListProvidersRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent of the provider to get. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $parent = ''; + /** + * The maximum number of providers to return on each page. + * + * Generated from protobuf field int32 page_size = 2; + */ + private $page_size = 0; + /** + * The page token; provide the value from the `next_page_token` field in a + * previous `ListProviders` call to retrieve the subsequent page. + * When paginating, all other parameters provided to `ListProviders` must + * match the call that provided the page token. + * + * Generated from protobuf field string page_token = 3; + */ + private $page_token = ''; + /** + * The sorting order of the resources returned. Value should be a + * comma-separated list of fields. The default sorting oder is ascending. To + * specify descending order for a field, append a `desc` suffix; for example: + * `name desc, _id`. + * + * Generated from protobuf field string order_by = 4; + */ + private $order_by = ''; + /** + * The filter field that the list request will filter on. + * + * Generated from protobuf field string filter = 5; + */ + private $filter = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent of the provider to get. + * @type int $page_size + * The maximum number of providers to return on each page. + * @type string $page_token + * The page token; provide the value from the `next_page_token` field in a + * previous `ListProviders` call to retrieve the subsequent page. + * When paginating, all other parameters provided to `ListProviders` must + * match the call that provided the page token. + * @type string $order_by + * The sorting order of the resources returned. Value should be a + * comma-separated list of fields. The default sorting oder is ascending. To + * specify descending order for a field, append a `desc` suffix; for example: + * `name desc, _id`. + * @type string $filter + * The filter field that the list request will filter on. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\V1\Eventarc::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent of the provider to get. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent of the provider to get. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * The maximum number of providers to return on each page. + * + * Generated from protobuf field int32 page_size = 2; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The maximum number of providers to return on each page. + * + * Generated from protobuf field int32 page_size = 2; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * The page token; provide the value from the `next_page_token` field in a + * previous `ListProviders` call to retrieve the subsequent page. + * When paginating, all other parameters provided to `ListProviders` must + * match the call that provided the page token. + * + * Generated from protobuf field string page_token = 3; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * The page token; provide the value from the `next_page_token` field in a + * previous `ListProviders` call to retrieve the subsequent page. + * When paginating, all other parameters provided to `ListProviders` must + * match the call that provided the page token. + * + * Generated from protobuf field string page_token = 3; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * The sorting order of the resources returned. Value should be a + * comma-separated list of fields. The default sorting oder is ascending. To + * specify descending order for a field, append a `desc` suffix; for example: + * `name desc, _id`. + * + * Generated from protobuf field string order_by = 4; + * @return string + */ + public function getOrderBy() + { + return $this->order_by; + } + + /** + * The sorting order of the resources returned. Value should be a + * comma-separated list of fields. The default sorting oder is ascending. To + * specify descending order for a field, append a `desc` suffix; for example: + * `name desc, _id`. + * + * Generated from protobuf field string order_by = 4; + * @param string $var + * @return $this + */ + public function setOrderBy($var) + { + GPBUtil::checkString($var, True); + $this->order_by = $var; + + return $this; + } + + /** + * The filter field that the list request will filter on. + * + * Generated from protobuf field string filter = 5; + * @return string + */ + public function getFilter() + { + return $this->filter; + } + + /** + * The filter field that the list request will filter on. + * + * Generated from protobuf field string filter = 5; + * @param string $var + * @return $this + */ + public function setFilter($var) + { + GPBUtil::checkString($var, True); + $this->filter = $var; + + return $this; + } + +} + diff --git a/Eventarc/src/V1/ListProvidersResponse.php b/Eventarc/src/V1/ListProvidersResponse.php new file mode 100644 index 00000000000..aecfa67437b --- /dev/null +++ b/Eventarc/src/V1/ListProvidersResponse.php @@ -0,0 +1,139 @@ +google.cloud.eventarc.v1.ListProvidersResponse + */ +class ListProvidersResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The requested providers, up to the number specified in `page_size`. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.Provider providers = 1; + */ + private $providers; + /** + * A page token that can be sent to ListProviders to request the next page. + * If this is empty, then there are no more pages. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + /** + * Unreachable resources, if any. + * + * Generated from protobuf field repeated string unreachable = 3; + */ + private $unreachable; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\Eventarc\V1\Provider[]|\Google\Protobuf\Internal\RepeatedField $providers + * The requested providers, up to the number specified in `page_size`. + * @type string $next_page_token + * A page token that can be sent to ListProviders to request the next page. + * If this is empty, then there are no more pages. + * @type string[]|\Google\Protobuf\Internal\RepeatedField $unreachable + * Unreachable resources, if any. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\V1\Eventarc::initOnce(); + parent::__construct($data); + } + + /** + * The requested providers, up to the number specified in `page_size`. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.Provider providers = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getProviders() + { + return $this->providers; + } + + /** + * The requested providers, up to the number specified in `page_size`. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.Provider providers = 1; + * @param \Google\Cloud\Eventarc\V1\Provider[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setProviders($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Eventarc\V1\Provider::class); + $this->providers = $arr; + + return $this; + } + + /** + * A page token that can be sent to ListProviders to request the next page. + * If this is empty, then there are no more pages. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * A page token that can be sent to ListProviders to request the next page. + * If this is empty, then there are no more pages. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + + /** + * Unreachable resources, if any. + * + * Generated from protobuf field repeated string unreachable = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getUnreachable() + { + return $this->unreachable; + } + + /** + * Unreachable resources, if any. + * + * Generated from protobuf field repeated string unreachable = 3; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setUnreachable($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->unreachable = $arr; + + return $this; + } + +} + diff --git a/Eventarc/src/V1/Provider.php b/Eventarc/src/V1/Provider.php new file mode 100644 index 00000000000..654a819ff88 --- /dev/null +++ b/Eventarc/src/V1/Provider.php @@ -0,0 +1,139 @@ +google.cloud.eventarc.v1.Provider + */ +class Provider extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. In `projects/{project}/locations/{location}/providers/{provider_id}` + * format. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $name = ''; + /** + * Output only. Human friendly name for the Provider. For example "Cloud Storage". + * + * Generated from protobuf field string display_name = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $display_name = ''; + /** + * Output only. Event types for this provider. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.EventType event_types = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $event_types; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Output only. In `projects/{project}/locations/{location}/providers/{provider_id}` + * format. + * @type string $display_name + * Output only. Human friendly name for the Provider. For example "Cloud Storage". + * @type \Google\Cloud\Eventarc\V1\EventType[]|\Google\Protobuf\Internal\RepeatedField $event_types + * Output only. Event types for this provider. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\V1\Discovery::initOnce(); + parent::__construct($data); + } + + /** + * Output only. In `projects/{project}/locations/{location}/providers/{provider_id}` + * format. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Output only. In `projects/{project}/locations/{location}/providers/{provider_id}` + * format. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Output only. Human friendly name for the Provider. For example "Cloud Storage". + * + * Generated from protobuf field string display_name = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getDisplayName() + { + return $this->display_name; + } + + /** + * Output only. Human friendly name for the Provider. For example "Cloud Storage". + * + * Generated from protobuf field string display_name = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setDisplayName($var) + { + GPBUtil::checkString($var, True); + $this->display_name = $var; + + return $this; + } + + /** + * Output only. Event types for this provider. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.EventType event_types = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEventTypes() + { + return $this->event_types; + } + + /** + * Output only. Event types for this provider. + * + * Generated from protobuf field repeated .google.cloud.eventarc.v1.EventType event_types = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Cloud\Eventarc\V1\EventType[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setEventTypes($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Eventarc\V1\EventType::class); + $this->event_types = $arr; + + return $this; + } + +} + diff --git a/Eventarc/src/V1/gapic_metadata.json b/Eventarc/src/V1/gapic_metadata.json index 3f2301e595f..90ecd1eea55 100644 --- a/Eventarc/src/V1/gapic_metadata.json +++ b/Eventarc/src/V1/gapic_metadata.json @@ -50,6 +50,11 @@ "getChannelConnection" ] }, + "GetProvider": { + "methods": [ + "getProvider" + ] + }, "GetTrigger": { "methods": [ "getTrigger" @@ -65,6 +70,11 @@ "listChannels" ] }, + "ListProviders": { + "methods": [ + "listProviders" + ] + }, "ListTriggers": { "methods": [ "listTriggers" diff --git a/Eventarc/src/V1/resources/eventarc_client_config.json b/Eventarc/src/V1/resources/eventarc_client_config.json index 378cd88f917..4b84cd5e832 100644 --- a/Eventarc/src/V1/resources/eventarc_client_config.json +++ b/Eventarc/src/V1/resources/eventarc_client_config.json @@ -56,6 +56,11 @@ "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" }, + "GetProvider": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "GetTrigger": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", @@ -71,6 +76,11 @@ "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" }, + "ListProviders": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "ListTriggers": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", diff --git a/Eventarc/src/V1/resources/eventarc_descriptor_config.php b/Eventarc/src/V1/resources/eventarc_descriptor_config.php index 1f7aa10c4c2..6a8c21cde01 100644 --- a/Eventarc/src/V1/resources/eventarc_descriptor_config.php +++ b/Eventarc/src/V1/resources/eventarc_descriptor_config.php @@ -103,6 +103,16 @@ 'resourcesGetMethod' => 'getChannels', ], ], + 'ListProviders' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getProviders', + ], + ], 'ListTriggers' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', diff --git a/Eventarc/src/V1/resources/eventarc_rest_client_config.php b/Eventarc/src/V1/resources/eventarc_rest_client_config.php index 36eea765f88..803c56aa5be 100644 --- a/Eventarc/src/V1/resources/eventarc_rest_client_config.php +++ b/Eventarc/src/V1/resources/eventarc_rest_client_config.php @@ -111,6 +111,17 @@ ], ], ], + 'GetProvider' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=projects/*/locations/*/providers/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'GetTrigger' => [ 'method' => 'get', 'uriTemplate' => '/v1/{name=projects/*/locations/*/triggers/*}', @@ -144,6 +155,17 @@ ], ], ], + 'ListProviders' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*/locations/*}/providers', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], 'ListTriggers' => [ 'method' => 'get', 'uriTemplate' => '/v1/{parent=projects/*/locations/*}/triggers', diff --git a/Eventarc/tests/Unit/V1/EventarcClientTest.php b/Eventarc/tests/Unit/V1/EventarcClientTest.php index 8c6bc81f8d7..46322b95007 100644 --- a/Eventarc/tests/Unit/V1/EventarcClientTest.php +++ b/Eventarc/tests/Unit/V1/EventarcClientTest.php @@ -36,7 +36,9 @@ use Google\Cloud\Eventarc\V1\EventarcClient; use Google\Cloud\Eventarc\V1\ListChannelConnectionsResponse; use Google\Cloud\Eventarc\V1\ListChannelsResponse; +use Google\Cloud\Eventarc\V1\ListProvidersResponse; use Google\Cloud\Eventarc\V1\ListTriggersResponse; +use Google\Cloud\Eventarc\V1\Provider; use Google\Cloud\Eventarc\V1\Trigger; use Google\LongRunning\GetOperationRequest; use Google\LongRunning\Operation; @@ -1070,6 +1072,72 @@ public function getChannelConnectionExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** + * @test + */ + public function getProviderTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new Provider(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $client->providerName('[PROJECT]', '[LOCATION]', '[PROVIDER]'); + $response = $client->getProvider($formattedName); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.eventarc.v1.Eventarc/GetProvider', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** + * @test + */ + public function getProviderExceptionTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $client->providerName('[PROJECT]', '[LOCATION]', '[PROVIDER]'); + try { + $client->getProvider($formattedName); + // If the $client method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** * @test */ @@ -1286,6 +1354,78 @@ public function listChannelsExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** + * @test + */ + public function listProvidersTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $providersElement = new Provider(); + $providers = [ + $providersElement, + ]; + $expectedResponse = new ListProvidersResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProviders($providers); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); + $response = $client->listProviders($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProviders()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.eventarc.v1.Eventarc/ListProviders', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** + * @test + */ + public function listProvidersExceptionTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $client->locationName('[PROJECT]', '[LOCATION]'); + try { + $client->listProviders($formattedParent); + // If the $client method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** * @test */