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