Skip to content

Commit da3d412

Browse files
yoshi-automationjdpedrie
authored andcommitted
feat: Add support for notification channel verification codes. (#2155)
1 parent 6d9c47f commit da3d412

5 files changed

Lines changed: 484 additions & 5 deletions

Monitoring/src/V3/Gapic/NotificationChannelServiceGapicClient.php

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,20 @@
3939
use Google\Cloud\Monitoring\V3\DeleteNotificationChannelRequest;
4040
use Google\Cloud\Monitoring\V3\GetNotificationChannelDescriptorRequest;
4141
use Google\Cloud\Monitoring\V3\GetNotificationChannelRequest;
42+
use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeRequest;
43+
use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse;
4244
use Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsRequest;
4345
use Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsResponse;
4446
use Google\Cloud\Monitoring\V3\ListNotificationChannelsRequest;
4547
use Google\Cloud\Monitoring\V3\ListNotificationChannelsResponse;
4648
use Google\Cloud\Monitoring\V3\NotificationChannel;
4749
use Google\Cloud\Monitoring\V3\NotificationChannelDescriptor;
50+
use Google\Cloud\Monitoring\V3\SendNotificationChannelVerificationCodeRequest;
4851
use Google\Cloud\Monitoring\V3\UpdateNotificationChannelRequest;
52+
use Google\Cloud\Monitoring\V3\VerifyNotificationChannelRequest;
4953
use Google\Protobuf\FieldMask;
5054
use Google\Protobuf\GPBEmpty;
55+
use Google\Protobuf\Timestamp;
5156

5257
/**
5358
* Service Description: The Notification Channel API provides access to configuration that
@@ -815,4 +820,199 @@ public function deleteNotificationChannel($name, array $optionalArgs = [])
815820
$request
816821
)->wait();
817822
}
823+
824+
/**
825+
* Causes a verification code to be delivered to the channel. The code
826+
* can then be supplied in `VerifyNotificationChannel` to verify the channel.
827+
*
828+
* Sample code:
829+
* ```
830+
* $notificationChannelServiceClient = new Google\Cloud\Monitoring\V3\NotificationChannelServiceClient();
831+
* try {
832+
* $formattedName = $notificationChannelServiceClient->notificationChannelName('[PROJECT]', '[NOTIFICATION_CHANNEL]');
833+
* $notificationChannelServiceClient->sendNotificationChannelVerificationCode($formattedName);
834+
* } finally {
835+
* $notificationChannelServiceClient->close();
836+
* }
837+
* ```
838+
*
839+
* @param string $name The notification channel to which to send a verification code.
840+
* @param array $optionalArgs {
841+
* Optional.
842+
*
843+
* @type RetrySettings|array $retrySettings
844+
* Retry settings to use for this call. Can be a
845+
* {@see Google\ApiCore\RetrySettings} object, or an associative array
846+
* of retry settings parameters. See the documentation on
847+
* {@see Google\ApiCore\RetrySettings} for example usage.
848+
* }
849+
*
850+
* @throws ApiException if the remote call fails
851+
* @experimental
852+
*/
853+
public function sendNotificationChannelVerificationCode($name, array $optionalArgs = [])
854+
{
855+
$request = new SendNotificationChannelVerificationCodeRequest();
856+
$request->setName($name);
857+
858+
$requestParams = new RequestParamsHeaderDescriptor([
859+
'name' => $request->getName(),
860+
]);
861+
$optionalArgs['headers'] = isset($optionalArgs['headers'])
862+
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
863+
: $requestParams->getHeader();
864+
865+
return $this->startCall(
866+
'SendNotificationChannelVerificationCode',
867+
GPBEmpty::class,
868+
$optionalArgs,
869+
$request
870+
)->wait();
871+
}
872+
873+
/**
874+
* Requests a verification code for an already verified channel that can then
875+
* be used in a call to VerifyNotificationChannel() on a different channel
876+
* with an equivalent identity in the same or in a different project. This
877+
* makes it possible to copy a channel between projects without requiring
878+
* manual reverification of the channel. If the channel is not in the
879+
* verified state, this method will fail (in other words, this may only be
880+
* used if the SendNotificationChannelVerificationCode and
881+
* VerifyNotificationChannel paths have already been used to put the given
882+
* channel into the verified state).
883+
*
884+
* There is no guarantee that the verification codes returned by this method
885+
* will be of a similar structure or form as the ones that are delivered
886+
* to the channel via SendNotificationChannelVerificationCode; while
887+
* VerifyNotificationChannel() will recognize both the codes delivered via
888+
* SendNotificationChannelVerificationCode() and returned from
889+
* GetNotificationChannelVerificationCode(), it is typically the case that
890+
* the verification codes delivered via
891+
* SendNotificationChannelVerificationCode() will be shorter and also
892+
* have a shorter expiration (e.g. codes such as "G-123456") whereas
893+
* GetVerificationCode() will typically return a much longer, websafe base
894+
* 64 encoded string that has a longer expiration time.
895+
*
896+
* Sample code:
897+
* ```
898+
* $notificationChannelServiceClient = new Google\Cloud\Monitoring\V3\NotificationChannelServiceClient();
899+
* try {
900+
* $formattedName = $notificationChannelServiceClient->notificationChannelName('[PROJECT]', '[NOTIFICATION_CHANNEL]');
901+
* $response = $notificationChannelServiceClient->getNotificationChannelVerificationCode($formattedName);
902+
* } finally {
903+
* $notificationChannelServiceClient->close();
904+
* }
905+
* ```
906+
*
907+
* @param string $name The notification channel for which a verification code is to be generated
908+
* and retrieved. This must name a channel that is already verified; if
909+
* the specified channel is not verified, the request will fail.
910+
* @param array $optionalArgs {
911+
* Optional.
912+
*
913+
* @type Timestamp $expireTime
914+
* The desired expiration time. If specified, the API will guarantee that
915+
* the returned code will not be valid after the specified timestamp;
916+
* however, the API cannot guarantee that the returned code will be
917+
* valid for at least as long as the requested time (the API puts an upper
918+
* bound on the amount of time for which a code may be valid). If omitted,
919+
* a default expiration will be used, which may be less than the max
920+
* permissible expiration (so specifying an expiration may extend the
921+
* code's lifetime over omitting an expiration, even though the API does
922+
* impose an upper limit on the maximum expiration that is permitted).
923+
* @type RetrySettings|array $retrySettings
924+
* Retry settings to use for this call. Can be a
925+
* {@see Google\ApiCore\RetrySettings} object, or an associative array
926+
* of retry settings parameters. See the documentation on
927+
* {@see Google\ApiCore\RetrySettings} for example usage.
928+
* }
929+
*
930+
* @return \Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse
931+
*
932+
* @throws ApiException if the remote call fails
933+
* @experimental
934+
*/
935+
public function getNotificationChannelVerificationCode($name, array $optionalArgs = [])
936+
{
937+
$request = new GetNotificationChannelVerificationCodeRequest();
938+
$request->setName($name);
939+
if (isset($optionalArgs['expireTime'])) {
940+
$request->setExpireTime($optionalArgs['expireTime']);
941+
}
942+
943+
$requestParams = new RequestParamsHeaderDescriptor([
944+
'name' => $request->getName(),
945+
]);
946+
$optionalArgs['headers'] = isset($optionalArgs['headers'])
947+
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
948+
: $requestParams->getHeader();
949+
950+
return $this->startCall(
951+
'GetNotificationChannelVerificationCode',
952+
GetNotificationChannelVerificationCodeResponse::class,
953+
$optionalArgs,
954+
$request
955+
)->wait();
956+
}
957+
958+
/**
959+
* Verifies a `NotificationChannel` by proving receipt of the code
960+
* delivered to the channel as a result of calling
961+
* `SendNotificationChannelVerificationCode`.
962+
*
963+
* Sample code:
964+
* ```
965+
* $notificationChannelServiceClient = new Google\Cloud\Monitoring\V3\NotificationChannelServiceClient();
966+
* try {
967+
* $formattedName = $notificationChannelServiceClient->notificationChannelName('[PROJECT]', '[NOTIFICATION_CHANNEL]');
968+
* $code = '';
969+
* $response = $notificationChannelServiceClient->verifyNotificationChannel($formattedName, $code);
970+
* } finally {
971+
* $notificationChannelServiceClient->close();
972+
* }
973+
* ```
974+
*
975+
* @param string $name The notification channel to verify.
976+
* @param string $code The verification code that was delivered to the channel as
977+
* a result of invoking the `SendNotificationChannelVerificationCode` API
978+
* method or that was retrieved from a verified channel via
979+
* `GetNotificationChannelVerificationCode`. For example, one might have
980+
* "G-123456" or "TKNZGhhd2EyN3I1MnRnMjRv" (in general, one is only
981+
* guaranteed that the code is valid UTF-8; one should not
982+
* make any assumptions regarding the structure or format of the code).
983+
* @param array $optionalArgs {
984+
* Optional.
985+
*
986+
* @type RetrySettings|array $retrySettings
987+
* Retry settings to use for this call. Can be a
988+
* {@see Google\ApiCore\RetrySettings} object, or an associative array
989+
* of retry settings parameters. See the documentation on
990+
* {@see Google\ApiCore\RetrySettings} for example usage.
991+
* }
992+
*
993+
* @return \Google\Cloud\Monitoring\V3\NotificationChannel
994+
*
995+
* @throws ApiException if the remote call fails
996+
* @experimental
997+
*/
998+
public function verifyNotificationChannel($name, $code, array $optionalArgs = [])
999+
{
1000+
$request = new VerifyNotificationChannelRequest();
1001+
$request->setName($name);
1002+
$request->setCode($code);
1003+
1004+
$requestParams = new RequestParamsHeaderDescriptor([
1005+
'name' => $request->getName(),
1006+
]);
1007+
$optionalArgs['headers'] = isset($optionalArgs['headers'])
1008+
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
1009+
: $requestParams->getHeader();
1010+
1011+
return $this->startCall(
1012+
'VerifyNotificationChannel',
1013+
NotificationChannel::class,
1014+
$optionalArgs,
1015+
$request
1016+
)->wait();
1017+
}
8181018
}

Monitoring/src/V3/resources/notification_channel_service_client_config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@
5454
"timeout_millis": 30000,
5555
"retry_codes_name": "idempotent",
5656
"retry_params_name": "default"
57+
},
58+
"SendNotificationChannelVerificationCode": {
59+
"timeout_millis": 30000,
60+
"retry_codes_name": "non_idempotent",
61+
"retry_params_name": "default"
62+
},
63+
"GetNotificationChannelVerificationCode": {
64+
"timeout_millis": 30000,
65+
"retry_codes_name": "idempotent",
66+
"retry_params_name": "default"
67+
},
68+
"VerifyNotificationChannel": {
69+
"timeout_millis": 30000,
70+
"retry_codes_name": "idempotent",
71+
"retry_params_name": "default"
5772
}
5873
}
5974
}

Monitoring/src/V3/resources/notification_channel_service_rest_client_config.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@
8383
],
8484
],
8585
],
86+
'SendNotificationChannelVerificationCode' => [
87+
'method' => 'post',
88+
'uriTemplate' => '/v3/{name=projects/*/notificationChannels/*}:sendVerificationCode',
89+
'body' => '*',
90+
'placeholders' => [
91+
'name' => [
92+
'getters' => [
93+
'getName',
94+
],
95+
],
96+
],
97+
],
98+
'GetNotificationChannelVerificationCode' => [
99+
'method' => 'post',
100+
'uriTemplate' => '/v3/{name=projects/*/notificationChannels/*}:getVerificationCode',
101+
'body' => '*',
102+
'placeholders' => [
103+
'name' => [
104+
'getters' => [
105+
'getName',
106+
],
107+
],
108+
],
109+
],
110+
'VerifyNotificationChannel' => [
111+
'method' => 'post',
112+
'uriTemplate' => '/v3/{name=projects/*/notificationChannels/*}:verify',
113+
'body' => '*',
114+
'placeholders' => [
115+
'name' => [
116+
'getters' => [
117+
'getName',
118+
],
119+
],
120+
],
121+
],
86122
],
87123
],
88124
];

Monitoring/synth.metadata

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"updateTime": "2019-06-24T17:23:20.114171Z",
2+
"updateTime": "2019-08-01T10:01:29.921345Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.29.0",
8-
"dockerImage": "googleapis/artman@sha256:b79c8c20ee51e5302686c9d1294672d59290df1489be93749ef17d0172cc508d"
7+
"version": "0.29.1",
8+
"dockerImage": "googleapis/artman@sha256:b2a73f4dda03ef8fcaa973e3ba26d0cf34091f6c22c70add663af325931aef4d"
99
}
1010
},
1111
{
1212
"git": {
1313
"name": "googleapis",
1414
"remote": "https://github.com/googleapis/googleapis.git",
15-
"sha": "de1150ccad2a3daa4e265a0948bec54fdf9c8b54",
16-
"internalRef": "254446031"
15+
"sha": "e3b51e761db720974bc153a380a2f7ae5baee43d",
16+
"internalRef": "260992170"
1717
}
1818
}
1919
],

0 commit comments

Comments
 (0)