|
39 | 39 | use Google\Cloud\Monitoring\V3\DeleteNotificationChannelRequest; |
40 | 40 | use Google\Cloud\Monitoring\V3\GetNotificationChannelDescriptorRequest; |
41 | 41 | use Google\Cloud\Monitoring\V3\GetNotificationChannelRequest; |
| 42 | +use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeRequest; |
| 43 | +use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse; |
42 | 44 | use Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsRequest; |
43 | 45 | use Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsResponse; |
44 | 46 | use Google\Cloud\Monitoring\V3\ListNotificationChannelsRequest; |
45 | 47 | use Google\Cloud\Monitoring\V3\ListNotificationChannelsResponse; |
46 | 48 | use Google\Cloud\Monitoring\V3\NotificationChannel; |
47 | 49 | use Google\Cloud\Monitoring\V3\NotificationChannelDescriptor; |
| 50 | +use Google\Cloud\Monitoring\V3\SendNotificationChannelVerificationCodeRequest; |
48 | 51 | use Google\Cloud\Monitoring\V3\UpdateNotificationChannelRequest; |
| 52 | +use Google\Cloud\Monitoring\V3\VerifyNotificationChannelRequest; |
49 | 53 | use Google\Protobuf\FieldMask; |
50 | 54 | use Google\Protobuf\GPBEmpty; |
| 55 | +use Google\Protobuf\Timestamp; |
51 | 56 |
|
52 | 57 | /** |
53 | 58 | * Service Description: The Notification Channel API provides access to configuration that |
@@ -815,4 +820,199 @@ public function deleteNotificationChannel($name, array $optionalArgs = []) |
815 | 820 | $request |
816 | 821 | )->wait(); |
817 | 822 | } |
| 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 | + } |
818 | 1018 | } |
0 commit comments