From 3b9605ff5d84545c327675be0d9ed4ed8d5b7bbe Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 12:28:21 -0700 Subject: [PATCH] feat: [EventarcPublishing] Add publishing methods for channel resources (#5226) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add publishing methods for channel resources PiperOrigin-RevId: 442858558 Source-Link: https://github.com/googleapis/googleapis/commit/726dac2bf68b80c06801fb5f4a3dd2297ac98bc4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/b2ecfcf252436ebe2137664ea41cdcd33d36e2af Copy-Tag: eyJwIjoiRXZlbnRhcmNQdWJsaXNoaW5nLy5Pd2xCb3QueWFtbCIsImgiOiJiMmVjZmNmMjUyNDM2ZWJlMjEzNzY2NGVhNDFjZGNkMzNkMzZlMmFmIn0= * 🦉 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 --- EventarcPublishing/metadata/V1/Publisher.php | 15 ++- .../src/V1/Gapic/PublisherGapicClient.php | 61 ++++++++++ .../src/V1/PublishEventsRequest.php | 105 ++++++++++++++++++ .../src/V1/PublishEventsResponse.php | 33 ++++++ .../src/V1/PublisherGrpcClient.php | 15 +++ EventarcPublishing/src/V1/gapic_metadata.json | 5 + .../V1/resources/publisher_client_config.json | 5 + .../publisher_rest_client_config.php | 12 ++ .../tests/Unit/V1/PublisherClientTest.php | 57 ++++++++++ 9 files changed, 303 insertions(+), 5 deletions(-) create mode 100644 EventarcPublishing/src/V1/PublishEventsRequest.php create mode 100644 EventarcPublishing/src/V1/PublishEventsResponse.php diff --git a/EventarcPublishing/metadata/V1/Publisher.php b/EventarcPublishing/metadata/V1/Publisher.php index 8c3d1fb3803..0038c4ed61d 100644 --- a/EventarcPublishing/metadata/V1/Publisher.php +++ b/EventarcPublishing/metadata/V1/Publisher.php @@ -15,18 +15,23 @@ public static function initOnce() { return; } \GPBMetadata\Google\Api\Annotations::initOnce(); - \GPBMetadata\Google\Protobuf\Any::initOnce(); \GPBMetadata\Google\Api\Client::initOnce(); + \GPBMetadata\Google\Protobuf\Any::initOnce(); $pool->internalAddGeneratedFile( ' -­ -3google/cloud/eventarc/publishing/v1/publisher.proto#google.cloud.eventarc.publishing.v1google/protobuf/any.protogoogle/api/client.proto"i +è +3google/cloud/eventarc/publishing/v1/publisher.proto#google.cloud.eventarc.publishing.v1google/api/client.protogoogle/protobuf/any.proto"i %PublishChannelConnectionEventsRequest channel_connection ( $ events ( 2.google.protobuf.Any"( -&PublishChannelConnectionEventsResponse2ý +&PublishChannelConnectionEventsResponse"M +PublishEventsRequest +channel ( $ +events ( 2.google.protobuf.Any" +PublishEventsResponse2Ð Publisher˜ -PublishChannelConnectionEventsJ.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsRequestK.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsResponse"]‚Óä“W"R/v1/{channel_connection=projects/*/locations/*/channelConnections/*}:publishEvents:*UÊA!eventarcpublishing.googleapis.comÒA.https://www.googleapis.com/auth/cloud-platformBÿ +PublishChannelConnectionEventsJ.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsRequestK.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsResponse"]‚Óä“W"R/v1/{channel_connection=projects/*/locations/*/channelConnections/*}:publishEvents:*Ð + PublishEvents9.google.cloud.eventarc.publishing.v1.PublishEventsRequest:.google.cloud.eventarc.publishing.v1.PublishEventsResponse"H‚Óä“B"=/v1/{channel=projects/*/locations/*/channels/*}:publishEvents:*UÊA!eventarcpublishing.googleapis.comÒA.https://www.googleapis.com/auth/cloud-platformBÿ \'com.google.cloud.eventarc.publishing.v1BPublisherProtoPZLgoogle.golang.org/genproto/googleapis/cloud/eventarc/publishing/v1;publisherª#Google.Cloud.Eventarc.Publishing.V1Ê#Google\\Cloud\\Eventarc\\Publishing\\V1ê\'Google::Cloud::Eventarc::Publishing::V1bproto3' , true); diff --git a/EventarcPublishing/src/V1/Gapic/PublisherGapicClient.php b/EventarcPublishing/src/V1/Gapic/PublisherGapicClient.php index aa4ac37a016..37ed2aed545 100644 --- a/EventarcPublishing/src/V1/Gapic/PublisherGapicClient.php +++ b/EventarcPublishing/src/V1/Gapic/PublisherGapicClient.php @@ -35,6 +35,8 @@ use Google\Auth\FetchAuthTokenInterface; use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsRequest; use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse; +use Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest; +use Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse; use Google\Protobuf\Any; /** @@ -253,4 +255,63 @@ public function publishChannelConnectionEvents(array $optionalArgs = []) $request )->wait(); } + + /** + * Publish events to a subscriber's channel. + * + * Sample code: + * ``` + * $publisherClient = new PublisherClient(); + * try { + * $response = $publisherClient->publishEvents(); + * } finally { + * $publisherClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * + * @type string $channel + * The full name of the channel to publish to. For example: + * `projects/{project}/locations/{location}/channels/{channel-id}`. + * @type Any[] $events + * The CloudEvents v1.0 events to publish. No other types are allowed. + * @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\Publishing\V1\PublishEventsResponse + * + * @throws ApiException if the remote call fails + */ + public function publishEvents(array $optionalArgs = []) + { + $request = new PublishEventsRequest(); + $requestParamHeaders = []; + if (isset($optionalArgs['channel'])) { + $request->setChannel($optionalArgs['channel']); + $requestParamHeaders['channel'] = $optionalArgs['channel']; + } + + if (isset($optionalArgs['events'])) { + $request->setEvents($optionalArgs['events']); + } + + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'PublishEvents', + PublishEventsResponse::class, + $optionalArgs, + $request + )->wait(); + } } diff --git a/EventarcPublishing/src/V1/PublishEventsRequest.php b/EventarcPublishing/src/V1/PublishEventsRequest.php new file mode 100644 index 00000000000..aea6d16b81d --- /dev/null +++ b/EventarcPublishing/src/V1/PublishEventsRequest.php @@ -0,0 +1,105 @@ +google.cloud.eventarc.publishing.v1.PublishEventsRequest + */ +class PublishEventsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * The full name of the channel to publish to. For example: + * `projects/{project}/locations/{location}/channels/{channel-id}`. + * + * Generated from protobuf field string channel = 1; + */ + private $channel = ''; + /** + * The CloudEvents v1.0 events to publish. No other types are allowed. + * + * Generated from protobuf field repeated .google.protobuf.Any events = 2; + */ + private $events; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $channel + * The full name of the channel to publish to. For example: + * `projects/{project}/locations/{location}/channels/{channel-id}`. + * @type \Google\Protobuf\Any[]|\Google\Protobuf\Internal\RepeatedField $events + * The CloudEvents v1.0 events to publish. No other types are allowed. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\Publishing\V1\Publisher::initOnce(); + parent::__construct($data); + } + + /** + * The full name of the channel to publish to. For example: + * `projects/{project}/locations/{location}/channels/{channel-id}`. + * + * Generated from protobuf field string channel = 1; + * @return string + */ + public function getChannel() + { + return $this->channel; + } + + /** + * The full name of the channel to publish to. For example: + * `projects/{project}/locations/{location}/channels/{channel-id}`. + * + * Generated from protobuf field string channel = 1; + * @param string $var + * @return $this + */ + public function setChannel($var) + { + GPBUtil::checkString($var, True); + $this->channel = $var; + + return $this; + } + + /** + * The CloudEvents v1.0 events to publish. No other types are allowed. + * + * Generated from protobuf field repeated .google.protobuf.Any events = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEvents() + { + return $this->events; + } + + /** + * The CloudEvents v1.0 events to publish. No other types are allowed. + * + * Generated from protobuf field repeated .google.protobuf.Any events = 2; + * @param \Google\Protobuf\Any[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setEvents($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Any::class); + $this->events = $arr; + + return $this; + } + +} + diff --git a/EventarcPublishing/src/V1/PublishEventsResponse.php b/EventarcPublishing/src/V1/PublishEventsResponse.php new file mode 100644 index 00000000000..4291ac3bfd7 --- /dev/null +++ b/EventarcPublishing/src/V1/PublishEventsResponse.php @@ -0,0 +1,33 @@ +google.cloud.eventarc.publishing.v1.PublishEventsResponse + */ +class PublishEventsResponse extends \Google\Protobuf\Internal\Message +{ + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Eventarc\Publishing\V1\Publisher::initOnce(); + parent::__construct($data); + } + +} + diff --git a/EventarcPublishing/src/V1/PublisherGrpcClient.php b/EventarcPublishing/src/V1/PublisherGrpcClient.php index 95bf6f8dc05..24bc424a12b 100644 --- a/EventarcPublishing/src/V1/PublisherGrpcClient.php +++ b/EventarcPublishing/src/V1/PublisherGrpcClient.php @@ -70,4 +70,19 @@ public function PublishChannelConnectionEvents(\Google\Cloud\Eventarc\Publishing $metadata, $options); } + /** + * Publish events to a subscriber's channel. + * @param \Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function PublishEvents(\Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.eventarc.publishing.v1.Publisher/PublishEvents', + $argument, + ['\Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse', 'decode'], + $metadata, $options); + } + } diff --git a/EventarcPublishing/src/V1/gapic_metadata.json b/EventarcPublishing/src/V1/gapic_metadata.json index cfd916e60ae..ea1b74edc86 100644 --- a/EventarcPublishing/src/V1/gapic_metadata.json +++ b/EventarcPublishing/src/V1/gapic_metadata.json @@ -14,6 +14,11 @@ "methods": [ "publishChannelConnectionEvents" ] + }, + "PublishEvents": { + "methods": [ + "publishEvents" + ] } } } diff --git a/EventarcPublishing/src/V1/resources/publisher_client_config.json b/EventarcPublishing/src/V1/resources/publisher_client_config.json index de9772ad991..4eca798f5b1 100644 --- a/EventarcPublishing/src/V1/resources/publisher_client_config.json +++ b/EventarcPublishing/src/V1/resources/publisher_client_config.json @@ -30,6 +30,11 @@ "timeout_millis": 60000, "retry_codes_name": "no_retry_1_codes", "retry_params_name": "no_retry_1_params" + }, + "PublishEvents": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" } } } diff --git a/EventarcPublishing/src/V1/resources/publisher_rest_client_config.php b/EventarcPublishing/src/V1/resources/publisher_rest_client_config.php index 4cf9771e9cf..dfd2669329f 100644 --- a/EventarcPublishing/src/V1/resources/publisher_rest_client_config.php +++ b/EventarcPublishing/src/V1/resources/publisher_rest_client_config.php @@ -15,6 +15,18 @@ ], ], ], + 'PublishEvents' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{channel=projects/*/locations/*/channels/*}:publishEvents', + 'body' => '*', + 'placeholders' => [ + 'channel' => [ + 'getters' => [ + 'getChannel', + ], + ], + ], + ], ], ], ]; diff --git a/EventarcPublishing/tests/Unit/V1/PublisherClientTest.php b/EventarcPublishing/tests/Unit/V1/PublisherClientTest.php index e848c3019dd..c070d0a3ae7 100644 --- a/EventarcPublishing/tests/Unit/V1/PublisherClientTest.php +++ b/EventarcPublishing/tests/Unit/V1/PublisherClientTest.php @@ -29,6 +29,7 @@ use Google\ApiCore\Testing\MockTransport; use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse; use Google\Cloud\Eventarc\Publishing\V1\PublisherClient; +use Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse; use Google\Rpc\Code; use stdClass; @@ -121,4 +122,60 @@ public function publishChannelConnectionEventsExceptionTest() $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); } + + /** + * @test + */ + public function publishEventsTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new PublishEventsResponse(); + $transport->addResponse($expectedResponse); + $response = $client->publishEvents(); + $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.publishing.v1.Publisher/PublishEvents', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** + * @test + */ + public function publishEventsExceptionTest() + { + $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); + try { + $client->publishEvents(); + // 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()); + } }