1# -*- coding: utf-8 -*-
2# Copyright 2024 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import dataclasses
17import json # type: ignore
18import logging
19from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
20import warnings
21
22from google.api_core import exceptions as core_exceptions
23from google.api_core import gapic_v1, rest_helpers, rest_streaming
24from google.api_core import retry as retries
25from google.auth import credentials as ga_credentials # type: ignore
26from google.auth.transport.requests import AuthorizedSession # type: ignore
27from google.iam.v1 import iam_policy_pb2 # type: ignore
28from google.iam.v1 import policy_pb2 # type: ignore
29from google.protobuf import empty_pb2 # type: ignore
30from google.protobuf import json_format
31from requests import __version__ as requests_version
32
33from google.cloud.secretmanager_v1beta1.types import resources, service
34
35from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
36from .rest_base import _BaseSecretManagerServiceRestTransport
37
38try:
39 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
40except AttributeError: # pragma: NO COVER
41 OptionalRetry = Union[retries.Retry, object, None] # type: ignore
42
43try:
44 from google.api_core import client_logging # type: ignore
45
46 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
47except ImportError: # pragma: NO COVER
48 CLIENT_LOGGING_SUPPORTED = False
49
50_LOGGER = logging.getLogger(__name__)
51
52DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
53 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
54 grpc_version=None,
55 rest_version=f"requests@{requests_version}",
56)
57
58
59class SecretManagerServiceRestInterceptor:
60 """Interceptor for SecretManagerService.
61
62 Interceptors are used to manipulate requests, request metadata, and responses
63 in arbitrary ways.
64 Example use cases include:
65 * Logging
66 * Verifying requests according to service or custom semantics
67 * Stripping extraneous information from responses
68
69 These use cases and more can be enabled by injecting an
70 instance of a custom subclass when constructing the SecretManagerServiceRestTransport.
71
72 .. code-block:: python
73 class MyCustomSecretManagerServiceInterceptor(SecretManagerServiceRestInterceptor):
74 def pre_access_secret_version(self, request, metadata):
75 logging.log(f"Received request: {request}")
76 return request, metadata
77
78 def post_access_secret_version(self, response):
79 logging.log(f"Received response: {response}")
80 return response
81
82 def pre_add_secret_version(self, request, metadata):
83 logging.log(f"Received request: {request}")
84 return request, metadata
85
86 def post_add_secret_version(self, response):
87 logging.log(f"Received response: {response}")
88 return response
89
90 def pre_create_secret(self, request, metadata):
91 logging.log(f"Received request: {request}")
92 return request, metadata
93
94 def post_create_secret(self, response):
95 logging.log(f"Received response: {response}")
96 return response
97
98 def pre_delete_secret(self, request, metadata):
99 logging.log(f"Received request: {request}")
100 return request, metadata
101
102 def pre_destroy_secret_version(self, request, metadata):
103 logging.log(f"Received request: {request}")
104 return request, metadata
105
106 def post_destroy_secret_version(self, response):
107 logging.log(f"Received response: {response}")
108 return response
109
110 def pre_disable_secret_version(self, request, metadata):
111 logging.log(f"Received request: {request}")
112 return request, metadata
113
114 def post_disable_secret_version(self, response):
115 logging.log(f"Received response: {response}")
116 return response
117
118 def pre_enable_secret_version(self, request, metadata):
119 logging.log(f"Received request: {request}")
120 return request, metadata
121
122 def post_enable_secret_version(self, response):
123 logging.log(f"Received response: {response}")
124 return response
125
126 def pre_get_iam_policy(self, request, metadata):
127 logging.log(f"Received request: {request}")
128 return request, metadata
129
130 def post_get_iam_policy(self, response):
131 logging.log(f"Received response: {response}")
132 return response
133
134 def pre_get_secret(self, request, metadata):
135 logging.log(f"Received request: {request}")
136 return request, metadata
137
138 def post_get_secret(self, response):
139 logging.log(f"Received response: {response}")
140 return response
141
142 def pre_get_secret_version(self, request, metadata):
143 logging.log(f"Received request: {request}")
144 return request, metadata
145
146 def post_get_secret_version(self, response):
147 logging.log(f"Received response: {response}")
148 return response
149
150 def pre_list_secrets(self, request, metadata):
151 logging.log(f"Received request: {request}")
152 return request, metadata
153
154 def post_list_secrets(self, response):
155 logging.log(f"Received response: {response}")
156 return response
157
158 def pre_list_secret_versions(self, request, metadata):
159 logging.log(f"Received request: {request}")
160 return request, metadata
161
162 def post_list_secret_versions(self, response):
163 logging.log(f"Received response: {response}")
164 return response
165
166 def pre_set_iam_policy(self, request, metadata):
167 logging.log(f"Received request: {request}")
168 return request, metadata
169
170 def post_set_iam_policy(self, response):
171 logging.log(f"Received response: {response}")
172 return response
173
174 def pre_test_iam_permissions(self, request, metadata):
175 logging.log(f"Received request: {request}")
176 return request, metadata
177
178 def post_test_iam_permissions(self, response):
179 logging.log(f"Received response: {response}")
180 return response
181
182 def pre_update_secret(self, request, metadata):
183 logging.log(f"Received request: {request}")
184 return request, metadata
185
186 def post_update_secret(self, response):
187 logging.log(f"Received response: {response}")
188 return response
189
190 transport = SecretManagerServiceRestTransport(interceptor=MyCustomSecretManagerServiceInterceptor())
191 client = SecretManagerServiceClient(transport=transport)
192
193
194 """
195
196 def pre_access_secret_version(
197 self,
198 request: service.AccessSecretVersionRequest,
199 metadata: Sequence[Tuple[str, Union[str, bytes]]],
200 ) -> Tuple[
201 service.AccessSecretVersionRequest, Sequence[Tuple[str, Union[str, bytes]]]
202 ]:
203 """Pre-rpc interceptor for access_secret_version
204
205 Override in a subclass to manipulate the request or metadata
206 before they are sent to the SecretManagerService server.
207 """
208 return request, metadata
209
210 def post_access_secret_version(
211 self, response: service.AccessSecretVersionResponse
212 ) -> service.AccessSecretVersionResponse:
213 """Post-rpc interceptor for access_secret_version
214
215 Override in a subclass to manipulate the response
216 after it is returned by the SecretManagerService server but before
217 it is returned to user code.
218 """
219 return response
220
221 def pre_add_secret_version(
222 self,
223 request: service.AddSecretVersionRequest,
224 metadata: Sequence[Tuple[str, Union[str, bytes]]],
225 ) -> Tuple[
226 service.AddSecretVersionRequest, Sequence[Tuple[str, Union[str, bytes]]]
227 ]:
228 """Pre-rpc interceptor for add_secret_version
229
230 Override in a subclass to manipulate the request or metadata
231 before they are sent to the SecretManagerService server.
232 """
233 return request, metadata
234
235 def post_add_secret_version(
236 self, response: resources.SecretVersion
237 ) -> resources.SecretVersion:
238 """Post-rpc interceptor for add_secret_version
239
240 Override in a subclass to manipulate the response
241 after it is returned by the SecretManagerService server but before
242 it is returned to user code.
243 """
244 return response
245
246 def pre_create_secret(
247 self,
248 request: service.CreateSecretRequest,
249 metadata: Sequence[Tuple[str, Union[str, bytes]]],
250 ) -> Tuple[service.CreateSecretRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
251 """Pre-rpc interceptor for create_secret
252
253 Override in a subclass to manipulate the request or metadata
254 before they are sent to the SecretManagerService server.
255 """
256 return request, metadata
257
258 def post_create_secret(self, response: resources.Secret) -> resources.Secret:
259 """Post-rpc interceptor for create_secret
260
261 Override in a subclass to manipulate the response
262 after it is returned by the SecretManagerService server but before
263 it is returned to user code.
264 """
265 return response
266
267 def pre_delete_secret(
268 self,
269 request: service.DeleteSecretRequest,
270 metadata: Sequence[Tuple[str, Union[str, bytes]]],
271 ) -> Tuple[service.DeleteSecretRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
272 """Pre-rpc interceptor for delete_secret
273
274 Override in a subclass to manipulate the request or metadata
275 before they are sent to the SecretManagerService server.
276 """
277 return request, metadata
278
279 def pre_destroy_secret_version(
280 self,
281 request: service.DestroySecretVersionRequest,
282 metadata: Sequence[Tuple[str, Union[str, bytes]]],
283 ) -> Tuple[
284 service.DestroySecretVersionRequest, Sequence[Tuple[str, Union[str, bytes]]]
285 ]:
286 """Pre-rpc interceptor for destroy_secret_version
287
288 Override in a subclass to manipulate the request or metadata
289 before they are sent to the SecretManagerService server.
290 """
291 return request, metadata
292
293 def post_destroy_secret_version(
294 self, response: resources.SecretVersion
295 ) -> resources.SecretVersion:
296 """Post-rpc interceptor for destroy_secret_version
297
298 Override in a subclass to manipulate the response
299 after it is returned by the SecretManagerService server but before
300 it is returned to user code.
301 """
302 return response
303
304 def pre_disable_secret_version(
305 self,
306 request: service.DisableSecretVersionRequest,
307 metadata: Sequence[Tuple[str, Union[str, bytes]]],
308 ) -> Tuple[
309 service.DisableSecretVersionRequest, Sequence[Tuple[str, Union[str, bytes]]]
310 ]:
311 """Pre-rpc interceptor for disable_secret_version
312
313 Override in a subclass to manipulate the request or metadata
314 before they are sent to the SecretManagerService server.
315 """
316 return request, metadata
317
318 def post_disable_secret_version(
319 self, response: resources.SecretVersion
320 ) -> resources.SecretVersion:
321 """Post-rpc interceptor for disable_secret_version
322
323 Override in a subclass to manipulate the response
324 after it is returned by the SecretManagerService server but before
325 it is returned to user code.
326 """
327 return response
328
329 def pre_enable_secret_version(
330 self,
331 request: service.EnableSecretVersionRequest,
332 metadata: Sequence[Tuple[str, Union[str, bytes]]],
333 ) -> Tuple[
334 service.EnableSecretVersionRequest, Sequence[Tuple[str, Union[str, bytes]]]
335 ]:
336 """Pre-rpc interceptor for enable_secret_version
337
338 Override in a subclass to manipulate the request or metadata
339 before they are sent to the SecretManagerService server.
340 """
341 return request, metadata
342
343 def post_enable_secret_version(
344 self, response: resources.SecretVersion
345 ) -> resources.SecretVersion:
346 """Post-rpc interceptor for enable_secret_version
347
348 Override in a subclass to manipulate the response
349 after it is returned by the SecretManagerService server but before
350 it is returned to user code.
351 """
352 return response
353
354 def pre_get_iam_policy(
355 self,
356 request: iam_policy_pb2.GetIamPolicyRequest,
357 metadata: Sequence[Tuple[str, Union[str, bytes]]],
358 ) -> Tuple[
359 iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]]
360 ]:
361 """Pre-rpc interceptor for get_iam_policy
362
363 Override in a subclass to manipulate the request or metadata
364 before they are sent to the SecretManagerService server.
365 """
366 return request, metadata
367
368 def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy:
369 """Post-rpc interceptor for get_iam_policy
370
371 Override in a subclass to manipulate the response
372 after it is returned by the SecretManagerService server but before
373 it is returned to user code.
374 """
375 return response
376
377 def pre_get_secret(
378 self,
379 request: service.GetSecretRequest,
380 metadata: Sequence[Tuple[str, Union[str, bytes]]],
381 ) -> Tuple[service.GetSecretRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
382 """Pre-rpc interceptor for get_secret
383
384 Override in a subclass to manipulate the request or metadata
385 before they are sent to the SecretManagerService server.
386 """
387 return request, metadata
388
389 def post_get_secret(self, response: resources.Secret) -> resources.Secret:
390 """Post-rpc interceptor for get_secret
391
392 Override in a subclass to manipulate the response
393 after it is returned by the SecretManagerService server but before
394 it is returned to user code.
395 """
396 return response
397
398 def pre_get_secret_version(
399 self,
400 request: service.GetSecretVersionRequest,
401 metadata: Sequence[Tuple[str, Union[str, bytes]]],
402 ) -> Tuple[
403 service.GetSecretVersionRequest, Sequence[Tuple[str, Union[str, bytes]]]
404 ]:
405 """Pre-rpc interceptor for get_secret_version
406
407 Override in a subclass to manipulate the request or metadata
408 before they are sent to the SecretManagerService server.
409 """
410 return request, metadata
411
412 def post_get_secret_version(
413 self, response: resources.SecretVersion
414 ) -> resources.SecretVersion:
415 """Post-rpc interceptor for get_secret_version
416
417 Override in a subclass to manipulate the response
418 after it is returned by the SecretManagerService server but before
419 it is returned to user code.
420 """
421 return response
422
423 def pre_list_secrets(
424 self,
425 request: service.ListSecretsRequest,
426 metadata: Sequence[Tuple[str, Union[str, bytes]]],
427 ) -> Tuple[service.ListSecretsRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
428 """Pre-rpc interceptor for list_secrets
429
430 Override in a subclass to manipulate the request or metadata
431 before they are sent to the SecretManagerService server.
432 """
433 return request, metadata
434
435 def post_list_secrets(
436 self, response: service.ListSecretsResponse
437 ) -> service.ListSecretsResponse:
438 """Post-rpc interceptor for list_secrets
439
440 Override in a subclass to manipulate the response
441 after it is returned by the SecretManagerService server but before
442 it is returned to user code.
443 """
444 return response
445
446 def pre_list_secret_versions(
447 self,
448 request: service.ListSecretVersionsRequest,
449 metadata: Sequence[Tuple[str, Union[str, bytes]]],
450 ) -> Tuple[
451 service.ListSecretVersionsRequest, Sequence[Tuple[str, Union[str, bytes]]]
452 ]:
453 """Pre-rpc interceptor for list_secret_versions
454
455 Override in a subclass to manipulate the request or metadata
456 before they are sent to the SecretManagerService server.
457 """
458 return request, metadata
459
460 def post_list_secret_versions(
461 self, response: service.ListSecretVersionsResponse
462 ) -> service.ListSecretVersionsResponse:
463 """Post-rpc interceptor for list_secret_versions
464
465 Override in a subclass to manipulate the response
466 after it is returned by the SecretManagerService server but before
467 it is returned to user code.
468 """
469 return response
470
471 def pre_set_iam_policy(
472 self,
473 request: iam_policy_pb2.SetIamPolicyRequest,
474 metadata: Sequence[Tuple[str, Union[str, bytes]]],
475 ) -> Tuple[
476 iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]]
477 ]:
478 """Pre-rpc interceptor for set_iam_policy
479
480 Override in a subclass to manipulate the request or metadata
481 before they are sent to the SecretManagerService server.
482 """
483 return request, metadata
484
485 def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy:
486 """Post-rpc interceptor for set_iam_policy
487
488 Override in a subclass to manipulate the response
489 after it is returned by the SecretManagerService server but before
490 it is returned to user code.
491 """
492 return response
493
494 def pre_test_iam_permissions(
495 self,
496 request: iam_policy_pb2.TestIamPermissionsRequest,
497 metadata: Sequence[Tuple[str, Union[str, bytes]]],
498 ) -> Tuple[
499 iam_policy_pb2.TestIamPermissionsRequest,
500 Sequence[Tuple[str, Union[str, bytes]]],
501 ]:
502 """Pre-rpc interceptor for test_iam_permissions
503
504 Override in a subclass to manipulate the request or metadata
505 before they are sent to the SecretManagerService server.
506 """
507 return request, metadata
508
509 def post_test_iam_permissions(
510 self, response: iam_policy_pb2.TestIamPermissionsResponse
511 ) -> iam_policy_pb2.TestIamPermissionsResponse:
512 """Post-rpc interceptor for test_iam_permissions
513
514 Override in a subclass to manipulate the response
515 after it is returned by the SecretManagerService server but before
516 it is returned to user code.
517 """
518 return response
519
520 def pre_update_secret(
521 self,
522 request: service.UpdateSecretRequest,
523 metadata: Sequence[Tuple[str, Union[str, bytes]]],
524 ) -> Tuple[service.UpdateSecretRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
525 """Pre-rpc interceptor for update_secret
526
527 Override in a subclass to manipulate the request or metadata
528 before they are sent to the SecretManagerService server.
529 """
530 return request, metadata
531
532 def post_update_secret(self, response: resources.Secret) -> resources.Secret:
533 """Post-rpc interceptor for update_secret
534
535 Override in a subclass to manipulate the response
536 after it is returned by the SecretManagerService server but before
537 it is returned to user code.
538 """
539 return response
540
541
542@dataclasses.dataclass
543class SecretManagerServiceRestStub:
544 _session: AuthorizedSession
545 _host: str
546 _interceptor: SecretManagerServiceRestInterceptor
547
548
549class SecretManagerServiceRestTransport(_BaseSecretManagerServiceRestTransport):
550 """REST backend synchronous transport for SecretManagerService.
551
552 Secret Manager Service
553
554 Manages secrets and operations using those secrets. Implements a
555 REST model with the following objects:
556
557 - [Secret][google.cloud.secrets.v1beta1.Secret]
558 - [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]
559
560 This class defines the same methods as the primary client, so the
561 primary client can load the underlying transport implementation
562 and call it.
563
564 It sends JSON representations of protocol buffers over HTTP/1.1
565 """
566
567 def __init__(
568 self,
569 *,
570 host: str = "secretmanager.googleapis.com",
571 credentials: Optional[ga_credentials.Credentials] = None,
572 credentials_file: Optional[str] = None,
573 scopes: Optional[Sequence[str]] = None,
574 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
575 quota_project_id: Optional[str] = None,
576 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
577 always_use_jwt_access: Optional[bool] = False,
578 url_scheme: str = "https",
579 interceptor: Optional[SecretManagerServiceRestInterceptor] = None,
580 api_audience: Optional[str] = None,
581 ) -> None:
582 """Instantiate the transport.
583
584 Args:
585 host (Optional[str]):
586 The hostname to connect to (default: 'secretmanager.googleapis.com').
587 credentials (Optional[google.auth.credentials.Credentials]): The
588 authorization credentials to attach to requests. These
589 credentials identify the application to the service; if none
590 are specified, the client will attempt to ascertain the
591 credentials from the environment.
592
593 credentials_file (Optional[str]): A file with credentials that can
594 be loaded with :func:`google.auth.load_credentials_from_file`.
595 This argument is ignored if ``channel`` is provided.
596 scopes (Optional(Sequence[str])): A list of scopes. This argument is
597 ignored if ``channel`` is provided.
598 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
599 certificate to configure mutual TLS HTTP channel. It is ignored
600 if ``channel`` is provided.
601 quota_project_id (Optional[str]): An optional project to use for billing
602 and quota.
603 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
604 The client info used to send a user-agent string along with
605 API requests. If ``None``, then default info will be used.
606 Generally, you only need to set this if you are developing
607 your own client library.
608 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
609 be used for service account credentials.
610 url_scheme: the protocol scheme for the API endpoint. Normally
611 "https", but for testing or local servers,
612 "http" can be specified.
613 """
614 # Run the base constructor
615 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
616 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
617 # credentials object
618 super().__init__(
619 host=host,
620 credentials=credentials,
621 client_info=client_info,
622 always_use_jwt_access=always_use_jwt_access,
623 url_scheme=url_scheme,
624 api_audience=api_audience,
625 )
626 self._session = AuthorizedSession(
627 self._credentials, default_host=self.DEFAULT_HOST
628 )
629 if client_cert_source_for_mtls:
630 self._session.configure_mtls_channel(client_cert_source_for_mtls)
631 self._interceptor = interceptor or SecretManagerServiceRestInterceptor()
632 self._prep_wrapped_messages(client_info)
633
634 class _AccessSecretVersion(
635 _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion,
636 SecretManagerServiceRestStub,
637 ):
638 def __hash__(self):
639 return hash("SecretManagerServiceRestTransport.AccessSecretVersion")
640
641 @staticmethod
642 def _get_response(
643 host,
644 metadata,
645 query_params,
646 session,
647 timeout,
648 transcoded_request,
649 body=None,
650 ):
651 uri = transcoded_request["uri"]
652 method = transcoded_request["method"]
653 headers = dict(metadata)
654 headers["Content-Type"] = "application/json"
655 response = getattr(session, method)(
656 "{host}{uri}".format(host=host, uri=uri),
657 timeout=timeout,
658 headers=headers,
659 params=rest_helpers.flatten_query_params(query_params, strict=True),
660 )
661 return response
662
663 def __call__(
664 self,
665 request: service.AccessSecretVersionRequest,
666 *,
667 retry: OptionalRetry = gapic_v1.method.DEFAULT,
668 timeout: Optional[float] = None,
669 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
670 ) -> service.AccessSecretVersionResponse:
671 r"""Call the access secret version method over HTTP.
672
673 Args:
674 request (~.service.AccessSecretVersionRequest):
675 The request object. Request message for
676 [SecretManagerService.AccessSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AccessSecretVersion].
677 retry (google.api_core.retry.Retry): Designation of what errors, if any,
678 should be retried.
679 timeout (float): The timeout for this request.
680 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
681 sent along with the request as metadata. Normally, each value must be of type `str`,
682 but for metadata keys ending with the suffix `-bin`, the corresponding values must
683 be of type `bytes`.
684
685 Returns:
686 ~.service.AccessSecretVersionResponse:
687 Response message for
688 [SecretManagerService.AccessSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AccessSecretVersion].
689
690 """
691
692 http_options = (
693 _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion._get_http_options()
694 )
695
696 request, metadata = self._interceptor.pre_access_secret_version(
697 request, metadata
698 )
699 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion._get_transcoded_request(
700 http_options, request
701 )
702
703 # Jsonify the query params
704 query_params = _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion._get_query_params_json(
705 transcoded_request
706 )
707
708 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
709 logging.DEBUG
710 ): # pragma: NO COVER
711 request_url = "{host}{uri}".format(
712 host=self._host, uri=transcoded_request["uri"]
713 )
714 method = transcoded_request["method"]
715 try:
716 request_payload = type(request).to_json(request)
717 except:
718 request_payload = None
719 http_request = {
720 "payload": request_payload,
721 "requestMethod": method,
722 "requestUrl": request_url,
723 "headers": dict(metadata),
724 }
725 _LOGGER.debug(
726 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.AccessSecretVersion",
727 extra={
728 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
729 "rpcName": "AccessSecretVersion",
730 "httpRequest": http_request,
731 "metadata": http_request["headers"],
732 },
733 )
734
735 # Send the request
736 response = (
737 SecretManagerServiceRestTransport._AccessSecretVersion._get_response(
738 self._host,
739 metadata,
740 query_params,
741 self._session,
742 timeout,
743 transcoded_request,
744 )
745 )
746
747 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
748 # subclass.
749 if response.status_code >= 400:
750 raise core_exceptions.from_http_response(response)
751
752 # Return the response
753 resp = service.AccessSecretVersionResponse()
754 pb_resp = service.AccessSecretVersionResponse.pb(resp)
755
756 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
757
758 resp = self._interceptor.post_access_secret_version(resp)
759 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
760 logging.DEBUG
761 ): # pragma: NO COVER
762 try:
763 response_payload = service.AccessSecretVersionResponse.to_json(
764 response
765 )
766 except:
767 response_payload = None
768 http_response = {
769 "payload": response_payload,
770 "headers": dict(response.headers),
771 "status": response.status_code,
772 }
773 _LOGGER.debug(
774 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.access_secret_version",
775 extra={
776 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
777 "rpcName": "AccessSecretVersion",
778 "metadata": http_response["headers"],
779 "httpResponse": http_response,
780 },
781 )
782 return resp
783
784 class _AddSecretVersion(
785 _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion,
786 SecretManagerServiceRestStub,
787 ):
788 def __hash__(self):
789 return hash("SecretManagerServiceRestTransport.AddSecretVersion")
790
791 @staticmethod
792 def _get_response(
793 host,
794 metadata,
795 query_params,
796 session,
797 timeout,
798 transcoded_request,
799 body=None,
800 ):
801 uri = transcoded_request["uri"]
802 method = transcoded_request["method"]
803 headers = dict(metadata)
804 headers["Content-Type"] = "application/json"
805 response = getattr(session, method)(
806 "{host}{uri}".format(host=host, uri=uri),
807 timeout=timeout,
808 headers=headers,
809 params=rest_helpers.flatten_query_params(query_params, strict=True),
810 data=body,
811 )
812 return response
813
814 def __call__(
815 self,
816 request: service.AddSecretVersionRequest,
817 *,
818 retry: OptionalRetry = gapic_v1.method.DEFAULT,
819 timeout: Optional[float] = None,
820 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
821 ) -> resources.SecretVersion:
822 r"""Call the add secret version method over HTTP.
823
824 Args:
825 request (~.service.AddSecretVersionRequest):
826 The request object. Request message for
827 [SecretManagerService.AddSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AddSecretVersion].
828 retry (google.api_core.retry.Retry): Designation of what errors, if any,
829 should be retried.
830 timeout (float): The timeout for this request.
831 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
832 sent along with the request as metadata. Normally, each value must be of type `str`,
833 but for metadata keys ending with the suffix `-bin`, the corresponding values must
834 be of type `bytes`.
835
836 Returns:
837 ~.resources.SecretVersion:
838 A secret version resource in the
839 Secret Manager API.
840
841 """
842
843 http_options = (
844 _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_http_options()
845 )
846
847 request, metadata = self._interceptor.pre_add_secret_version(
848 request, metadata
849 )
850 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_transcoded_request(
851 http_options, request
852 )
853
854 body = _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_request_body_json(
855 transcoded_request
856 )
857
858 # Jsonify the query params
859 query_params = _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_query_params_json(
860 transcoded_request
861 )
862
863 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
864 logging.DEBUG
865 ): # pragma: NO COVER
866 request_url = "{host}{uri}".format(
867 host=self._host, uri=transcoded_request["uri"]
868 )
869 method = transcoded_request["method"]
870 try:
871 request_payload = type(request).to_json(request)
872 except:
873 request_payload = None
874 http_request = {
875 "payload": request_payload,
876 "requestMethod": method,
877 "requestUrl": request_url,
878 "headers": dict(metadata),
879 }
880 _LOGGER.debug(
881 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.AddSecretVersion",
882 extra={
883 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
884 "rpcName": "AddSecretVersion",
885 "httpRequest": http_request,
886 "metadata": http_request["headers"],
887 },
888 )
889
890 # Send the request
891 response = (
892 SecretManagerServiceRestTransport._AddSecretVersion._get_response(
893 self._host,
894 metadata,
895 query_params,
896 self._session,
897 timeout,
898 transcoded_request,
899 body,
900 )
901 )
902
903 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
904 # subclass.
905 if response.status_code >= 400:
906 raise core_exceptions.from_http_response(response)
907
908 # Return the response
909 resp = resources.SecretVersion()
910 pb_resp = resources.SecretVersion.pb(resp)
911
912 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
913
914 resp = self._interceptor.post_add_secret_version(resp)
915 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
916 logging.DEBUG
917 ): # pragma: NO COVER
918 try:
919 response_payload = resources.SecretVersion.to_json(response)
920 except:
921 response_payload = None
922 http_response = {
923 "payload": response_payload,
924 "headers": dict(response.headers),
925 "status": response.status_code,
926 }
927 _LOGGER.debug(
928 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.add_secret_version",
929 extra={
930 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
931 "rpcName": "AddSecretVersion",
932 "metadata": http_response["headers"],
933 "httpResponse": http_response,
934 },
935 )
936 return resp
937
938 class _CreateSecret(
939 _BaseSecretManagerServiceRestTransport._BaseCreateSecret,
940 SecretManagerServiceRestStub,
941 ):
942 def __hash__(self):
943 return hash("SecretManagerServiceRestTransport.CreateSecret")
944
945 @staticmethod
946 def _get_response(
947 host,
948 metadata,
949 query_params,
950 session,
951 timeout,
952 transcoded_request,
953 body=None,
954 ):
955 uri = transcoded_request["uri"]
956 method = transcoded_request["method"]
957 headers = dict(metadata)
958 headers["Content-Type"] = "application/json"
959 response = getattr(session, method)(
960 "{host}{uri}".format(host=host, uri=uri),
961 timeout=timeout,
962 headers=headers,
963 params=rest_helpers.flatten_query_params(query_params, strict=True),
964 data=body,
965 )
966 return response
967
968 def __call__(
969 self,
970 request: service.CreateSecretRequest,
971 *,
972 retry: OptionalRetry = gapic_v1.method.DEFAULT,
973 timeout: Optional[float] = None,
974 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
975 ) -> resources.Secret:
976 r"""Call the create secret method over HTTP.
977
978 Args:
979 request (~.service.CreateSecretRequest):
980 The request object. Request message for
981 [SecretManagerService.CreateSecret][google.cloud.secrets.v1beta1.SecretManagerService.CreateSecret].
982 retry (google.api_core.retry.Retry): Designation of what errors, if any,
983 should be retried.
984 timeout (float): The timeout for this request.
985 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
986 sent along with the request as metadata. Normally, each value must be of type `str`,
987 but for metadata keys ending with the suffix `-bin`, the corresponding values must
988 be of type `bytes`.
989
990 Returns:
991 ~.resources.Secret:
992 A [Secret][google.cloud.secrets.v1beta1.Secret] is a
993 logical secret whose value and versions can be accessed.
994
995 A [Secret][google.cloud.secrets.v1beta1.Secret] is made
996 up of zero or more
997 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]
998 that represent the secret data.
999
1000 """
1001
1002 http_options = (
1003 _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_http_options()
1004 )
1005
1006 request, metadata = self._interceptor.pre_create_secret(request, metadata)
1007 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_transcoded_request(
1008 http_options, request
1009 )
1010
1011 body = _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_request_body_json(
1012 transcoded_request
1013 )
1014
1015 # Jsonify the query params
1016 query_params = _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_query_params_json(
1017 transcoded_request
1018 )
1019
1020 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1021 logging.DEBUG
1022 ): # pragma: NO COVER
1023 request_url = "{host}{uri}".format(
1024 host=self._host, uri=transcoded_request["uri"]
1025 )
1026 method = transcoded_request["method"]
1027 try:
1028 request_payload = type(request).to_json(request)
1029 except:
1030 request_payload = None
1031 http_request = {
1032 "payload": request_payload,
1033 "requestMethod": method,
1034 "requestUrl": request_url,
1035 "headers": dict(metadata),
1036 }
1037 _LOGGER.debug(
1038 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.CreateSecret",
1039 extra={
1040 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1041 "rpcName": "CreateSecret",
1042 "httpRequest": http_request,
1043 "metadata": http_request["headers"],
1044 },
1045 )
1046
1047 # Send the request
1048 response = SecretManagerServiceRestTransport._CreateSecret._get_response(
1049 self._host,
1050 metadata,
1051 query_params,
1052 self._session,
1053 timeout,
1054 transcoded_request,
1055 body,
1056 )
1057
1058 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1059 # subclass.
1060 if response.status_code >= 400:
1061 raise core_exceptions.from_http_response(response)
1062
1063 # Return the response
1064 resp = resources.Secret()
1065 pb_resp = resources.Secret.pb(resp)
1066
1067 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1068
1069 resp = self._interceptor.post_create_secret(resp)
1070 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1071 logging.DEBUG
1072 ): # pragma: NO COVER
1073 try:
1074 response_payload = resources.Secret.to_json(response)
1075 except:
1076 response_payload = None
1077 http_response = {
1078 "payload": response_payload,
1079 "headers": dict(response.headers),
1080 "status": response.status_code,
1081 }
1082 _LOGGER.debug(
1083 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.create_secret",
1084 extra={
1085 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1086 "rpcName": "CreateSecret",
1087 "metadata": http_response["headers"],
1088 "httpResponse": http_response,
1089 },
1090 )
1091 return resp
1092
1093 class _DeleteSecret(
1094 _BaseSecretManagerServiceRestTransport._BaseDeleteSecret,
1095 SecretManagerServiceRestStub,
1096 ):
1097 def __hash__(self):
1098 return hash("SecretManagerServiceRestTransport.DeleteSecret")
1099
1100 @staticmethod
1101 def _get_response(
1102 host,
1103 metadata,
1104 query_params,
1105 session,
1106 timeout,
1107 transcoded_request,
1108 body=None,
1109 ):
1110 uri = transcoded_request["uri"]
1111 method = transcoded_request["method"]
1112 headers = dict(metadata)
1113 headers["Content-Type"] = "application/json"
1114 response = getattr(session, method)(
1115 "{host}{uri}".format(host=host, uri=uri),
1116 timeout=timeout,
1117 headers=headers,
1118 params=rest_helpers.flatten_query_params(query_params, strict=True),
1119 )
1120 return response
1121
1122 def __call__(
1123 self,
1124 request: service.DeleteSecretRequest,
1125 *,
1126 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1127 timeout: Optional[float] = None,
1128 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1129 ):
1130 r"""Call the delete secret method over HTTP.
1131
1132 Args:
1133 request (~.service.DeleteSecretRequest):
1134 The request object. Request message for
1135 [SecretManagerService.DeleteSecret][google.cloud.secrets.v1beta1.SecretManagerService.DeleteSecret].
1136 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1137 should be retried.
1138 timeout (float): The timeout for this request.
1139 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1140 sent along with the request as metadata. Normally, each value must be of type `str`,
1141 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1142 be of type `bytes`.
1143 """
1144
1145 http_options = (
1146 _BaseSecretManagerServiceRestTransport._BaseDeleteSecret._get_http_options()
1147 )
1148
1149 request, metadata = self._interceptor.pre_delete_secret(request, metadata)
1150 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseDeleteSecret._get_transcoded_request(
1151 http_options, request
1152 )
1153
1154 # Jsonify the query params
1155 query_params = _BaseSecretManagerServiceRestTransport._BaseDeleteSecret._get_query_params_json(
1156 transcoded_request
1157 )
1158
1159 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1160 logging.DEBUG
1161 ): # pragma: NO COVER
1162 request_url = "{host}{uri}".format(
1163 host=self._host, uri=transcoded_request["uri"]
1164 )
1165 method = transcoded_request["method"]
1166 try:
1167 request_payload = json_format.MessageToJson(request)
1168 except:
1169 request_payload = None
1170 http_request = {
1171 "payload": request_payload,
1172 "requestMethod": method,
1173 "requestUrl": request_url,
1174 "headers": dict(metadata),
1175 }
1176 _LOGGER.debug(
1177 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.DeleteSecret",
1178 extra={
1179 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1180 "rpcName": "DeleteSecret",
1181 "httpRequest": http_request,
1182 "metadata": http_request["headers"],
1183 },
1184 )
1185
1186 # Send the request
1187 response = SecretManagerServiceRestTransport._DeleteSecret._get_response(
1188 self._host,
1189 metadata,
1190 query_params,
1191 self._session,
1192 timeout,
1193 transcoded_request,
1194 )
1195
1196 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1197 # subclass.
1198 if response.status_code >= 400:
1199 raise core_exceptions.from_http_response(response)
1200
1201 class _DestroySecretVersion(
1202 _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion,
1203 SecretManagerServiceRestStub,
1204 ):
1205 def __hash__(self):
1206 return hash("SecretManagerServiceRestTransport.DestroySecretVersion")
1207
1208 @staticmethod
1209 def _get_response(
1210 host,
1211 metadata,
1212 query_params,
1213 session,
1214 timeout,
1215 transcoded_request,
1216 body=None,
1217 ):
1218 uri = transcoded_request["uri"]
1219 method = transcoded_request["method"]
1220 headers = dict(metadata)
1221 headers["Content-Type"] = "application/json"
1222 response = getattr(session, method)(
1223 "{host}{uri}".format(host=host, uri=uri),
1224 timeout=timeout,
1225 headers=headers,
1226 params=rest_helpers.flatten_query_params(query_params, strict=True),
1227 data=body,
1228 )
1229 return response
1230
1231 def __call__(
1232 self,
1233 request: service.DestroySecretVersionRequest,
1234 *,
1235 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1236 timeout: Optional[float] = None,
1237 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1238 ) -> resources.SecretVersion:
1239 r"""Call the destroy secret version method over HTTP.
1240
1241 Args:
1242 request (~.service.DestroySecretVersionRequest):
1243 The request object. Request message for
1244 [SecretManagerService.DestroySecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.DestroySecretVersion].
1245 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1246 should be retried.
1247 timeout (float): The timeout for this request.
1248 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1249 sent along with the request as metadata. Normally, each value must be of type `str`,
1250 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1251 be of type `bytes`.
1252
1253 Returns:
1254 ~.resources.SecretVersion:
1255 A secret version resource in the
1256 Secret Manager API.
1257
1258 """
1259
1260 http_options = (
1261 _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_http_options()
1262 )
1263
1264 request, metadata = self._interceptor.pre_destroy_secret_version(
1265 request, metadata
1266 )
1267 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_transcoded_request(
1268 http_options, request
1269 )
1270
1271 body = _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_request_body_json(
1272 transcoded_request
1273 )
1274
1275 # Jsonify the query params
1276 query_params = _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_query_params_json(
1277 transcoded_request
1278 )
1279
1280 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1281 logging.DEBUG
1282 ): # pragma: NO COVER
1283 request_url = "{host}{uri}".format(
1284 host=self._host, uri=transcoded_request["uri"]
1285 )
1286 method = transcoded_request["method"]
1287 try:
1288 request_payload = type(request).to_json(request)
1289 except:
1290 request_payload = None
1291 http_request = {
1292 "payload": request_payload,
1293 "requestMethod": method,
1294 "requestUrl": request_url,
1295 "headers": dict(metadata),
1296 }
1297 _LOGGER.debug(
1298 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.DestroySecretVersion",
1299 extra={
1300 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1301 "rpcName": "DestroySecretVersion",
1302 "httpRequest": http_request,
1303 "metadata": http_request["headers"],
1304 },
1305 )
1306
1307 # Send the request
1308 response = (
1309 SecretManagerServiceRestTransport._DestroySecretVersion._get_response(
1310 self._host,
1311 metadata,
1312 query_params,
1313 self._session,
1314 timeout,
1315 transcoded_request,
1316 body,
1317 )
1318 )
1319
1320 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1321 # subclass.
1322 if response.status_code >= 400:
1323 raise core_exceptions.from_http_response(response)
1324
1325 # Return the response
1326 resp = resources.SecretVersion()
1327 pb_resp = resources.SecretVersion.pb(resp)
1328
1329 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1330
1331 resp = self._interceptor.post_destroy_secret_version(resp)
1332 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1333 logging.DEBUG
1334 ): # pragma: NO COVER
1335 try:
1336 response_payload = resources.SecretVersion.to_json(response)
1337 except:
1338 response_payload = None
1339 http_response = {
1340 "payload": response_payload,
1341 "headers": dict(response.headers),
1342 "status": response.status_code,
1343 }
1344 _LOGGER.debug(
1345 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.destroy_secret_version",
1346 extra={
1347 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1348 "rpcName": "DestroySecretVersion",
1349 "metadata": http_response["headers"],
1350 "httpResponse": http_response,
1351 },
1352 )
1353 return resp
1354
1355 class _DisableSecretVersion(
1356 _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion,
1357 SecretManagerServiceRestStub,
1358 ):
1359 def __hash__(self):
1360 return hash("SecretManagerServiceRestTransport.DisableSecretVersion")
1361
1362 @staticmethod
1363 def _get_response(
1364 host,
1365 metadata,
1366 query_params,
1367 session,
1368 timeout,
1369 transcoded_request,
1370 body=None,
1371 ):
1372 uri = transcoded_request["uri"]
1373 method = transcoded_request["method"]
1374 headers = dict(metadata)
1375 headers["Content-Type"] = "application/json"
1376 response = getattr(session, method)(
1377 "{host}{uri}".format(host=host, uri=uri),
1378 timeout=timeout,
1379 headers=headers,
1380 params=rest_helpers.flatten_query_params(query_params, strict=True),
1381 data=body,
1382 )
1383 return response
1384
1385 def __call__(
1386 self,
1387 request: service.DisableSecretVersionRequest,
1388 *,
1389 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1390 timeout: Optional[float] = None,
1391 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1392 ) -> resources.SecretVersion:
1393 r"""Call the disable secret version method over HTTP.
1394
1395 Args:
1396 request (~.service.DisableSecretVersionRequest):
1397 The request object. Request message for
1398 [SecretManagerService.DisableSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.DisableSecretVersion].
1399 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1400 should be retried.
1401 timeout (float): The timeout for this request.
1402 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1403 sent along with the request as metadata. Normally, each value must be of type `str`,
1404 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1405 be of type `bytes`.
1406
1407 Returns:
1408 ~.resources.SecretVersion:
1409 A secret version resource in the
1410 Secret Manager API.
1411
1412 """
1413
1414 http_options = (
1415 _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_http_options()
1416 )
1417
1418 request, metadata = self._interceptor.pre_disable_secret_version(
1419 request, metadata
1420 )
1421 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_transcoded_request(
1422 http_options, request
1423 )
1424
1425 body = _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_request_body_json(
1426 transcoded_request
1427 )
1428
1429 # Jsonify the query params
1430 query_params = _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_query_params_json(
1431 transcoded_request
1432 )
1433
1434 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1435 logging.DEBUG
1436 ): # pragma: NO COVER
1437 request_url = "{host}{uri}".format(
1438 host=self._host, uri=transcoded_request["uri"]
1439 )
1440 method = transcoded_request["method"]
1441 try:
1442 request_payload = type(request).to_json(request)
1443 except:
1444 request_payload = None
1445 http_request = {
1446 "payload": request_payload,
1447 "requestMethod": method,
1448 "requestUrl": request_url,
1449 "headers": dict(metadata),
1450 }
1451 _LOGGER.debug(
1452 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.DisableSecretVersion",
1453 extra={
1454 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1455 "rpcName": "DisableSecretVersion",
1456 "httpRequest": http_request,
1457 "metadata": http_request["headers"],
1458 },
1459 )
1460
1461 # Send the request
1462 response = (
1463 SecretManagerServiceRestTransport._DisableSecretVersion._get_response(
1464 self._host,
1465 metadata,
1466 query_params,
1467 self._session,
1468 timeout,
1469 transcoded_request,
1470 body,
1471 )
1472 )
1473
1474 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1475 # subclass.
1476 if response.status_code >= 400:
1477 raise core_exceptions.from_http_response(response)
1478
1479 # Return the response
1480 resp = resources.SecretVersion()
1481 pb_resp = resources.SecretVersion.pb(resp)
1482
1483 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1484
1485 resp = self._interceptor.post_disable_secret_version(resp)
1486 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1487 logging.DEBUG
1488 ): # pragma: NO COVER
1489 try:
1490 response_payload = resources.SecretVersion.to_json(response)
1491 except:
1492 response_payload = None
1493 http_response = {
1494 "payload": response_payload,
1495 "headers": dict(response.headers),
1496 "status": response.status_code,
1497 }
1498 _LOGGER.debug(
1499 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.disable_secret_version",
1500 extra={
1501 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1502 "rpcName": "DisableSecretVersion",
1503 "metadata": http_response["headers"],
1504 "httpResponse": http_response,
1505 },
1506 )
1507 return resp
1508
1509 class _EnableSecretVersion(
1510 _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion,
1511 SecretManagerServiceRestStub,
1512 ):
1513 def __hash__(self):
1514 return hash("SecretManagerServiceRestTransport.EnableSecretVersion")
1515
1516 @staticmethod
1517 def _get_response(
1518 host,
1519 metadata,
1520 query_params,
1521 session,
1522 timeout,
1523 transcoded_request,
1524 body=None,
1525 ):
1526 uri = transcoded_request["uri"]
1527 method = transcoded_request["method"]
1528 headers = dict(metadata)
1529 headers["Content-Type"] = "application/json"
1530 response = getattr(session, method)(
1531 "{host}{uri}".format(host=host, uri=uri),
1532 timeout=timeout,
1533 headers=headers,
1534 params=rest_helpers.flatten_query_params(query_params, strict=True),
1535 data=body,
1536 )
1537 return response
1538
1539 def __call__(
1540 self,
1541 request: service.EnableSecretVersionRequest,
1542 *,
1543 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1544 timeout: Optional[float] = None,
1545 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1546 ) -> resources.SecretVersion:
1547 r"""Call the enable secret version method over HTTP.
1548
1549 Args:
1550 request (~.service.EnableSecretVersionRequest):
1551 The request object. Request message for
1552 [SecretManagerService.EnableSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.EnableSecretVersion].
1553 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1554 should be retried.
1555 timeout (float): The timeout for this request.
1556 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1557 sent along with the request as metadata. Normally, each value must be of type `str`,
1558 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1559 be of type `bytes`.
1560
1561 Returns:
1562 ~.resources.SecretVersion:
1563 A secret version resource in the
1564 Secret Manager API.
1565
1566 """
1567
1568 http_options = (
1569 _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_http_options()
1570 )
1571
1572 request, metadata = self._interceptor.pre_enable_secret_version(
1573 request, metadata
1574 )
1575 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_transcoded_request(
1576 http_options, request
1577 )
1578
1579 body = _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_request_body_json(
1580 transcoded_request
1581 )
1582
1583 # Jsonify the query params
1584 query_params = _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_query_params_json(
1585 transcoded_request
1586 )
1587
1588 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1589 logging.DEBUG
1590 ): # pragma: NO COVER
1591 request_url = "{host}{uri}".format(
1592 host=self._host, uri=transcoded_request["uri"]
1593 )
1594 method = transcoded_request["method"]
1595 try:
1596 request_payload = type(request).to_json(request)
1597 except:
1598 request_payload = None
1599 http_request = {
1600 "payload": request_payload,
1601 "requestMethod": method,
1602 "requestUrl": request_url,
1603 "headers": dict(metadata),
1604 }
1605 _LOGGER.debug(
1606 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.EnableSecretVersion",
1607 extra={
1608 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1609 "rpcName": "EnableSecretVersion",
1610 "httpRequest": http_request,
1611 "metadata": http_request["headers"],
1612 },
1613 )
1614
1615 # Send the request
1616 response = (
1617 SecretManagerServiceRestTransport._EnableSecretVersion._get_response(
1618 self._host,
1619 metadata,
1620 query_params,
1621 self._session,
1622 timeout,
1623 transcoded_request,
1624 body,
1625 )
1626 )
1627
1628 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1629 # subclass.
1630 if response.status_code >= 400:
1631 raise core_exceptions.from_http_response(response)
1632
1633 # Return the response
1634 resp = resources.SecretVersion()
1635 pb_resp = resources.SecretVersion.pb(resp)
1636
1637 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1638
1639 resp = self._interceptor.post_enable_secret_version(resp)
1640 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1641 logging.DEBUG
1642 ): # pragma: NO COVER
1643 try:
1644 response_payload = resources.SecretVersion.to_json(response)
1645 except:
1646 response_payload = None
1647 http_response = {
1648 "payload": response_payload,
1649 "headers": dict(response.headers),
1650 "status": response.status_code,
1651 }
1652 _LOGGER.debug(
1653 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.enable_secret_version",
1654 extra={
1655 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1656 "rpcName": "EnableSecretVersion",
1657 "metadata": http_response["headers"],
1658 "httpResponse": http_response,
1659 },
1660 )
1661 return resp
1662
1663 class _GetIamPolicy(
1664 _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy,
1665 SecretManagerServiceRestStub,
1666 ):
1667 def __hash__(self):
1668 return hash("SecretManagerServiceRestTransport.GetIamPolicy")
1669
1670 @staticmethod
1671 def _get_response(
1672 host,
1673 metadata,
1674 query_params,
1675 session,
1676 timeout,
1677 transcoded_request,
1678 body=None,
1679 ):
1680 uri = transcoded_request["uri"]
1681 method = transcoded_request["method"]
1682 headers = dict(metadata)
1683 headers["Content-Type"] = "application/json"
1684 response = getattr(session, method)(
1685 "{host}{uri}".format(host=host, uri=uri),
1686 timeout=timeout,
1687 headers=headers,
1688 params=rest_helpers.flatten_query_params(query_params, strict=True),
1689 )
1690 return response
1691
1692 def __call__(
1693 self,
1694 request: iam_policy_pb2.GetIamPolicyRequest,
1695 *,
1696 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1697 timeout: Optional[float] = None,
1698 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1699 ) -> policy_pb2.Policy:
1700 r"""Call the get iam policy method over HTTP.
1701
1702 Args:
1703 request (~.iam_policy_pb2.GetIamPolicyRequest):
1704 The request object. Request message for ``GetIamPolicy`` method.
1705 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1706 should be retried.
1707 timeout (float): The timeout for this request.
1708 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1709 sent along with the request as metadata. Normally, each value must be of type `str`,
1710 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1711 be of type `bytes`.
1712
1713 Returns:
1714 ~.policy_pb2.Policy:
1715 An Identity and Access Management (IAM) policy, which
1716 specifies access controls for Google Cloud resources.
1717
1718 A ``Policy`` is a collection of ``bindings``. A
1719 ``binding`` binds one or more ``members``, or
1720 principals, to a single ``role``. Principals can be user
1721 accounts, service accounts, Google groups, and domains
1722 (such as G Suite). A ``role`` is a named list of
1723 permissions; each ``role`` can be an IAM predefined role
1724 or a user-created custom role.
1725
1726 For some types of Google Cloud resources, a ``binding``
1727 can also specify a ``condition``, which is a logical
1728 expression that allows access to a resource only if the
1729 expression evaluates to ``true``. A condition can add
1730 constraints based on attributes of the request, the
1731 resource, or both. To learn which resources support
1732 conditions in their IAM policies, see the `IAM
1733 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__.
1734
1735 **JSON example:**
1736
1737 ::
1738
1739 {
1740 "bindings": [
1741 {
1742 "role": "roles/resourcemanager.organizationAdmin",
1743 "members": [
1744 "user:mike@example.com",
1745 "group:admins@example.com",
1746 "domain:google.com",
1747 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1748 ]
1749 },
1750 {
1751 "role": "roles/resourcemanager.organizationViewer",
1752 "members": [
1753 "user:eve@example.com"
1754 ],
1755 "condition": {
1756 "title": "expirable access",
1757 "description": "Does not grant access after Sep 2020",
1758 "expression": "request.time <
1759 timestamp('2020-10-01T00:00:00.000Z')",
1760 }
1761 }
1762 ],
1763 "etag": "BwWWja0YfJA=",
1764 "version": 3
1765 }
1766
1767 **YAML example:**
1768
1769 ::
1770
1771 bindings:
1772 - members:
1773 - user:mike@example.com
1774 - group:admins@example.com
1775 - domain:google.com
1776 - serviceAccount:my-project-id@appspot.gserviceaccount.com
1777 role: roles/resourcemanager.organizationAdmin
1778 - members:
1779 - user:eve@example.com
1780 role: roles/resourcemanager.organizationViewer
1781 condition:
1782 title: expirable access
1783 description: Does not grant access after Sep 2020
1784 expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
1785 etag: BwWWja0YfJA=
1786 version: 3
1787
1788 For a description of IAM and its features, see the `IAM
1789 documentation <https://cloud.google.com/iam/docs/>`__.
1790
1791 """
1792
1793 http_options = (
1794 _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy._get_http_options()
1795 )
1796
1797 request, metadata = self._interceptor.pre_get_iam_policy(request, metadata)
1798 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy._get_transcoded_request(
1799 http_options, request
1800 )
1801
1802 # Jsonify the query params
1803 query_params = _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy._get_query_params_json(
1804 transcoded_request
1805 )
1806
1807 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1808 logging.DEBUG
1809 ): # pragma: NO COVER
1810 request_url = "{host}{uri}".format(
1811 host=self._host, uri=transcoded_request["uri"]
1812 )
1813 method = transcoded_request["method"]
1814 try:
1815 request_payload = json_format.MessageToJson(request)
1816 except:
1817 request_payload = None
1818 http_request = {
1819 "payload": request_payload,
1820 "requestMethod": method,
1821 "requestUrl": request_url,
1822 "headers": dict(metadata),
1823 }
1824 _LOGGER.debug(
1825 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetIamPolicy",
1826 extra={
1827 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1828 "rpcName": "GetIamPolicy",
1829 "httpRequest": http_request,
1830 "metadata": http_request["headers"],
1831 },
1832 )
1833
1834 # Send the request
1835 response = SecretManagerServiceRestTransport._GetIamPolicy._get_response(
1836 self._host,
1837 metadata,
1838 query_params,
1839 self._session,
1840 timeout,
1841 transcoded_request,
1842 )
1843
1844 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1845 # subclass.
1846 if response.status_code >= 400:
1847 raise core_exceptions.from_http_response(response)
1848
1849 # Return the response
1850 resp = policy_pb2.Policy()
1851 pb_resp = resp
1852
1853 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1854
1855 resp = self._interceptor.post_get_iam_policy(resp)
1856 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1857 logging.DEBUG
1858 ): # pragma: NO COVER
1859 try:
1860 response_payload = json_format.MessageToJson(resp)
1861 except:
1862 response_payload = None
1863 http_response = {
1864 "payload": response_payload,
1865 "headers": dict(response.headers),
1866 "status": response.status_code,
1867 }
1868 _LOGGER.debug(
1869 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.get_iam_policy",
1870 extra={
1871 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1872 "rpcName": "GetIamPolicy",
1873 "metadata": http_response["headers"],
1874 "httpResponse": http_response,
1875 },
1876 )
1877 return resp
1878
1879 class _GetSecret(
1880 _BaseSecretManagerServiceRestTransport._BaseGetSecret,
1881 SecretManagerServiceRestStub,
1882 ):
1883 def __hash__(self):
1884 return hash("SecretManagerServiceRestTransport.GetSecret")
1885
1886 @staticmethod
1887 def _get_response(
1888 host,
1889 metadata,
1890 query_params,
1891 session,
1892 timeout,
1893 transcoded_request,
1894 body=None,
1895 ):
1896 uri = transcoded_request["uri"]
1897 method = transcoded_request["method"]
1898 headers = dict(metadata)
1899 headers["Content-Type"] = "application/json"
1900 response = getattr(session, method)(
1901 "{host}{uri}".format(host=host, uri=uri),
1902 timeout=timeout,
1903 headers=headers,
1904 params=rest_helpers.flatten_query_params(query_params, strict=True),
1905 )
1906 return response
1907
1908 def __call__(
1909 self,
1910 request: service.GetSecretRequest,
1911 *,
1912 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1913 timeout: Optional[float] = None,
1914 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1915 ) -> resources.Secret:
1916 r"""Call the get secret method over HTTP.
1917
1918 Args:
1919 request (~.service.GetSecretRequest):
1920 The request object. Request message for
1921 [SecretManagerService.GetSecret][google.cloud.secrets.v1beta1.SecretManagerService.GetSecret].
1922 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1923 should be retried.
1924 timeout (float): The timeout for this request.
1925 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1926 sent along with the request as metadata. Normally, each value must be of type `str`,
1927 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1928 be of type `bytes`.
1929
1930 Returns:
1931 ~.resources.Secret:
1932 A [Secret][google.cloud.secrets.v1beta1.Secret] is a
1933 logical secret whose value and versions can be accessed.
1934
1935 A [Secret][google.cloud.secrets.v1beta1.Secret] is made
1936 up of zero or more
1937 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]
1938 that represent the secret data.
1939
1940 """
1941
1942 http_options = (
1943 _BaseSecretManagerServiceRestTransport._BaseGetSecret._get_http_options()
1944 )
1945
1946 request, metadata = self._interceptor.pre_get_secret(request, metadata)
1947 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetSecret._get_transcoded_request(
1948 http_options, request
1949 )
1950
1951 # Jsonify the query params
1952 query_params = _BaseSecretManagerServiceRestTransport._BaseGetSecret._get_query_params_json(
1953 transcoded_request
1954 )
1955
1956 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1957 logging.DEBUG
1958 ): # pragma: NO COVER
1959 request_url = "{host}{uri}".format(
1960 host=self._host, uri=transcoded_request["uri"]
1961 )
1962 method = transcoded_request["method"]
1963 try:
1964 request_payload = type(request).to_json(request)
1965 except:
1966 request_payload = None
1967 http_request = {
1968 "payload": request_payload,
1969 "requestMethod": method,
1970 "requestUrl": request_url,
1971 "headers": dict(metadata),
1972 }
1973 _LOGGER.debug(
1974 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetSecret",
1975 extra={
1976 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1977 "rpcName": "GetSecret",
1978 "httpRequest": http_request,
1979 "metadata": http_request["headers"],
1980 },
1981 )
1982
1983 # Send the request
1984 response = SecretManagerServiceRestTransport._GetSecret._get_response(
1985 self._host,
1986 metadata,
1987 query_params,
1988 self._session,
1989 timeout,
1990 transcoded_request,
1991 )
1992
1993 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1994 # subclass.
1995 if response.status_code >= 400:
1996 raise core_exceptions.from_http_response(response)
1997
1998 # Return the response
1999 resp = resources.Secret()
2000 pb_resp = resources.Secret.pb(resp)
2001
2002 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2003
2004 resp = self._interceptor.post_get_secret(resp)
2005 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2006 logging.DEBUG
2007 ): # pragma: NO COVER
2008 try:
2009 response_payload = resources.Secret.to_json(response)
2010 except:
2011 response_payload = None
2012 http_response = {
2013 "payload": response_payload,
2014 "headers": dict(response.headers),
2015 "status": response.status_code,
2016 }
2017 _LOGGER.debug(
2018 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.get_secret",
2019 extra={
2020 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2021 "rpcName": "GetSecret",
2022 "metadata": http_response["headers"],
2023 "httpResponse": http_response,
2024 },
2025 )
2026 return resp
2027
2028 class _GetSecretVersion(
2029 _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion,
2030 SecretManagerServiceRestStub,
2031 ):
2032 def __hash__(self):
2033 return hash("SecretManagerServiceRestTransport.GetSecretVersion")
2034
2035 @staticmethod
2036 def _get_response(
2037 host,
2038 metadata,
2039 query_params,
2040 session,
2041 timeout,
2042 transcoded_request,
2043 body=None,
2044 ):
2045 uri = transcoded_request["uri"]
2046 method = transcoded_request["method"]
2047 headers = dict(metadata)
2048 headers["Content-Type"] = "application/json"
2049 response = getattr(session, method)(
2050 "{host}{uri}".format(host=host, uri=uri),
2051 timeout=timeout,
2052 headers=headers,
2053 params=rest_helpers.flatten_query_params(query_params, strict=True),
2054 )
2055 return response
2056
2057 def __call__(
2058 self,
2059 request: service.GetSecretVersionRequest,
2060 *,
2061 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2062 timeout: Optional[float] = None,
2063 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2064 ) -> resources.SecretVersion:
2065 r"""Call the get secret version method over HTTP.
2066
2067 Args:
2068 request (~.service.GetSecretVersionRequest):
2069 The request object. Request message for
2070 [SecretManagerService.GetSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.GetSecretVersion].
2071 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2072 should be retried.
2073 timeout (float): The timeout for this request.
2074 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2075 sent along with the request as metadata. Normally, each value must be of type `str`,
2076 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2077 be of type `bytes`.
2078
2079 Returns:
2080 ~.resources.SecretVersion:
2081 A secret version resource in the
2082 Secret Manager API.
2083
2084 """
2085
2086 http_options = (
2087 _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion._get_http_options()
2088 )
2089
2090 request, metadata = self._interceptor.pre_get_secret_version(
2091 request, metadata
2092 )
2093 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion._get_transcoded_request(
2094 http_options, request
2095 )
2096
2097 # Jsonify the query params
2098 query_params = _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion._get_query_params_json(
2099 transcoded_request
2100 )
2101
2102 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2103 logging.DEBUG
2104 ): # pragma: NO COVER
2105 request_url = "{host}{uri}".format(
2106 host=self._host, uri=transcoded_request["uri"]
2107 )
2108 method = transcoded_request["method"]
2109 try:
2110 request_payload = type(request).to_json(request)
2111 except:
2112 request_payload = None
2113 http_request = {
2114 "payload": request_payload,
2115 "requestMethod": method,
2116 "requestUrl": request_url,
2117 "headers": dict(metadata),
2118 }
2119 _LOGGER.debug(
2120 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetSecretVersion",
2121 extra={
2122 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2123 "rpcName": "GetSecretVersion",
2124 "httpRequest": http_request,
2125 "metadata": http_request["headers"],
2126 },
2127 )
2128
2129 # Send the request
2130 response = (
2131 SecretManagerServiceRestTransport._GetSecretVersion._get_response(
2132 self._host,
2133 metadata,
2134 query_params,
2135 self._session,
2136 timeout,
2137 transcoded_request,
2138 )
2139 )
2140
2141 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2142 # subclass.
2143 if response.status_code >= 400:
2144 raise core_exceptions.from_http_response(response)
2145
2146 # Return the response
2147 resp = resources.SecretVersion()
2148 pb_resp = resources.SecretVersion.pb(resp)
2149
2150 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2151
2152 resp = self._interceptor.post_get_secret_version(resp)
2153 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2154 logging.DEBUG
2155 ): # pragma: NO COVER
2156 try:
2157 response_payload = resources.SecretVersion.to_json(response)
2158 except:
2159 response_payload = None
2160 http_response = {
2161 "payload": response_payload,
2162 "headers": dict(response.headers),
2163 "status": response.status_code,
2164 }
2165 _LOGGER.debug(
2166 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.get_secret_version",
2167 extra={
2168 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2169 "rpcName": "GetSecretVersion",
2170 "metadata": http_response["headers"],
2171 "httpResponse": http_response,
2172 },
2173 )
2174 return resp
2175
2176 class _ListSecrets(
2177 _BaseSecretManagerServiceRestTransport._BaseListSecrets,
2178 SecretManagerServiceRestStub,
2179 ):
2180 def __hash__(self):
2181 return hash("SecretManagerServiceRestTransport.ListSecrets")
2182
2183 @staticmethod
2184 def _get_response(
2185 host,
2186 metadata,
2187 query_params,
2188 session,
2189 timeout,
2190 transcoded_request,
2191 body=None,
2192 ):
2193 uri = transcoded_request["uri"]
2194 method = transcoded_request["method"]
2195 headers = dict(metadata)
2196 headers["Content-Type"] = "application/json"
2197 response = getattr(session, method)(
2198 "{host}{uri}".format(host=host, uri=uri),
2199 timeout=timeout,
2200 headers=headers,
2201 params=rest_helpers.flatten_query_params(query_params, strict=True),
2202 )
2203 return response
2204
2205 def __call__(
2206 self,
2207 request: service.ListSecretsRequest,
2208 *,
2209 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2210 timeout: Optional[float] = None,
2211 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2212 ) -> service.ListSecretsResponse:
2213 r"""Call the list secrets method over HTTP.
2214
2215 Args:
2216 request (~.service.ListSecretsRequest):
2217 The request object. Request message for
2218 [SecretManagerService.ListSecrets][google.cloud.secrets.v1beta1.SecretManagerService.ListSecrets].
2219 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2220 should be retried.
2221 timeout (float): The timeout for this request.
2222 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2223 sent along with the request as metadata. Normally, each value must be of type `str`,
2224 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2225 be of type `bytes`.
2226
2227 Returns:
2228 ~.service.ListSecretsResponse:
2229 Response message for
2230 [SecretManagerService.ListSecrets][google.cloud.secrets.v1beta1.SecretManagerService.ListSecrets].
2231
2232 """
2233
2234 http_options = (
2235 _BaseSecretManagerServiceRestTransport._BaseListSecrets._get_http_options()
2236 )
2237
2238 request, metadata = self._interceptor.pre_list_secrets(request, metadata)
2239 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseListSecrets._get_transcoded_request(
2240 http_options, request
2241 )
2242
2243 # Jsonify the query params
2244 query_params = _BaseSecretManagerServiceRestTransport._BaseListSecrets._get_query_params_json(
2245 transcoded_request
2246 )
2247
2248 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2249 logging.DEBUG
2250 ): # pragma: NO COVER
2251 request_url = "{host}{uri}".format(
2252 host=self._host, uri=transcoded_request["uri"]
2253 )
2254 method = transcoded_request["method"]
2255 try:
2256 request_payload = type(request).to_json(request)
2257 except:
2258 request_payload = None
2259 http_request = {
2260 "payload": request_payload,
2261 "requestMethod": method,
2262 "requestUrl": request_url,
2263 "headers": dict(metadata),
2264 }
2265 _LOGGER.debug(
2266 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.ListSecrets",
2267 extra={
2268 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2269 "rpcName": "ListSecrets",
2270 "httpRequest": http_request,
2271 "metadata": http_request["headers"],
2272 },
2273 )
2274
2275 # Send the request
2276 response = SecretManagerServiceRestTransport._ListSecrets._get_response(
2277 self._host,
2278 metadata,
2279 query_params,
2280 self._session,
2281 timeout,
2282 transcoded_request,
2283 )
2284
2285 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2286 # subclass.
2287 if response.status_code >= 400:
2288 raise core_exceptions.from_http_response(response)
2289
2290 # Return the response
2291 resp = service.ListSecretsResponse()
2292 pb_resp = service.ListSecretsResponse.pb(resp)
2293
2294 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2295
2296 resp = self._interceptor.post_list_secrets(resp)
2297 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2298 logging.DEBUG
2299 ): # pragma: NO COVER
2300 try:
2301 response_payload = service.ListSecretsResponse.to_json(response)
2302 except:
2303 response_payload = None
2304 http_response = {
2305 "payload": response_payload,
2306 "headers": dict(response.headers),
2307 "status": response.status_code,
2308 }
2309 _LOGGER.debug(
2310 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.list_secrets",
2311 extra={
2312 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2313 "rpcName": "ListSecrets",
2314 "metadata": http_response["headers"],
2315 "httpResponse": http_response,
2316 },
2317 )
2318 return resp
2319
2320 class _ListSecretVersions(
2321 _BaseSecretManagerServiceRestTransport._BaseListSecretVersions,
2322 SecretManagerServiceRestStub,
2323 ):
2324 def __hash__(self):
2325 return hash("SecretManagerServiceRestTransport.ListSecretVersions")
2326
2327 @staticmethod
2328 def _get_response(
2329 host,
2330 metadata,
2331 query_params,
2332 session,
2333 timeout,
2334 transcoded_request,
2335 body=None,
2336 ):
2337 uri = transcoded_request["uri"]
2338 method = transcoded_request["method"]
2339 headers = dict(metadata)
2340 headers["Content-Type"] = "application/json"
2341 response = getattr(session, method)(
2342 "{host}{uri}".format(host=host, uri=uri),
2343 timeout=timeout,
2344 headers=headers,
2345 params=rest_helpers.flatten_query_params(query_params, strict=True),
2346 )
2347 return response
2348
2349 def __call__(
2350 self,
2351 request: service.ListSecretVersionsRequest,
2352 *,
2353 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2354 timeout: Optional[float] = None,
2355 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2356 ) -> service.ListSecretVersionsResponse:
2357 r"""Call the list secret versions method over HTTP.
2358
2359 Args:
2360 request (~.service.ListSecretVersionsRequest):
2361 The request object. Request message for
2362 [SecretManagerService.ListSecretVersions][google.cloud.secrets.v1beta1.SecretManagerService.ListSecretVersions].
2363 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2364 should be retried.
2365 timeout (float): The timeout for this request.
2366 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2367 sent along with the request as metadata. Normally, each value must be of type `str`,
2368 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2369 be of type `bytes`.
2370
2371 Returns:
2372 ~.service.ListSecretVersionsResponse:
2373 Response message for
2374 [SecretManagerService.ListSecretVersions][google.cloud.secrets.v1beta1.SecretManagerService.ListSecretVersions].
2375
2376 """
2377
2378 http_options = (
2379 _BaseSecretManagerServiceRestTransport._BaseListSecretVersions._get_http_options()
2380 )
2381
2382 request, metadata = self._interceptor.pre_list_secret_versions(
2383 request, metadata
2384 )
2385 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseListSecretVersions._get_transcoded_request(
2386 http_options, request
2387 )
2388
2389 # Jsonify the query params
2390 query_params = _BaseSecretManagerServiceRestTransport._BaseListSecretVersions._get_query_params_json(
2391 transcoded_request
2392 )
2393
2394 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2395 logging.DEBUG
2396 ): # pragma: NO COVER
2397 request_url = "{host}{uri}".format(
2398 host=self._host, uri=transcoded_request["uri"]
2399 )
2400 method = transcoded_request["method"]
2401 try:
2402 request_payload = type(request).to_json(request)
2403 except:
2404 request_payload = None
2405 http_request = {
2406 "payload": request_payload,
2407 "requestMethod": method,
2408 "requestUrl": request_url,
2409 "headers": dict(metadata),
2410 }
2411 _LOGGER.debug(
2412 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.ListSecretVersions",
2413 extra={
2414 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2415 "rpcName": "ListSecretVersions",
2416 "httpRequest": http_request,
2417 "metadata": http_request["headers"],
2418 },
2419 )
2420
2421 # Send the request
2422 response = (
2423 SecretManagerServiceRestTransport._ListSecretVersions._get_response(
2424 self._host,
2425 metadata,
2426 query_params,
2427 self._session,
2428 timeout,
2429 transcoded_request,
2430 )
2431 )
2432
2433 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2434 # subclass.
2435 if response.status_code >= 400:
2436 raise core_exceptions.from_http_response(response)
2437
2438 # Return the response
2439 resp = service.ListSecretVersionsResponse()
2440 pb_resp = service.ListSecretVersionsResponse.pb(resp)
2441
2442 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2443
2444 resp = self._interceptor.post_list_secret_versions(resp)
2445 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2446 logging.DEBUG
2447 ): # pragma: NO COVER
2448 try:
2449 response_payload = service.ListSecretVersionsResponse.to_json(
2450 response
2451 )
2452 except:
2453 response_payload = None
2454 http_response = {
2455 "payload": response_payload,
2456 "headers": dict(response.headers),
2457 "status": response.status_code,
2458 }
2459 _LOGGER.debug(
2460 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.list_secret_versions",
2461 extra={
2462 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2463 "rpcName": "ListSecretVersions",
2464 "metadata": http_response["headers"],
2465 "httpResponse": http_response,
2466 },
2467 )
2468 return resp
2469
2470 class _SetIamPolicy(
2471 _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy,
2472 SecretManagerServiceRestStub,
2473 ):
2474 def __hash__(self):
2475 return hash("SecretManagerServiceRestTransport.SetIamPolicy")
2476
2477 @staticmethod
2478 def _get_response(
2479 host,
2480 metadata,
2481 query_params,
2482 session,
2483 timeout,
2484 transcoded_request,
2485 body=None,
2486 ):
2487 uri = transcoded_request["uri"]
2488 method = transcoded_request["method"]
2489 headers = dict(metadata)
2490 headers["Content-Type"] = "application/json"
2491 response = getattr(session, method)(
2492 "{host}{uri}".format(host=host, uri=uri),
2493 timeout=timeout,
2494 headers=headers,
2495 params=rest_helpers.flatten_query_params(query_params, strict=True),
2496 data=body,
2497 )
2498 return response
2499
2500 def __call__(
2501 self,
2502 request: iam_policy_pb2.SetIamPolicyRequest,
2503 *,
2504 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2505 timeout: Optional[float] = None,
2506 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2507 ) -> policy_pb2.Policy:
2508 r"""Call the set iam policy method over HTTP.
2509
2510 Args:
2511 request (~.iam_policy_pb2.SetIamPolicyRequest):
2512 The request object. Request message for ``SetIamPolicy`` method.
2513 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2514 should be retried.
2515 timeout (float): The timeout for this request.
2516 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2517 sent along with the request as metadata. Normally, each value must be of type `str`,
2518 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2519 be of type `bytes`.
2520
2521 Returns:
2522 ~.policy_pb2.Policy:
2523 An Identity and Access Management (IAM) policy, which
2524 specifies access controls for Google Cloud resources.
2525
2526 A ``Policy`` is a collection of ``bindings``. A
2527 ``binding`` binds one or more ``members``, or
2528 principals, to a single ``role``. Principals can be user
2529 accounts, service accounts, Google groups, and domains
2530 (such as G Suite). A ``role`` is a named list of
2531 permissions; each ``role`` can be an IAM predefined role
2532 or a user-created custom role.
2533
2534 For some types of Google Cloud resources, a ``binding``
2535 can also specify a ``condition``, which is a logical
2536 expression that allows access to a resource only if the
2537 expression evaluates to ``true``. A condition can add
2538 constraints based on attributes of the request, the
2539 resource, or both. To learn which resources support
2540 conditions in their IAM policies, see the `IAM
2541 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__.
2542
2543 **JSON example:**
2544
2545 ::
2546
2547 {
2548 "bindings": [
2549 {
2550 "role": "roles/resourcemanager.organizationAdmin",
2551 "members": [
2552 "user:mike@example.com",
2553 "group:admins@example.com",
2554 "domain:google.com",
2555 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
2556 ]
2557 },
2558 {
2559 "role": "roles/resourcemanager.organizationViewer",
2560 "members": [
2561 "user:eve@example.com"
2562 ],
2563 "condition": {
2564 "title": "expirable access",
2565 "description": "Does not grant access after Sep 2020",
2566 "expression": "request.time <
2567 timestamp('2020-10-01T00:00:00.000Z')",
2568 }
2569 }
2570 ],
2571 "etag": "BwWWja0YfJA=",
2572 "version": 3
2573 }
2574
2575 **YAML example:**
2576
2577 ::
2578
2579 bindings:
2580 - members:
2581 - user:mike@example.com
2582 - group:admins@example.com
2583 - domain:google.com
2584 - serviceAccount:my-project-id@appspot.gserviceaccount.com
2585 role: roles/resourcemanager.organizationAdmin
2586 - members:
2587 - user:eve@example.com
2588 role: roles/resourcemanager.organizationViewer
2589 condition:
2590 title: expirable access
2591 description: Does not grant access after Sep 2020
2592 expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
2593 etag: BwWWja0YfJA=
2594 version: 3
2595
2596 For a description of IAM and its features, see the `IAM
2597 documentation <https://cloud.google.com/iam/docs/>`__.
2598
2599 """
2600
2601 http_options = (
2602 _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_http_options()
2603 )
2604
2605 request, metadata = self._interceptor.pre_set_iam_policy(request, metadata)
2606 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_transcoded_request(
2607 http_options, request
2608 )
2609
2610 body = _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_request_body_json(
2611 transcoded_request
2612 )
2613
2614 # Jsonify the query params
2615 query_params = _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_query_params_json(
2616 transcoded_request
2617 )
2618
2619 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2620 logging.DEBUG
2621 ): # pragma: NO COVER
2622 request_url = "{host}{uri}".format(
2623 host=self._host, uri=transcoded_request["uri"]
2624 )
2625 method = transcoded_request["method"]
2626 try:
2627 request_payload = json_format.MessageToJson(request)
2628 except:
2629 request_payload = None
2630 http_request = {
2631 "payload": request_payload,
2632 "requestMethod": method,
2633 "requestUrl": request_url,
2634 "headers": dict(metadata),
2635 }
2636 _LOGGER.debug(
2637 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.SetIamPolicy",
2638 extra={
2639 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2640 "rpcName": "SetIamPolicy",
2641 "httpRequest": http_request,
2642 "metadata": http_request["headers"],
2643 },
2644 )
2645
2646 # Send the request
2647 response = SecretManagerServiceRestTransport._SetIamPolicy._get_response(
2648 self._host,
2649 metadata,
2650 query_params,
2651 self._session,
2652 timeout,
2653 transcoded_request,
2654 body,
2655 )
2656
2657 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2658 # subclass.
2659 if response.status_code >= 400:
2660 raise core_exceptions.from_http_response(response)
2661
2662 # Return the response
2663 resp = policy_pb2.Policy()
2664 pb_resp = resp
2665
2666 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2667
2668 resp = self._interceptor.post_set_iam_policy(resp)
2669 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2670 logging.DEBUG
2671 ): # pragma: NO COVER
2672 try:
2673 response_payload = json_format.MessageToJson(resp)
2674 except:
2675 response_payload = None
2676 http_response = {
2677 "payload": response_payload,
2678 "headers": dict(response.headers),
2679 "status": response.status_code,
2680 }
2681 _LOGGER.debug(
2682 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.set_iam_policy",
2683 extra={
2684 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2685 "rpcName": "SetIamPolicy",
2686 "metadata": http_response["headers"],
2687 "httpResponse": http_response,
2688 },
2689 )
2690 return resp
2691
2692 class _TestIamPermissions(
2693 _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions,
2694 SecretManagerServiceRestStub,
2695 ):
2696 def __hash__(self):
2697 return hash("SecretManagerServiceRestTransport.TestIamPermissions")
2698
2699 @staticmethod
2700 def _get_response(
2701 host,
2702 metadata,
2703 query_params,
2704 session,
2705 timeout,
2706 transcoded_request,
2707 body=None,
2708 ):
2709 uri = transcoded_request["uri"]
2710 method = transcoded_request["method"]
2711 headers = dict(metadata)
2712 headers["Content-Type"] = "application/json"
2713 response = getattr(session, method)(
2714 "{host}{uri}".format(host=host, uri=uri),
2715 timeout=timeout,
2716 headers=headers,
2717 params=rest_helpers.flatten_query_params(query_params, strict=True),
2718 data=body,
2719 )
2720 return response
2721
2722 def __call__(
2723 self,
2724 request: iam_policy_pb2.TestIamPermissionsRequest,
2725 *,
2726 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2727 timeout: Optional[float] = None,
2728 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2729 ) -> iam_policy_pb2.TestIamPermissionsResponse:
2730 r"""Call the test iam permissions method over HTTP.
2731
2732 Args:
2733 request (~.iam_policy_pb2.TestIamPermissionsRequest):
2734 The request object. Request message for ``TestIamPermissions`` method.
2735 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2736 should be retried.
2737 timeout (float): The timeout for this request.
2738 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2739 sent along with the request as metadata. Normally, each value must be of type `str`,
2740 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2741 be of type `bytes`.
2742
2743 Returns:
2744 ~.iam_policy_pb2.TestIamPermissionsResponse:
2745 Response message for ``TestIamPermissions`` method.
2746 """
2747
2748 http_options = (
2749 _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_http_options()
2750 )
2751
2752 request, metadata = self._interceptor.pre_test_iam_permissions(
2753 request, metadata
2754 )
2755 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_transcoded_request(
2756 http_options, request
2757 )
2758
2759 body = _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_request_body_json(
2760 transcoded_request
2761 )
2762
2763 # Jsonify the query params
2764 query_params = _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_query_params_json(
2765 transcoded_request
2766 )
2767
2768 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2769 logging.DEBUG
2770 ): # pragma: NO COVER
2771 request_url = "{host}{uri}".format(
2772 host=self._host, uri=transcoded_request["uri"]
2773 )
2774 method = transcoded_request["method"]
2775 try:
2776 request_payload = json_format.MessageToJson(request)
2777 except:
2778 request_payload = None
2779 http_request = {
2780 "payload": request_payload,
2781 "requestMethod": method,
2782 "requestUrl": request_url,
2783 "headers": dict(metadata),
2784 }
2785 _LOGGER.debug(
2786 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.TestIamPermissions",
2787 extra={
2788 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2789 "rpcName": "TestIamPermissions",
2790 "httpRequest": http_request,
2791 "metadata": http_request["headers"],
2792 },
2793 )
2794
2795 # Send the request
2796 response = (
2797 SecretManagerServiceRestTransport._TestIamPermissions._get_response(
2798 self._host,
2799 metadata,
2800 query_params,
2801 self._session,
2802 timeout,
2803 transcoded_request,
2804 body,
2805 )
2806 )
2807
2808 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2809 # subclass.
2810 if response.status_code >= 400:
2811 raise core_exceptions.from_http_response(response)
2812
2813 # Return the response
2814 resp = iam_policy_pb2.TestIamPermissionsResponse()
2815 pb_resp = resp
2816
2817 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2818
2819 resp = self._interceptor.post_test_iam_permissions(resp)
2820 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2821 logging.DEBUG
2822 ): # pragma: NO COVER
2823 try:
2824 response_payload = json_format.MessageToJson(resp)
2825 except:
2826 response_payload = None
2827 http_response = {
2828 "payload": response_payload,
2829 "headers": dict(response.headers),
2830 "status": response.status_code,
2831 }
2832 _LOGGER.debug(
2833 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.test_iam_permissions",
2834 extra={
2835 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2836 "rpcName": "TestIamPermissions",
2837 "metadata": http_response["headers"],
2838 "httpResponse": http_response,
2839 },
2840 )
2841 return resp
2842
2843 class _UpdateSecret(
2844 _BaseSecretManagerServiceRestTransport._BaseUpdateSecret,
2845 SecretManagerServiceRestStub,
2846 ):
2847 def __hash__(self):
2848 return hash("SecretManagerServiceRestTransport.UpdateSecret")
2849
2850 @staticmethod
2851 def _get_response(
2852 host,
2853 metadata,
2854 query_params,
2855 session,
2856 timeout,
2857 transcoded_request,
2858 body=None,
2859 ):
2860 uri = transcoded_request["uri"]
2861 method = transcoded_request["method"]
2862 headers = dict(metadata)
2863 headers["Content-Type"] = "application/json"
2864 response = getattr(session, method)(
2865 "{host}{uri}".format(host=host, uri=uri),
2866 timeout=timeout,
2867 headers=headers,
2868 params=rest_helpers.flatten_query_params(query_params, strict=True),
2869 data=body,
2870 )
2871 return response
2872
2873 def __call__(
2874 self,
2875 request: service.UpdateSecretRequest,
2876 *,
2877 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2878 timeout: Optional[float] = None,
2879 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2880 ) -> resources.Secret:
2881 r"""Call the update secret method over HTTP.
2882
2883 Args:
2884 request (~.service.UpdateSecretRequest):
2885 The request object. Request message for
2886 [SecretManagerService.UpdateSecret][google.cloud.secrets.v1beta1.SecretManagerService.UpdateSecret].
2887 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2888 should be retried.
2889 timeout (float): The timeout for this request.
2890 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2891 sent along with the request as metadata. Normally, each value must be of type `str`,
2892 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2893 be of type `bytes`.
2894
2895 Returns:
2896 ~.resources.Secret:
2897 A [Secret][google.cloud.secrets.v1beta1.Secret] is a
2898 logical secret whose value and versions can be accessed.
2899
2900 A [Secret][google.cloud.secrets.v1beta1.Secret] is made
2901 up of zero or more
2902 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]
2903 that represent the secret data.
2904
2905 """
2906
2907 http_options = (
2908 _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_http_options()
2909 )
2910
2911 request, metadata = self._interceptor.pre_update_secret(request, metadata)
2912 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_transcoded_request(
2913 http_options, request
2914 )
2915
2916 body = _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_request_body_json(
2917 transcoded_request
2918 )
2919
2920 # Jsonify the query params
2921 query_params = _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_query_params_json(
2922 transcoded_request
2923 )
2924
2925 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2926 logging.DEBUG
2927 ): # pragma: NO COVER
2928 request_url = "{host}{uri}".format(
2929 host=self._host, uri=transcoded_request["uri"]
2930 )
2931 method = transcoded_request["method"]
2932 try:
2933 request_payload = type(request).to_json(request)
2934 except:
2935 request_payload = None
2936 http_request = {
2937 "payload": request_payload,
2938 "requestMethod": method,
2939 "requestUrl": request_url,
2940 "headers": dict(metadata),
2941 }
2942 _LOGGER.debug(
2943 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.UpdateSecret",
2944 extra={
2945 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2946 "rpcName": "UpdateSecret",
2947 "httpRequest": http_request,
2948 "metadata": http_request["headers"],
2949 },
2950 )
2951
2952 # Send the request
2953 response = SecretManagerServiceRestTransport._UpdateSecret._get_response(
2954 self._host,
2955 metadata,
2956 query_params,
2957 self._session,
2958 timeout,
2959 transcoded_request,
2960 body,
2961 )
2962
2963 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2964 # subclass.
2965 if response.status_code >= 400:
2966 raise core_exceptions.from_http_response(response)
2967
2968 # Return the response
2969 resp = resources.Secret()
2970 pb_resp = resources.Secret.pb(resp)
2971
2972 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2973
2974 resp = self._interceptor.post_update_secret(resp)
2975 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2976 logging.DEBUG
2977 ): # pragma: NO COVER
2978 try:
2979 response_payload = resources.Secret.to_json(response)
2980 except:
2981 response_payload = None
2982 http_response = {
2983 "payload": response_payload,
2984 "headers": dict(response.headers),
2985 "status": response.status_code,
2986 }
2987 _LOGGER.debug(
2988 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.update_secret",
2989 extra={
2990 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2991 "rpcName": "UpdateSecret",
2992 "metadata": http_response["headers"],
2993 "httpResponse": http_response,
2994 },
2995 )
2996 return resp
2997
2998 @property
2999 def access_secret_version(
3000 self,
3001 ) -> Callable[
3002 [service.AccessSecretVersionRequest], service.AccessSecretVersionResponse
3003 ]:
3004 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3005 # In C++ this would require a dynamic_cast
3006 return self._AccessSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3007
3008 @property
3009 def add_secret_version(
3010 self,
3011 ) -> Callable[[service.AddSecretVersionRequest], resources.SecretVersion]:
3012 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3013 # In C++ this would require a dynamic_cast
3014 return self._AddSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3015
3016 @property
3017 def create_secret(
3018 self,
3019 ) -> Callable[[service.CreateSecretRequest], resources.Secret]:
3020 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3021 # In C++ this would require a dynamic_cast
3022 return self._CreateSecret(self._session, self._host, self._interceptor) # type: ignore
3023
3024 @property
3025 def delete_secret(self) -> Callable[[service.DeleteSecretRequest], empty_pb2.Empty]:
3026 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3027 # In C++ this would require a dynamic_cast
3028 return self._DeleteSecret(self._session, self._host, self._interceptor) # type: ignore
3029
3030 @property
3031 def destroy_secret_version(
3032 self,
3033 ) -> Callable[[service.DestroySecretVersionRequest], resources.SecretVersion]:
3034 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3035 # In C++ this would require a dynamic_cast
3036 return self._DestroySecretVersion(self._session, self._host, self._interceptor) # type: ignore
3037
3038 @property
3039 def disable_secret_version(
3040 self,
3041 ) -> Callable[[service.DisableSecretVersionRequest], resources.SecretVersion]:
3042 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3043 # In C++ this would require a dynamic_cast
3044 return self._DisableSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3045
3046 @property
3047 def enable_secret_version(
3048 self,
3049 ) -> Callable[[service.EnableSecretVersionRequest], resources.SecretVersion]:
3050 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3051 # In C++ this would require a dynamic_cast
3052 return self._EnableSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3053
3054 @property
3055 def get_iam_policy(
3056 self,
3057 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]:
3058 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3059 # In C++ this would require a dynamic_cast
3060 return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore
3061
3062 @property
3063 def get_secret(self) -> Callable[[service.GetSecretRequest], resources.Secret]:
3064 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3065 # In C++ this would require a dynamic_cast
3066 return self._GetSecret(self._session, self._host, self._interceptor) # type: ignore
3067
3068 @property
3069 def get_secret_version(
3070 self,
3071 ) -> Callable[[service.GetSecretVersionRequest], resources.SecretVersion]:
3072 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3073 # In C++ this would require a dynamic_cast
3074 return self._GetSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3075
3076 @property
3077 def list_secrets(
3078 self,
3079 ) -> Callable[[service.ListSecretsRequest], service.ListSecretsResponse]:
3080 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3081 # In C++ this would require a dynamic_cast
3082 return self._ListSecrets(self._session, self._host, self._interceptor) # type: ignore
3083
3084 @property
3085 def list_secret_versions(
3086 self,
3087 ) -> Callable[
3088 [service.ListSecretVersionsRequest], service.ListSecretVersionsResponse
3089 ]:
3090 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3091 # In C++ this would require a dynamic_cast
3092 return self._ListSecretVersions(self._session, self._host, self._interceptor) # type: ignore
3093
3094 @property
3095 def set_iam_policy(
3096 self,
3097 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]:
3098 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3099 # In C++ this would require a dynamic_cast
3100 return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore
3101
3102 @property
3103 def test_iam_permissions(
3104 self,
3105 ) -> Callable[
3106 [iam_policy_pb2.TestIamPermissionsRequest],
3107 iam_policy_pb2.TestIamPermissionsResponse,
3108 ]:
3109 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3110 # In C++ this would require a dynamic_cast
3111 return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore
3112
3113 @property
3114 def update_secret(
3115 self,
3116 ) -> Callable[[service.UpdateSecretRequest], resources.Secret]:
3117 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3118 # In C++ this would require a dynamic_cast
3119 return self._UpdateSecret(self._session, self._host, self._interceptor) # type: ignore
3120
3121 @property
3122 def kind(self) -> str:
3123 return "rest"
3124
3125 def close(self):
3126 self._session.close()
3127
3128
3129__all__ = ("SecretManagerServiceRestTransport",)