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]): Deprecated. 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. This argument will be
980 removed in the next major version of this library.
981 scopes (Optional(Sequence[str])): A list of scopes. This argument is
982 ignored if ``channel`` is provided.
983 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
984 certificate to configure mutual TLS HTTP channel. It is ignored
985 if ``channel`` is provided.
986 quota_project_id (Optional[str]): An optional project to use for billing
987 and quota.
988 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
989 The client info used to send a user-agent string along with
990 API requests. If ``None``, then default info will be used.
991 Generally, you only need to set this if you are developing
992 your own client library.
993 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
994 be used for service account credentials.
995 url_scheme: the protocol scheme for the API endpoint. Normally
996 "https", but for testing or local servers,
997 "http" can be specified.
998 """
999 # Run the base constructor
1000 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
1001 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
1002 # credentials object
1003 super().__init__(
1004 host=host,
1005 credentials=credentials,
1006 client_info=client_info,
1007 always_use_jwt_access=always_use_jwt_access,
1008 url_scheme=url_scheme,
1009 api_audience=api_audience,
1010 )
1011 self._session = AuthorizedSession(
1012 self._credentials, default_host=self.DEFAULT_HOST
1013 )
1014 if client_cert_source_for_mtls:
1015 self._session.configure_mtls_channel(client_cert_source_for_mtls)
1016 self._interceptor = interceptor or SecretManagerServiceRestInterceptor()
1017 self._prep_wrapped_messages(client_info)
1018
1019 class _AccessSecretVersion(
1020 _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion,
1021 SecretManagerServiceRestStub,
1022 ):
1023 def __hash__(self):
1024 return hash("SecretManagerServiceRestTransport.AccessSecretVersion")
1025
1026 @staticmethod
1027 def _get_response(
1028 host,
1029 metadata,
1030 query_params,
1031 session,
1032 timeout,
1033 transcoded_request,
1034 body=None,
1035 ):
1036 uri = transcoded_request["uri"]
1037 method = transcoded_request["method"]
1038 headers = dict(metadata)
1039 headers["Content-Type"] = "application/json"
1040 response = getattr(session, method)(
1041 "{host}{uri}".format(host=host, uri=uri),
1042 timeout=timeout,
1043 headers=headers,
1044 params=rest_helpers.flatten_query_params(query_params, strict=True),
1045 )
1046 return response
1047
1048 def __call__(
1049 self,
1050 request: service.AccessSecretVersionRequest,
1051 *,
1052 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1053 timeout: Optional[float] = None,
1054 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1055 ) -> service.AccessSecretVersionResponse:
1056 r"""Call the access secret version method over HTTP.
1057
1058 Args:
1059 request (~.service.AccessSecretVersionRequest):
1060 The request object. Request message for
1061 [SecretManagerService.AccessSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AccessSecretVersion].
1062 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1063 should be retried.
1064 timeout (float): The timeout for this request.
1065 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1066 sent along with the request as metadata. Normally, each value must be of type `str`,
1067 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1068 be of type `bytes`.
1069
1070 Returns:
1071 ~.service.AccessSecretVersionResponse:
1072 Response message for
1073 [SecretManagerService.AccessSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AccessSecretVersion].
1074
1075 """
1076
1077 http_options = (
1078 _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion._get_http_options()
1079 )
1080
1081 request, metadata = self._interceptor.pre_access_secret_version(
1082 request, metadata
1083 )
1084 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion._get_transcoded_request(
1085 http_options, request
1086 )
1087
1088 # Jsonify the query params
1089 query_params = _BaseSecretManagerServiceRestTransport._BaseAccessSecretVersion._get_query_params_json(
1090 transcoded_request
1091 )
1092
1093 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1094 logging.DEBUG
1095 ): # pragma: NO COVER
1096 request_url = "{host}{uri}".format(
1097 host=self._host, uri=transcoded_request["uri"]
1098 )
1099 method = transcoded_request["method"]
1100 try:
1101 request_payload = type(request).to_json(request)
1102 except:
1103 request_payload = None
1104 http_request = {
1105 "payload": request_payload,
1106 "requestMethod": method,
1107 "requestUrl": request_url,
1108 "headers": dict(metadata),
1109 }
1110 _LOGGER.debug(
1111 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.AccessSecretVersion",
1112 extra={
1113 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1114 "rpcName": "AccessSecretVersion",
1115 "httpRequest": http_request,
1116 "metadata": http_request["headers"],
1117 },
1118 )
1119
1120 # Send the request
1121 response = (
1122 SecretManagerServiceRestTransport._AccessSecretVersion._get_response(
1123 self._host,
1124 metadata,
1125 query_params,
1126 self._session,
1127 timeout,
1128 transcoded_request,
1129 )
1130 )
1131
1132 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1133 # subclass.
1134 if response.status_code >= 400:
1135 raise core_exceptions.from_http_response(response)
1136
1137 # Return the response
1138 resp = service.AccessSecretVersionResponse()
1139 pb_resp = service.AccessSecretVersionResponse.pb(resp)
1140
1141 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1142
1143 resp = self._interceptor.post_access_secret_version(resp)
1144 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1145 resp, _ = self._interceptor.post_access_secret_version_with_metadata(
1146 resp, response_metadata
1147 )
1148 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1149 logging.DEBUG
1150 ): # pragma: NO COVER
1151 try:
1152 response_payload = service.AccessSecretVersionResponse.to_json(
1153 response
1154 )
1155 except:
1156 response_payload = None
1157 http_response = {
1158 "payload": response_payload,
1159 "headers": dict(response.headers),
1160 "status": response.status_code,
1161 }
1162 _LOGGER.debug(
1163 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.access_secret_version",
1164 extra={
1165 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1166 "rpcName": "AccessSecretVersion",
1167 "metadata": http_response["headers"],
1168 "httpResponse": http_response,
1169 },
1170 )
1171 return resp
1172
1173 class _AddSecretVersion(
1174 _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion,
1175 SecretManagerServiceRestStub,
1176 ):
1177 def __hash__(self):
1178 return hash("SecretManagerServiceRestTransport.AddSecretVersion")
1179
1180 @staticmethod
1181 def _get_response(
1182 host,
1183 metadata,
1184 query_params,
1185 session,
1186 timeout,
1187 transcoded_request,
1188 body=None,
1189 ):
1190 uri = transcoded_request["uri"]
1191 method = transcoded_request["method"]
1192 headers = dict(metadata)
1193 headers["Content-Type"] = "application/json"
1194 response = getattr(session, method)(
1195 "{host}{uri}".format(host=host, uri=uri),
1196 timeout=timeout,
1197 headers=headers,
1198 params=rest_helpers.flatten_query_params(query_params, strict=True),
1199 data=body,
1200 )
1201 return response
1202
1203 def __call__(
1204 self,
1205 request: service.AddSecretVersionRequest,
1206 *,
1207 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1208 timeout: Optional[float] = None,
1209 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1210 ) -> resources.SecretVersion:
1211 r"""Call the add secret version method over HTTP.
1212
1213 Args:
1214 request (~.service.AddSecretVersionRequest):
1215 The request object. Request message for
1216 [SecretManagerService.AddSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AddSecretVersion].
1217 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1218 should be retried.
1219 timeout (float): The timeout for this request.
1220 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1221 sent along with the request as metadata. Normally, each value must be of type `str`,
1222 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1223 be of type `bytes`.
1224
1225 Returns:
1226 ~.resources.SecretVersion:
1227 A secret version resource in the
1228 Secret Manager API.
1229
1230 """
1231
1232 http_options = (
1233 _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_http_options()
1234 )
1235
1236 request, metadata = self._interceptor.pre_add_secret_version(
1237 request, metadata
1238 )
1239 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_transcoded_request(
1240 http_options, request
1241 )
1242
1243 body = _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_request_body_json(
1244 transcoded_request
1245 )
1246
1247 # Jsonify the query params
1248 query_params = _BaseSecretManagerServiceRestTransport._BaseAddSecretVersion._get_query_params_json(
1249 transcoded_request
1250 )
1251
1252 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1253 logging.DEBUG
1254 ): # pragma: NO COVER
1255 request_url = "{host}{uri}".format(
1256 host=self._host, uri=transcoded_request["uri"]
1257 )
1258 method = transcoded_request["method"]
1259 try:
1260 request_payload = type(request).to_json(request)
1261 except:
1262 request_payload = None
1263 http_request = {
1264 "payload": request_payload,
1265 "requestMethod": method,
1266 "requestUrl": request_url,
1267 "headers": dict(metadata),
1268 }
1269 _LOGGER.debug(
1270 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.AddSecretVersion",
1271 extra={
1272 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1273 "rpcName": "AddSecretVersion",
1274 "httpRequest": http_request,
1275 "metadata": http_request["headers"],
1276 },
1277 )
1278
1279 # Send the request
1280 response = (
1281 SecretManagerServiceRestTransport._AddSecretVersion._get_response(
1282 self._host,
1283 metadata,
1284 query_params,
1285 self._session,
1286 timeout,
1287 transcoded_request,
1288 body,
1289 )
1290 )
1291
1292 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1293 # subclass.
1294 if response.status_code >= 400:
1295 raise core_exceptions.from_http_response(response)
1296
1297 # Return the response
1298 resp = resources.SecretVersion()
1299 pb_resp = resources.SecretVersion.pb(resp)
1300
1301 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1302
1303 resp = self._interceptor.post_add_secret_version(resp)
1304 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1305 resp, _ = self._interceptor.post_add_secret_version_with_metadata(
1306 resp, response_metadata
1307 )
1308 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1309 logging.DEBUG
1310 ): # pragma: NO COVER
1311 try:
1312 response_payload = resources.SecretVersion.to_json(response)
1313 except:
1314 response_payload = None
1315 http_response = {
1316 "payload": response_payload,
1317 "headers": dict(response.headers),
1318 "status": response.status_code,
1319 }
1320 _LOGGER.debug(
1321 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.add_secret_version",
1322 extra={
1323 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1324 "rpcName": "AddSecretVersion",
1325 "metadata": http_response["headers"],
1326 "httpResponse": http_response,
1327 },
1328 )
1329 return resp
1330
1331 class _CreateSecret(
1332 _BaseSecretManagerServiceRestTransport._BaseCreateSecret,
1333 SecretManagerServiceRestStub,
1334 ):
1335 def __hash__(self):
1336 return hash("SecretManagerServiceRestTransport.CreateSecret")
1337
1338 @staticmethod
1339 def _get_response(
1340 host,
1341 metadata,
1342 query_params,
1343 session,
1344 timeout,
1345 transcoded_request,
1346 body=None,
1347 ):
1348 uri = transcoded_request["uri"]
1349 method = transcoded_request["method"]
1350 headers = dict(metadata)
1351 headers["Content-Type"] = "application/json"
1352 response = getattr(session, method)(
1353 "{host}{uri}".format(host=host, uri=uri),
1354 timeout=timeout,
1355 headers=headers,
1356 params=rest_helpers.flatten_query_params(query_params, strict=True),
1357 data=body,
1358 )
1359 return response
1360
1361 def __call__(
1362 self,
1363 request: service.CreateSecretRequest,
1364 *,
1365 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1366 timeout: Optional[float] = None,
1367 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1368 ) -> resources.Secret:
1369 r"""Call the create secret method over HTTP.
1370
1371 Args:
1372 request (~.service.CreateSecretRequest):
1373 The request object. Request message for
1374 [SecretManagerService.CreateSecret][google.cloud.secrets.v1beta1.SecretManagerService.CreateSecret].
1375 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1376 should be retried.
1377 timeout (float): The timeout for this request.
1378 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1379 sent along with the request as metadata. Normally, each value must be of type `str`,
1380 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1381 be of type `bytes`.
1382
1383 Returns:
1384 ~.resources.Secret:
1385 A [Secret][google.cloud.secrets.v1beta1.Secret] is a
1386 logical secret whose value and versions can be accessed.
1387
1388 A [Secret][google.cloud.secrets.v1beta1.Secret] is made
1389 up of zero or more
1390 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]
1391 that represent the secret data.
1392
1393 """
1394
1395 http_options = (
1396 _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_http_options()
1397 )
1398
1399 request, metadata = self._interceptor.pre_create_secret(request, metadata)
1400 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_transcoded_request(
1401 http_options, request
1402 )
1403
1404 body = _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_request_body_json(
1405 transcoded_request
1406 )
1407
1408 # Jsonify the query params
1409 query_params = _BaseSecretManagerServiceRestTransport._BaseCreateSecret._get_query_params_json(
1410 transcoded_request
1411 )
1412
1413 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1414 logging.DEBUG
1415 ): # pragma: NO COVER
1416 request_url = "{host}{uri}".format(
1417 host=self._host, uri=transcoded_request["uri"]
1418 )
1419 method = transcoded_request["method"]
1420 try:
1421 request_payload = type(request).to_json(request)
1422 except:
1423 request_payload = None
1424 http_request = {
1425 "payload": request_payload,
1426 "requestMethod": method,
1427 "requestUrl": request_url,
1428 "headers": dict(metadata),
1429 }
1430 _LOGGER.debug(
1431 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.CreateSecret",
1432 extra={
1433 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1434 "rpcName": "CreateSecret",
1435 "httpRequest": http_request,
1436 "metadata": http_request["headers"],
1437 },
1438 )
1439
1440 # Send the request
1441 response = SecretManagerServiceRestTransport._CreateSecret._get_response(
1442 self._host,
1443 metadata,
1444 query_params,
1445 self._session,
1446 timeout,
1447 transcoded_request,
1448 body,
1449 )
1450
1451 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1452 # subclass.
1453 if response.status_code >= 400:
1454 raise core_exceptions.from_http_response(response)
1455
1456 # Return the response
1457 resp = resources.Secret()
1458 pb_resp = resources.Secret.pb(resp)
1459
1460 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1461
1462 resp = self._interceptor.post_create_secret(resp)
1463 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1464 resp, _ = self._interceptor.post_create_secret_with_metadata(
1465 resp, response_metadata
1466 )
1467 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1468 logging.DEBUG
1469 ): # pragma: NO COVER
1470 try:
1471 response_payload = resources.Secret.to_json(response)
1472 except:
1473 response_payload = None
1474 http_response = {
1475 "payload": response_payload,
1476 "headers": dict(response.headers),
1477 "status": response.status_code,
1478 }
1479 _LOGGER.debug(
1480 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.create_secret",
1481 extra={
1482 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1483 "rpcName": "CreateSecret",
1484 "metadata": http_response["headers"],
1485 "httpResponse": http_response,
1486 },
1487 )
1488 return resp
1489
1490 class _DeleteSecret(
1491 _BaseSecretManagerServiceRestTransport._BaseDeleteSecret,
1492 SecretManagerServiceRestStub,
1493 ):
1494 def __hash__(self):
1495 return hash("SecretManagerServiceRestTransport.DeleteSecret")
1496
1497 @staticmethod
1498 def _get_response(
1499 host,
1500 metadata,
1501 query_params,
1502 session,
1503 timeout,
1504 transcoded_request,
1505 body=None,
1506 ):
1507 uri = transcoded_request["uri"]
1508 method = transcoded_request["method"]
1509 headers = dict(metadata)
1510 headers["Content-Type"] = "application/json"
1511 response = getattr(session, method)(
1512 "{host}{uri}".format(host=host, uri=uri),
1513 timeout=timeout,
1514 headers=headers,
1515 params=rest_helpers.flatten_query_params(query_params, strict=True),
1516 )
1517 return response
1518
1519 def __call__(
1520 self,
1521 request: service.DeleteSecretRequest,
1522 *,
1523 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1524 timeout: Optional[float] = None,
1525 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1526 ):
1527 r"""Call the delete secret method over HTTP.
1528
1529 Args:
1530 request (~.service.DeleteSecretRequest):
1531 The request object. Request message for
1532 [SecretManagerService.DeleteSecret][google.cloud.secrets.v1beta1.SecretManagerService.DeleteSecret].
1533 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1534 should be retried.
1535 timeout (float): The timeout for this request.
1536 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1537 sent along with the request as metadata. Normally, each value must be of type `str`,
1538 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1539 be of type `bytes`.
1540 """
1541
1542 http_options = (
1543 _BaseSecretManagerServiceRestTransport._BaseDeleteSecret._get_http_options()
1544 )
1545
1546 request, metadata = self._interceptor.pre_delete_secret(request, metadata)
1547 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseDeleteSecret._get_transcoded_request(
1548 http_options, request
1549 )
1550
1551 # Jsonify the query params
1552 query_params = _BaseSecretManagerServiceRestTransport._BaseDeleteSecret._get_query_params_json(
1553 transcoded_request
1554 )
1555
1556 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1557 logging.DEBUG
1558 ): # pragma: NO COVER
1559 request_url = "{host}{uri}".format(
1560 host=self._host, uri=transcoded_request["uri"]
1561 )
1562 method = transcoded_request["method"]
1563 try:
1564 request_payload = json_format.MessageToJson(request)
1565 except:
1566 request_payload = None
1567 http_request = {
1568 "payload": request_payload,
1569 "requestMethod": method,
1570 "requestUrl": request_url,
1571 "headers": dict(metadata),
1572 }
1573 _LOGGER.debug(
1574 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.DeleteSecret",
1575 extra={
1576 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1577 "rpcName": "DeleteSecret",
1578 "httpRequest": http_request,
1579 "metadata": http_request["headers"],
1580 },
1581 )
1582
1583 # Send the request
1584 response = SecretManagerServiceRestTransport._DeleteSecret._get_response(
1585 self._host,
1586 metadata,
1587 query_params,
1588 self._session,
1589 timeout,
1590 transcoded_request,
1591 )
1592
1593 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1594 # subclass.
1595 if response.status_code >= 400:
1596 raise core_exceptions.from_http_response(response)
1597
1598 class _DestroySecretVersion(
1599 _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion,
1600 SecretManagerServiceRestStub,
1601 ):
1602 def __hash__(self):
1603 return hash("SecretManagerServiceRestTransport.DestroySecretVersion")
1604
1605 @staticmethod
1606 def _get_response(
1607 host,
1608 metadata,
1609 query_params,
1610 session,
1611 timeout,
1612 transcoded_request,
1613 body=None,
1614 ):
1615 uri = transcoded_request["uri"]
1616 method = transcoded_request["method"]
1617 headers = dict(metadata)
1618 headers["Content-Type"] = "application/json"
1619 response = getattr(session, method)(
1620 "{host}{uri}".format(host=host, uri=uri),
1621 timeout=timeout,
1622 headers=headers,
1623 params=rest_helpers.flatten_query_params(query_params, strict=True),
1624 data=body,
1625 )
1626 return response
1627
1628 def __call__(
1629 self,
1630 request: service.DestroySecretVersionRequest,
1631 *,
1632 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1633 timeout: Optional[float] = None,
1634 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1635 ) -> resources.SecretVersion:
1636 r"""Call the destroy secret version method over HTTP.
1637
1638 Args:
1639 request (~.service.DestroySecretVersionRequest):
1640 The request object. Request message for
1641 [SecretManagerService.DestroySecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.DestroySecretVersion].
1642 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1643 should be retried.
1644 timeout (float): The timeout for this request.
1645 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1646 sent along with the request as metadata. Normally, each value must be of type `str`,
1647 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1648 be of type `bytes`.
1649
1650 Returns:
1651 ~.resources.SecretVersion:
1652 A secret version resource in the
1653 Secret Manager API.
1654
1655 """
1656
1657 http_options = (
1658 _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_http_options()
1659 )
1660
1661 request, metadata = self._interceptor.pre_destroy_secret_version(
1662 request, metadata
1663 )
1664 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_transcoded_request(
1665 http_options, request
1666 )
1667
1668 body = _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_request_body_json(
1669 transcoded_request
1670 )
1671
1672 # Jsonify the query params
1673 query_params = _BaseSecretManagerServiceRestTransport._BaseDestroySecretVersion._get_query_params_json(
1674 transcoded_request
1675 )
1676
1677 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1678 logging.DEBUG
1679 ): # pragma: NO COVER
1680 request_url = "{host}{uri}".format(
1681 host=self._host, uri=transcoded_request["uri"]
1682 )
1683 method = transcoded_request["method"]
1684 try:
1685 request_payload = type(request).to_json(request)
1686 except:
1687 request_payload = None
1688 http_request = {
1689 "payload": request_payload,
1690 "requestMethod": method,
1691 "requestUrl": request_url,
1692 "headers": dict(metadata),
1693 }
1694 _LOGGER.debug(
1695 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.DestroySecretVersion",
1696 extra={
1697 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1698 "rpcName": "DestroySecretVersion",
1699 "httpRequest": http_request,
1700 "metadata": http_request["headers"],
1701 },
1702 )
1703
1704 # Send the request
1705 response = (
1706 SecretManagerServiceRestTransport._DestroySecretVersion._get_response(
1707 self._host,
1708 metadata,
1709 query_params,
1710 self._session,
1711 timeout,
1712 transcoded_request,
1713 body,
1714 )
1715 )
1716
1717 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1718 # subclass.
1719 if response.status_code >= 400:
1720 raise core_exceptions.from_http_response(response)
1721
1722 # Return the response
1723 resp = resources.SecretVersion()
1724 pb_resp = resources.SecretVersion.pb(resp)
1725
1726 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1727
1728 resp = self._interceptor.post_destroy_secret_version(resp)
1729 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1730 resp, _ = self._interceptor.post_destroy_secret_version_with_metadata(
1731 resp, response_metadata
1732 )
1733 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1734 logging.DEBUG
1735 ): # pragma: NO COVER
1736 try:
1737 response_payload = resources.SecretVersion.to_json(response)
1738 except:
1739 response_payload = None
1740 http_response = {
1741 "payload": response_payload,
1742 "headers": dict(response.headers),
1743 "status": response.status_code,
1744 }
1745 _LOGGER.debug(
1746 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.destroy_secret_version",
1747 extra={
1748 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1749 "rpcName": "DestroySecretVersion",
1750 "metadata": http_response["headers"],
1751 "httpResponse": http_response,
1752 },
1753 )
1754 return resp
1755
1756 class _DisableSecretVersion(
1757 _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion,
1758 SecretManagerServiceRestStub,
1759 ):
1760 def __hash__(self):
1761 return hash("SecretManagerServiceRestTransport.DisableSecretVersion")
1762
1763 @staticmethod
1764 def _get_response(
1765 host,
1766 metadata,
1767 query_params,
1768 session,
1769 timeout,
1770 transcoded_request,
1771 body=None,
1772 ):
1773 uri = transcoded_request["uri"]
1774 method = transcoded_request["method"]
1775 headers = dict(metadata)
1776 headers["Content-Type"] = "application/json"
1777 response = getattr(session, method)(
1778 "{host}{uri}".format(host=host, uri=uri),
1779 timeout=timeout,
1780 headers=headers,
1781 params=rest_helpers.flatten_query_params(query_params, strict=True),
1782 data=body,
1783 )
1784 return response
1785
1786 def __call__(
1787 self,
1788 request: service.DisableSecretVersionRequest,
1789 *,
1790 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1791 timeout: Optional[float] = None,
1792 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1793 ) -> resources.SecretVersion:
1794 r"""Call the disable secret version method over HTTP.
1795
1796 Args:
1797 request (~.service.DisableSecretVersionRequest):
1798 The request object. Request message for
1799 [SecretManagerService.DisableSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.DisableSecretVersion].
1800 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1801 should be retried.
1802 timeout (float): The timeout for this request.
1803 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1804 sent along with the request as metadata. Normally, each value must be of type `str`,
1805 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1806 be of type `bytes`.
1807
1808 Returns:
1809 ~.resources.SecretVersion:
1810 A secret version resource in the
1811 Secret Manager API.
1812
1813 """
1814
1815 http_options = (
1816 _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_http_options()
1817 )
1818
1819 request, metadata = self._interceptor.pre_disable_secret_version(
1820 request, metadata
1821 )
1822 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_transcoded_request(
1823 http_options, request
1824 )
1825
1826 body = _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_request_body_json(
1827 transcoded_request
1828 )
1829
1830 # Jsonify the query params
1831 query_params = _BaseSecretManagerServiceRestTransport._BaseDisableSecretVersion._get_query_params_json(
1832 transcoded_request
1833 )
1834
1835 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1836 logging.DEBUG
1837 ): # pragma: NO COVER
1838 request_url = "{host}{uri}".format(
1839 host=self._host, uri=transcoded_request["uri"]
1840 )
1841 method = transcoded_request["method"]
1842 try:
1843 request_payload = type(request).to_json(request)
1844 except:
1845 request_payload = None
1846 http_request = {
1847 "payload": request_payload,
1848 "requestMethod": method,
1849 "requestUrl": request_url,
1850 "headers": dict(metadata),
1851 }
1852 _LOGGER.debug(
1853 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.DisableSecretVersion",
1854 extra={
1855 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1856 "rpcName": "DisableSecretVersion",
1857 "httpRequest": http_request,
1858 "metadata": http_request["headers"],
1859 },
1860 )
1861
1862 # Send the request
1863 response = (
1864 SecretManagerServiceRestTransport._DisableSecretVersion._get_response(
1865 self._host,
1866 metadata,
1867 query_params,
1868 self._session,
1869 timeout,
1870 transcoded_request,
1871 body,
1872 )
1873 )
1874
1875 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1876 # subclass.
1877 if response.status_code >= 400:
1878 raise core_exceptions.from_http_response(response)
1879
1880 # Return the response
1881 resp = resources.SecretVersion()
1882 pb_resp = resources.SecretVersion.pb(resp)
1883
1884 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1885
1886 resp = self._interceptor.post_disable_secret_version(resp)
1887 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1888 resp, _ = self._interceptor.post_disable_secret_version_with_metadata(
1889 resp, response_metadata
1890 )
1891 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1892 logging.DEBUG
1893 ): # pragma: NO COVER
1894 try:
1895 response_payload = resources.SecretVersion.to_json(response)
1896 except:
1897 response_payload = None
1898 http_response = {
1899 "payload": response_payload,
1900 "headers": dict(response.headers),
1901 "status": response.status_code,
1902 }
1903 _LOGGER.debug(
1904 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.disable_secret_version",
1905 extra={
1906 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
1907 "rpcName": "DisableSecretVersion",
1908 "metadata": http_response["headers"],
1909 "httpResponse": http_response,
1910 },
1911 )
1912 return resp
1913
1914 class _EnableSecretVersion(
1915 _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion,
1916 SecretManagerServiceRestStub,
1917 ):
1918 def __hash__(self):
1919 return hash("SecretManagerServiceRestTransport.EnableSecretVersion")
1920
1921 @staticmethod
1922 def _get_response(
1923 host,
1924 metadata,
1925 query_params,
1926 session,
1927 timeout,
1928 transcoded_request,
1929 body=None,
1930 ):
1931 uri = transcoded_request["uri"]
1932 method = transcoded_request["method"]
1933 headers = dict(metadata)
1934 headers["Content-Type"] = "application/json"
1935 response = getattr(session, method)(
1936 "{host}{uri}".format(host=host, uri=uri),
1937 timeout=timeout,
1938 headers=headers,
1939 params=rest_helpers.flatten_query_params(query_params, strict=True),
1940 data=body,
1941 )
1942 return response
1943
1944 def __call__(
1945 self,
1946 request: service.EnableSecretVersionRequest,
1947 *,
1948 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1949 timeout: Optional[float] = None,
1950 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1951 ) -> resources.SecretVersion:
1952 r"""Call the enable secret version method over HTTP.
1953
1954 Args:
1955 request (~.service.EnableSecretVersionRequest):
1956 The request object. Request message for
1957 [SecretManagerService.EnableSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.EnableSecretVersion].
1958 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1959 should be retried.
1960 timeout (float): The timeout for this request.
1961 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1962 sent along with the request as metadata. Normally, each value must be of type `str`,
1963 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1964 be of type `bytes`.
1965
1966 Returns:
1967 ~.resources.SecretVersion:
1968 A secret version resource in the
1969 Secret Manager API.
1970
1971 """
1972
1973 http_options = (
1974 _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_http_options()
1975 )
1976
1977 request, metadata = self._interceptor.pre_enable_secret_version(
1978 request, metadata
1979 )
1980 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_transcoded_request(
1981 http_options, request
1982 )
1983
1984 body = _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_request_body_json(
1985 transcoded_request
1986 )
1987
1988 # Jsonify the query params
1989 query_params = _BaseSecretManagerServiceRestTransport._BaseEnableSecretVersion._get_query_params_json(
1990 transcoded_request
1991 )
1992
1993 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1994 logging.DEBUG
1995 ): # pragma: NO COVER
1996 request_url = "{host}{uri}".format(
1997 host=self._host, uri=transcoded_request["uri"]
1998 )
1999 method = transcoded_request["method"]
2000 try:
2001 request_payload = type(request).to_json(request)
2002 except:
2003 request_payload = None
2004 http_request = {
2005 "payload": request_payload,
2006 "requestMethod": method,
2007 "requestUrl": request_url,
2008 "headers": dict(metadata),
2009 }
2010 _LOGGER.debug(
2011 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.EnableSecretVersion",
2012 extra={
2013 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2014 "rpcName": "EnableSecretVersion",
2015 "httpRequest": http_request,
2016 "metadata": http_request["headers"],
2017 },
2018 )
2019
2020 # Send the request
2021 response = (
2022 SecretManagerServiceRestTransport._EnableSecretVersion._get_response(
2023 self._host,
2024 metadata,
2025 query_params,
2026 self._session,
2027 timeout,
2028 transcoded_request,
2029 body,
2030 )
2031 )
2032
2033 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2034 # subclass.
2035 if response.status_code >= 400:
2036 raise core_exceptions.from_http_response(response)
2037
2038 # Return the response
2039 resp = resources.SecretVersion()
2040 pb_resp = resources.SecretVersion.pb(resp)
2041
2042 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2043
2044 resp = self._interceptor.post_enable_secret_version(resp)
2045 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2046 resp, _ = self._interceptor.post_enable_secret_version_with_metadata(
2047 resp, response_metadata
2048 )
2049 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2050 logging.DEBUG
2051 ): # pragma: NO COVER
2052 try:
2053 response_payload = resources.SecretVersion.to_json(response)
2054 except:
2055 response_payload = None
2056 http_response = {
2057 "payload": response_payload,
2058 "headers": dict(response.headers),
2059 "status": response.status_code,
2060 }
2061 _LOGGER.debug(
2062 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.enable_secret_version",
2063 extra={
2064 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2065 "rpcName": "EnableSecretVersion",
2066 "metadata": http_response["headers"],
2067 "httpResponse": http_response,
2068 },
2069 )
2070 return resp
2071
2072 class _GetIamPolicy(
2073 _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy,
2074 SecretManagerServiceRestStub,
2075 ):
2076 def __hash__(self):
2077 return hash("SecretManagerServiceRestTransport.GetIamPolicy")
2078
2079 @staticmethod
2080 def _get_response(
2081 host,
2082 metadata,
2083 query_params,
2084 session,
2085 timeout,
2086 transcoded_request,
2087 body=None,
2088 ):
2089 uri = transcoded_request["uri"]
2090 method = transcoded_request["method"]
2091 headers = dict(metadata)
2092 headers["Content-Type"] = "application/json"
2093 response = getattr(session, method)(
2094 "{host}{uri}".format(host=host, uri=uri),
2095 timeout=timeout,
2096 headers=headers,
2097 params=rest_helpers.flatten_query_params(query_params, strict=True),
2098 )
2099 return response
2100
2101 def __call__(
2102 self,
2103 request: iam_policy_pb2.GetIamPolicyRequest,
2104 *,
2105 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2106 timeout: Optional[float] = None,
2107 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2108 ) -> policy_pb2.Policy:
2109 r"""Call the get iam policy method over HTTP.
2110
2111 Args:
2112 request (~.iam_policy_pb2.GetIamPolicyRequest):
2113 The request object. Request message for ``GetIamPolicy`` method.
2114 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2115 should be retried.
2116 timeout (float): The timeout for this request.
2117 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2118 sent along with the request as metadata. Normally, each value must be of type `str`,
2119 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2120 be of type `bytes`.
2121
2122 Returns:
2123 ~.policy_pb2.Policy:
2124 An Identity and Access Management (IAM) policy, which
2125 specifies access controls for Google Cloud resources.
2126
2127 A ``Policy`` is a collection of ``bindings``. A
2128 ``binding`` binds one or more ``members``, or
2129 principals, to a single ``role``. Principals can be user
2130 accounts, service accounts, Google groups, and domains
2131 (such as G Suite). A ``role`` is a named list of
2132 permissions; each ``role`` can be an IAM predefined role
2133 or a user-created custom role.
2134
2135 For some types of Google Cloud resources, a ``binding``
2136 can also specify a ``condition``, which is a logical
2137 expression that allows access to a resource only if the
2138 expression evaluates to ``true``. A condition can add
2139 constraints based on attributes of the request, the
2140 resource, or both. To learn which resources support
2141 conditions in their IAM policies, see the `IAM
2142 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__.
2143
2144 **JSON example:**
2145
2146 ::
2147
2148 {
2149 "bindings": [
2150 {
2151 "role": "roles/resourcemanager.organizationAdmin",
2152 "members": [
2153 "user:mike@example.com",
2154 "group:admins@example.com",
2155 "domain:google.com",
2156 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
2157 ]
2158 },
2159 {
2160 "role": "roles/resourcemanager.organizationViewer",
2161 "members": [
2162 "user:eve@example.com"
2163 ],
2164 "condition": {
2165 "title": "expirable access",
2166 "description": "Does not grant access after Sep 2020",
2167 "expression": "request.time <
2168 timestamp('2020-10-01T00:00:00.000Z')",
2169 }
2170 }
2171 ],
2172 "etag": "BwWWja0YfJA=",
2173 "version": 3
2174 }
2175
2176 **YAML example:**
2177
2178 ::
2179
2180 bindings:
2181 - members:
2182 - user:mike@example.com
2183 - group:admins@example.com
2184 - domain:google.com
2185 - serviceAccount:my-project-id@appspot.gserviceaccount.com
2186 role: roles/resourcemanager.organizationAdmin
2187 - members:
2188 - user:eve@example.com
2189 role: roles/resourcemanager.organizationViewer
2190 condition:
2191 title: expirable access
2192 description: Does not grant access after Sep 2020
2193 expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
2194 etag: BwWWja0YfJA=
2195 version: 3
2196
2197 For a description of IAM and its features, see the `IAM
2198 documentation <https://cloud.google.com/iam/docs/>`__.
2199
2200 """
2201
2202 http_options = (
2203 _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy._get_http_options()
2204 )
2205
2206 request, metadata = self._interceptor.pre_get_iam_policy(request, metadata)
2207 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy._get_transcoded_request(
2208 http_options, request
2209 )
2210
2211 # Jsonify the query params
2212 query_params = _BaseSecretManagerServiceRestTransport._BaseGetIamPolicy._get_query_params_json(
2213 transcoded_request
2214 )
2215
2216 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2217 logging.DEBUG
2218 ): # pragma: NO COVER
2219 request_url = "{host}{uri}".format(
2220 host=self._host, uri=transcoded_request["uri"]
2221 )
2222 method = transcoded_request["method"]
2223 try:
2224 request_payload = json_format.MessageToJson(request)
2225 except:
2226 request_payload = None
2227 http_request = {
2228 "payload": request_payload,
2229 "requestMethod": method,
2230 "requestUrl": request_url,
2231 "headers": dict(metadata),
2232 }
2233 _LOGGER.debug(
2234 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetIamPolicy",
2235 extra={
2236 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2237 "rpcName": "GetIamPolicy",
2238 "httpRequest": http_request,
2239 "metadata": http_request["headers"],
2240 },
2241 )
2242
2243 # Send the request
2244 response = SecretManagerServiceRestTransport._GetIamPolicy._get_response(
2245 self._host,
2246 metadata,
2247 query_params,
2248 self._session,
2249 timeout,
2250 transcoded_request,
2251 )
2252
2253 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2254 # subclass.
2255 if response.status_code >= 400:
2256 raise core_exceptions.from_http_response(response)
2257
2258 # Return the response
2259 resp = policy_pb2.Policy()
2260 pb_resp = resp
2261
2262 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2263
2264 resp = self._interceptor.post_get_iam_policy(resp)
2265 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2266 resp, _ = self._interceptor.post_get_iam_policy_with_metadata(
2267 resp, response_metadata
2268 )
2269 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2270 logging.DEBUG
2271 ): # pragma: NO COVER
2272 try:
2273 response_payload = json_format.MessageToJson(resp)
2274 except:
2275 response_payload = None
2276 http_response = {
2277 "payload": response_payload,
2278 "headers": dict(response.headers),
2279 "status": response.status_code,
2280 }
2281 _LOGGER.debug(
2282 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.get_iam_policy",
2283 extra={
2284 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2285 "rpcName": "GetIamPolicy",
2286 "metadata": http_response["headers"],
2287 "httpResponse": http_response,
2288 },
2289 )
2290 return resp
2291
2292 class _GetSecret(
2293 _BaseSecretManagerServiceRestTransport._BaseGetSecret,
2294 SecretManagerServiceRestStub,
2295 ):
2296 def __hash__(self):
2297 return hash("SecretManagerServiceRestTransport.GetSecret")
2298
2299 @staticmethod
2300 def _get_response(
2301 host,
2302 metadata,
2303 query_params,
2304 session,
2305 timeout,
2306 transcoded_request,
2307 body=None,
2308 ):
2309 uri = transcoded_request["uri"]
2310 method = transcoded_request["method"]
2311 headers = dict(metadata)
2312 headers["Content-Type"] = "application/json"
2313 response = getattr(session, method)(
2314 "{host}{uri}".format(host=host, uri=uri),
2315 timeout=timeout,
2316 headers=headers,
2317 params=rest_helpers.flatten_query_params(query_params, strict=True),
2318 )
2319 return response
2320
2321 def __call__(
2322 self,
2323 request: service.GetSecretRequest,
2324 *,
2325 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2326 timeout: Optional[float] = None,
2327 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2328 ) -> resources.Secret:
2329 r"""Call the get secret method over HTTP.
2330
2331 Args:
2332 request (~.service.GetSecretRequest):
2333 The request object. Request message for
2334 [SecretManagerService.GetSecret][google.cloud.secrets.v1beta1.SecretManagerService.GetSecret].
2335 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2336 should be retried.
2337 timeout (float): The timeout for this request.
2338 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2339 sent along with the request as metadata. Normally, each value must be of type `str`,
2340 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2341 be of type `bytes`.
2342
2343 Returns:
2344 ~.resources.Secret:
2345 A [Secret][google.cloud.secrets.v1beta1.Secret] is a
2346 logical secret whose value and versions can be accessed.
2347
2348 A [Secret][google.cloud.secrets.v1beta1.Secret] is made
2349 up of zero or more
2350 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]
2351 that represent the secret data.
2352
2353 """
2354
2355 http_options = (
2356 _BaseSecretManagerServiceRestTransport._BaseGetSecret._get_http_options()
2357 )
2358
2359 request, metadata = self._interceptor.pre_get_secret(request, metadata)
2360 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetSecret._get_transcoded_request(
2361 http_options, request
2362 )
2363
2364 # Jsonify the query params
2365 query_params = _BaseSecretManagerServiceRestTransport._BaseGetSecret._get_query_params_json(
2366 transcoded_request
2367 )
2368
2369 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2370 logging.DEBUG
2371 ): # pragma: NO COVER
2372 request_url = "{host}{uri}".format(
2373 host=self._host, uri=transcoded_request["uri"]
2374 )
2375 method = transcoded_request["method"]
2376 try:
2377 request_payload = type(request).to_json(request)
2378 except:
2379 request_payload = None
2380 http_request = {
2381 "payload": request_payload,
2382 "requestMethod": method,
2383 "requestUrl": request_url,
2384 "headers": dict(metadata),
2385 }
2386 _LOGGER.debug(
2387 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetSecret",
2388 extra={
2389 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2390 "rpcName": "GetSecret",
2391 "httpRequest": http_request,
2392 "metadata": http_request["headers"],
2393 },
2394 )
2395
2396 # Send the request
2397 response = SecretManagerServiceRestTransport._GetSecret._get_response(
2398 self._host,
2399 metadata,
2400 query_params,
2401 self._session,
2402 timeout,
2403 transcoded_request,
2404 )
2405
2406 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2407 # subclass.
2408 if response.status_code >= 400:
2409 raise core_exceptions.from_http_response(response)
2410
2411 # Return the response
2412 resp = resources.Secret()
2413 pb_resp = resources.Secret.pb(resp)
2414
2415 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2416
2417 resp = self._interceptor.post_get_secret(resp)
2418 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2419 resp, _ = self._interceptor.post_get_secret_with_metadata(
2420 resp, response_metadata
2421 )
2422 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2423 logging.DEBUG
2424 ): # pragma: NO COVER
2425 try:
2426 response_payload = resources.Secret.to_json(response)
2427 except:
2428 response_payload = None
2429 http_response = {
2430 "payload": response_payload,
2431 "headers": dict(response.headers),
2432 "status": response.status_code,
2433 }
2434 _LOGGER.debug(
2435 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.get_secret",
2436 extra={
2437 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2438 "rpcName": "GetSecret",
2439 "metadata": http_response["headers"],
2440 "httpResponse": http_response,
2441 },
2442 )
2443 return resp
2444
2445 class _GetSecretVersion(
2446 _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion,
2447 SecretManagerServiceRestStub,
2448 ):
2449 def __hash__(self):
2450 return hash("SecretManagerServiceRestTransport.GetSecretVersion")
2451
2452 @staticmethod
2453 def _get_response(
2454 host,
2455 metadata,
2456 query_params,
2457 session,
2458 timeout,
2459 transcoded_request,
2460 body=None,
2461 ):
2462 uri = transcoded_request["uri"]
2463 method = transcoded_request["method"]
2464 headers = dict(metadata)
2465 headers["Content-Type"] = "application/json"
2466 response = getattr(session, method)(
2467 "{host}{uri}".format(host=host, uri=uri),
2468 timeout=timeout,
2469 headers=headers,
2470 params=rest_helpers.flatten_query_params(query_params, strict=True),
2471 )
2472 return response
2473
2474 def __call__(
2475 self,
2476 request: service.GetSecretVersionRequest,
2477 *,
2478 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2479 timeout: Optional[float] = None,
2480 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2481 ) -> resources.SecretVersion:
2482 r"""Call the get secret version method over HTTP.
2483
2484 Args:
2485 request (~.service.GetSecretVersionRequest):
2486 The request object. Request message for
2487 [SecretManagerService.GetSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.GetSecretVersion].
2488 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2489 should be retried.
2490 timeout (float): The timeout for this request.
2491 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2492 sent along with the request as metadata. Normally, each value must be of type `str`,
2493 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2494 be of type `bytes`.
2495
2496 Returns:
2497 ~.resources.SecretVersion:
2498 A secret version resource in the
2499 Secret Manager API.
2500
2501 """
2502
2503 http_options = (
2504 _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion._get_http_options()
2505 )
2506
2507 request, metadata = self._interceptor.pre_get_secret_version(
2508 request, metadata
2509 )
2510 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion._get_transcoded_request(
2511 http_options, request
2512 )
2513
2514 # Jsonify the query params
2515 query_params = _BaseSecretManagerServiceRestTransport._BaseGetSecretVersion._get_query_params_json(
2516 transcoded_request
2517 )
2518
2519 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2520 logging.DEBUG
2521 ): # pragma: NO COVER
2522 request_url = "{host}{uri}".format(
2523 host=self._host, uri=transcoded_request["uri"]
2524 )
2525 method = transcoded_request["method"]
2526 try:
2527 request_payload = type(request).to_json(request)
2528 except:
2529 request_payload = None
2530 http_request = {
2531 "payload": request_payload,
2532 "requestMethod": method,
2533 "requestUrl": request_url,
2534 "headers": dict(metadata),
2535 }
2536 _LOGGER.debug(
2537 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetSecretVersion",
2538 extra={
2539 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2540 "rpcName": "GetSecretVersion",
2541 "httpRequest": http_request,
2542 "metadata": http_request["headers"],
2543 },
2544 )
2545
2546 # Send the request
2547 response = (
2548 SecretManagerServiceRestTransport._GetSecretVersion._get_response(
2549 self._host,
2550 metadata,
2551 query_params,
2552 self._session,
2553 timeout,
2554 transcoded_request,
2555 )
2556 )
2557
2558 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2559 # subclass.
2560 if response.status_code >= 400:
2561 raise core_exceptions.from_http_response(response)
2562
2563 # Return the response
2564 resp = resources.SecretVersion()
2565 pb_resp = resources.SecretVersion.pb(resp)
2566
2567 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2568
2569 resp = self._interceptor.post_get_secret_version(resp)
2570 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2571 resp, _ = self._interceptor.post_get_secret_version_with_metadata(
2572 resp, response_metadata
2573 )
2574 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2575 logging.DEBUG
2576 ): # pragma: NO COVER
2577 try:
2578 response_payload = resources.SecretVersion.to_json(response)
2579 except:
2580 response_payload = None
2581 http_response = {
2582 "payload": response_payload,
2583 "headers": dict(response.headers),
2584 "status": response.status_code,
2585 }
2586 _LOGGER.debug(
2587 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.get_secret_version",
2588 extra={
2589 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2590 "rpcName": "GetSecretVersion",
2591 "metadata": http_response["headers"],
2592 "httpResponse": http_response,
2593 },
2594 )
2595 return resp
2596
2597 class _ListSecrets(
2598 _BaseSecretManagerServiceRestTransport._BaseListSecrets,
2599 SecretManagerServiceRestStub,
2600 ):
2601 def __hash__(self):
2602 return hash("SecretManagerServiceRestTransport.ListSecrets")
2603
2604 @staticmethod
2605 def _get_response(
2606 host,
2607 metadata,
2608 query_params,
2609 session,
2610 timeout,
2611 transcoded_request,
2612 body=None,
2613 ):
2614 uri = transcoded_request["uri"]
2615 method = transcoded_request["method"]
2616 headers = dict(metadata)
2617 headers["Content-Type"] = "application/json"
2618 response = getattr(session, method)(
2619 "{host}{uri}".format(host=host, uri=uri),
2620 timeout=timeout,
2621 headers=headers,
2622 params=rest_helpers.flatten_query_params(query_params, strict=True),
2623 )
2624 return response
2625
2626 def __call__(
2627 self,
2628 request: service.ListSecretsRequest,
2629 *,
2630 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2631 timeout: Optional[float] = None,
2632 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2633 ) -> service.ListSecretsResponse:
2634 r"""Call the list secrets method over HTTP.
2635
2636 Args:
2637 request (~.service.ListSecretsRequest):
2638 The request object. Request message for
2639 [SecretManagerService.ListSecrets][google.cloud.secrets.v1beta1.SecretManagerService.ListSecrets].
2640 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2641 should be retried.
2642 timeout (float): The timeout for this request.
2643 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2644 sent along with the request as metadata. Normally, each value must be of type `str`,
2645 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2646 be of type `bytes`.
2647
2648 Returns:
2649 ~.service.ListSecretsResponse:
2650 Response message for
2651 [SecretManagerService.ListSecrets][google.cloud.secrets.v1beta1.SecretManagerService.ListSecrets].
2652
2653 """
2654
2655 http_options = (
2656 _BaseSecretManagerServiceRestTransport._BaseListSecrets._get_http_options()
2657 )
2658
2659 request, metadata = self._interceptor.pre_list_secrets(request, metadata)
2660 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseListSecrets._get_transcoded_request(
2661 http_options, request
2662 )
2663
2664 # Jsonify the query params
2665 query_params = _BaseSecretManagerServiceRestTransport._BaseListSecrets._get_query_params_json(
2666 transcoded_request
2667 )
2668
2669 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2670 logging.DEBUG
2671 ): # pragma: NO COVER
2672 request_url = "{host}{uri}".format(
2673 host=self._host, uri=transcoded_request["uri"]
2674 )
2675 method = transcoded_request["method"]
2676 try:
2677 request_payload = type(request).to_json(request)
2678 except:
2679 request_payload = None
2680 http_request = {
2681 "payload": request_payload,
2682 "requestMethod": method,
2683 "requestUrl": request_url,
2684 "headers": dict(metadata),
2685 }
2686 _LOGGER.debug(
2687 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.ListSecrets",
2688 extra={
2689 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2690 "rpcName": "ListSecrets",
2691 "httpRequest": http_request,
2692 "metadata": http_request["headers"],
2693 },
2694 )
2695
2696 # Send the request
2697 response = SecretManagerServiceRestTransport._ListSecrets._get_response(
2698 self._host,
2699 metadata,
2700 query_params,
2701 self._session,
2702 timeout,
2703 transcoded_request,
2704 )
2705
2706 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2707 # subclass.
2708 if response.status_code >= 400:
2709 raise core_exceptions.from_http_response(response)
2710
2711 # Return the response
2712 resp = service.ListSecretsResponse()
2713 pb_resp = service.ListSecretsResponse.pb(resp)
2714
2715 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2716
2717 resp = self._interceptor.post_list_secrets(resp)
2718 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2719 resp, _ = self._interceptor.post_list_secrets_with_metadata(
2720 resp, response_metadata
2721 )
2722 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2723 logging.DEBUG
2724 ): # pragma: NO COVER
2725 try:
2726 response_payload = service.ListSecretsResponse.to_json(response)
2727 except:
2728 response_payload = None
2729 http_response = {
2730 "payload": response_payload,
2731 "headers": dict(response.headers),
2732 "status": response.status_code,
2733 }
2734 _LOGGER.debug(
2735 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.list_secrets",
2736 extra={
2737 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2738 "rpcName": "ListSecrets",
2739 "metadata": http_response["headers"],
2740 "httpResponse": http_response,
2741 },
2742 )
2743 return resp
2744
2745 class _ListSecretVersions(
2746 _BaseSecretManagerServiceRestTransport._BaseListSecretVersions,
2747 SecretManagerServiceRestStub,
2748 ):
2749 def __hash__(self):
2750 return hash("SecretManagerServiceRestTransport.ListSecretVersions")
2751
2752 @staticmethod
2753 def _get_response(
2754 host,
2755 metadata,
2756 query_params,
2757 session,
2758 timeout,
2759 transcoded_request,
2760 body=None,
2761 ):
2762 uri = transcoded_request["uri"]
2763 method = transcoded_request["method"]
2764 headers = dict(metadata)
2765 headers["Content-Type"] = "application/json"
2766 response = getattr(session, method)(
2767 "{host}{uri}".format(host=host, uri=uri),
2768 timeout=timeout,
2769 headers=headers,
2770 params=rest_helpers.flatten_query_params(query_params, strict=True),
2771 )
2772 return response
2773
2774 def __call__(
2775 self,
2776 request: service.ListSecretVersionsRequest,
2777 *,
2778 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2779 timeout: Optional[float] = None,
2780 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2781 ) -> service.ListSecretVersionsResponse:
2782 r"""Call the list secret versions method over HTTP.
2783
2784 Args:
2785 request (~.service.ListSecretVersionsRequest):
2786 The request object. Request message for
2787 [SecretManagerService.ListSecretVersions][google.cloud.secrets.v1beta1.SecretManagerService.ListSecretVersions].
2788 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2789 should be retried.
2790 timeout (float): The timeout for this request.
2791 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2792 sent along with the request as metadata. Normally, each value must be of type `str`,
2793 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2794 be of type `bytes`.
2795
2796 Returns:
2797 ~.service.ListSecretVersionsResponse:
2798 Response message for
2799 [SecretManagerService.ListSecretVersions][google.cloud.secrets.v1beta1.SecretManagerService.ListSecretVersions].
2800
2801 """
2802
2803 http_options = (
2804 _BaseSecretManagerServiceRestTransport._BaseListSecretVersions._get_http_options()
2805 )
2806
2807 request, metadata = self._interceptor.pre_list_secret_versions(
2808 request, metadata
2809 )
2810 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseListSecretVersions._get_transcoded_request(
2811 http_options, request
2812 )
2813
2814 # Jsonify the query params
2815 query_params = _BaseSecretManagerServiceRestTransport._BaseListSecretVersions._get_query_params_json(
2816 transcoded_request
2817 )
2818
2819 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2820 logging.DEBUG
2821 ): # pragma: NO COVER
2822 request_url = "{host}{uri}".format(
2823 host=self._host, uri=transcoded_request["uri"]
2824 )
2825 method = transcoded_request["method"]
2826 try:
2827 request_payload = type(request).to_json(request)
2828 except:
2829 request_payload = None
2830 http_request = {
2831 "payload": request_payload,
2832 "requestMethod": method,
2833 "requestUrl": request_url,
2834 "headers": dict(metadata),
2835 }
2836 _LOGGER.debug(
2837 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.ListSecretVersions",
2838 extra={
2839 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2840 "rpcName": "ListSecretVersions",
2841 "httpRequest": http_request,
2842 "metadata": http_request["headers"],
2843 },
2844 )
2845
2846 # Send the request
2847 response = (
2848 SecretManagerServiceRestTransport._ListSecretVersions._get_response(
2849 self._host,
2850 metadata,
2851 query_params,
2852 self._session,
2853 timeout,
2854 transcoded_request,
2855 )
2856 )
2857
2858 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
2859 # subclass.
2860 if response.status_code >= 400:
2861 raise core_exceptions.from_http_response(response)
2862
2863 # Return the response
2864 resp = service.ListSecretVersionsResponse()
2865 pb_resp = service.ListSecretVersionsResponse.pb(resp)
2866
2867 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
2868
2869 resp = self._interceptor.post_list_secret_versions(resp)
2870 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
2871 resp, _ = self._interceptor.post_list_secret_versions_with_metadata(
2872 resp, response_metadata
2873 )
2874 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
2875 logging.DEBUG
2876 ): # pragma: NO COVER
2877 try:
2878 response_payload = service.ListSecretVersionsResponse.to_json(
2879 response
2880 )
2881 except:
2882 response_payload = None
2883 http_response = {
2884 "payload": response_payload,
2885 "headers": dict(response.headers),
2886 "status": response.status_code,
2887 }
2888 _LOGGER.debug(
2889 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.list_secret_versions",
2890 extra={
2891 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
2892 "rpcName": "ListSecretVersions",
2893 "metadata": http_response["headers"],
2894 "httpResponse": http_response,
2895 },
2896 )
2897 return resp
2898
2899 class _SetIamPolicy(
2900 _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy,
2901 SecretManagerServiceRestStub,
2902 ):
2903 def __hash__(self):
2904 return hash("SecretManagerServiceRestTransport.SetIamPolicy")
2905
2906 @staticmethod
2907 def _get_response(
2908 host,
2909 metadata,
2910 query_params,
2911 session,
2912 timeout,
2913 transcoded_request,
2914 body=None,
2915 ):
2916 uri = transcoded_request["uri"]
2917 method = transcoded_request["method"]
2918 headers = dict(metadata)
2919 headers["Content-Type"] = "application/json"
2920 response = getattr(session, method)(
2921 "{host}{uri}".format(host=host, uri=uri),
2922 timeout=timeout,
2923 headers=headers,
2924 params=rest_helpers.flatten_query_params(query_params, strict=True),
2925 data=body,
2926 )
2927 return response
2928
2929 def __call__(
2930 self,
2931 request: iam_policy_pb2.SetIamPolicyRequest,
2932 *,
2933 retry: OptionalRetry = gapic_v1.method.DEFAULT,
2934 timeout: Optional[float] = None,
2935 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2936 ) -> policy_pb2.Policy:
2937 r"""Call the set iam policy method over HTTP.
2938
2939 Args:
2940 request (~.iam_policy_pb2.SetIamPolicyRequest):
2941 The request object. Request message for ``SetIamPolicy`` method.
2942 retry (google.api_core.retry.Retry): Designation of what errors, if any,
2943 should be retried.
2944 timeout (float): The timeout for this request.
2945 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2946 sent along with the request as metadata. Normally, each value must be of type `str`,
2947 but for metadata keys ending with the suffix `-bin`, the corresponding values must
2948 be of type `bytes`.
2949
2950 Returns:
2951 ~.policy_pb2.Policy:
2952 An Identity and Access Management (IAM) policy, which
2953 specifies access controls for Google Cloud resources.
2954
2955 A ``Policy`` is a collection of ``bindings``. A
2956 ``binding`` binds one or more ``members``, or
2957 principals, to a single ``role``. Principals can be user
2958 accounts, service accounts, Google groups, and domains
2959 (such as G Suite). A ``role`` is a named list of
2960 permissions; each ``role`` can be an IAM predefined role
2961 or a user-created custom role.
2962
2963 For some types of Google Cloud resources, a ``binding``
2964 can also specify a ``condition``, which is a logical
2965 expression that allows access to a resource only if the
2966 expression evaluates to ``true``. A condition can add
2967 constraints based on attributes of the request, the
2968 resource, or both. To learn which resources support
2969 conditions in their IAM policies, see the `IAM
2970 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__.
2971
2972 **JSON example:**
2973
2974 ::
2975
2976 {
2977 "bindings": [
2978 {
2979 "role": "roles/resourcemanager.organizationAdmin",
2980 "members": [
2981 "user:mike@example.com",
2982 "group:admins@example.com",
2983 "domain:google.com",
2984 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
2985 ]
2986 },
2987 {
2988 "role": "roles/resourcemanager.organizationViewer",
2989 "members": [
2990 "user:eve@example.com"
2991 ],
2992 "condition": {
2993 "title": "expirable access",
2994 "description": "Does not grant access after Sep 2020",
2995 "expression": "request.time <
2996 timestamp('2020-10-01T00:00:00.000Z')",
2997 }
2998 }
2999 ],
3000 "etag": "BwWWja0YfJA=",
3001 "version": 3
3002 }
3003
3004 **YAML example:**
3005
3006 ::
3007
3008 bindings:
3009 - members:
3010 - user:mike@example.com
3011 - group:admins@example.com
3012 - domain:google.com
3013 - serviceAccount:my-project-id@appspot.gserviceaccount.com
3014 role: roles/resourcemanager.organizationAdmin
3015 - members:
3016 - user:eve@example.com
3017 role: roles/resourcemanager.organizationViewer
3018 condition:
3019 title: expirable access
3020 description: Does not grant access after Sep 2020
3021 expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
3022 etag: BwWWja0YfJA=
3023 version: 3
3024
3025 For a description of IAM and its features, see the `IAM
3026 documentation <https://cloud.google.com/iam/docs/>`__.
3027
3028 """
3029
3030 http_options = (
3031 _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_http_options()
3032 )
3033
3034 request, metadata = self._interceptor.pre_set_iam_policy(request, metadata)
3035 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_transcoded_request(
3036 http_options, request
3037 )
3038
3039 body = _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_request_body_json(
3040 transcoded_request
3041 )
3042
3043 # Jsonify the query params
3044 query_params = _BaseSecretManagerServiceRestTransport._BaseSetIamPolicy._get_query_params_json(
3045 transcoded_request
3046 )
3047
3048 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3049 logging.DEBUG
3050 ): # pragma: NO COVER
3051 request_url = "{host}{uri}".format(
3052 host=self._host, uri=transcoded_request["uri"]
3053 )
3054 method = transcoded_request["method"]
3055 try:
3056 request_payload = json_format.MessageToJson(request)
3057 except:
3058 request_payload = None
3059 http_request = {
3060 "payload": request_payload,
3061 "requestMethod": method,
3062 "requestUrl": request_url,
3063 "headers": dict(metadata),
3064 }
3065 _LOGGER.debug(
3066 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.SetIamPolicy",
3067 extra={
3068 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3069 "rpcName": "SetIamPolicy",
3070 "httpRequest": http_request,
3071 "metadata": http_request["headers"],
3072 },
3073 )
3074
3075 # Send the request
3076 response = SecretManagerServiceRestTransport._SetIamPolicy._get_response(
3077 self._host,
3078 metadata,
3079 query_params,
3080 self._session,
3081 timeout,
3082 transcoded_request,
3083 body,
3084 )
3085
3086 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3087 # subclass.
3088 if response.status_code >= 400:
3089 raise core_exceptions.from_http_response(response)
3090
3091 # Return the response
3092 resp = policy_pb2.Policy()
3093 pb_resp = resp
3094
3095 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
3096
3097 resp = self._interceptor.post_set_iam_policy(resp)
3098 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
3099 resp, _ = self._interceptor.post_set_iam_policy_with_metadata(
3100 resp, response_metadata
3101 )
3102 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3103 logging.DEBUG
3104 ): # pragma: NO COVER
3105 try:
3106 response_payload = json_format.MessageToJson(resp)
3107 except:
3108 response_payload = None
3109 http_response = {
3110 "payload": response_payload,
3111 "headers": dict(response.headers),
3112 "status": response.status_code,
3113 }
3114 _LOGGER.debug(
3115 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.set_iam_policy",
3116 extra={
3117 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3118 "rpcName": "SetIamPolicy",
3119 "metadata": http_response["headers"],
3120 "httpResponse": http_response,
3121 },
3122 )
3123 return resp
3124
3125 class _TestIamPermissions(
3126 _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions,
3127 SecretManagerServiceRestStub,
3128 ):
3129 def __hash__(self):
3130 return hash("SecretManagerServiceRestTransport.TestIamPermissions")
3131
3132 @staticmethod
3133 def _get_response(
3134 host,
3135 metadata,
3136 query_params,
3137 session,
3138 timeout,
3139 transcoded_request,
3140 body=None,
3141 ):
3142 uri = transcoded_request["uri"]
3143 method = transcoded_request["method"]
3144 headers = dict(metadata)
3145 headers["Content-Type"] = "application/json"
3146 response = getattr(session, method)(
3147 "{host}{uri}".format(host=host, uri=uri),
3148 timeout=timeout,
3149 headers=headers,
3150 params=rest_helpers.flatten_query_params(query_params, strict=True),
3151 data=body,
3152 )
3153 return response
3154
3155 def __call__(
3156 self,
3157 request: iam_policy_pb2.TestIamPermissionsRequest,
3158 *,
3159 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3160 timeout: Optional[float] = None,
3161 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3162 ) -> iam_policy_pb2.TestIamPermissionsResponse:
3163 r"""Call the test iam permissions method over HTTP.
3164
3165 Args:
3166 request (~.iam_policy_pb2.TestIamPermissionsRequest):
3167 The request object. Request message for ``TestIamPermissions`` method.
3168 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3169 should be retried.
3170 timeout (float): The timeout for this request.
3171 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3172 sent along with the request as metadata. Normally, each value must be of type `str`,
3173 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3174 be of type `bytes`.
3175
3176 Returns:
3177 ~.iam_policy_pb2.TestIamPermissionsResponse:
3178 Response message for ``TestIamPermissions`` method.
3179 """
3180
3181 http_options = (
3182 _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_http_options()
3183 )
3184
3185 request, metadata = self._interceptor.pre_test_iam_permissions(
3186 request, metadata
3187 )
3188 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_transcoded_request(
3189 http_options, request
3190 )
3191
3192 body = _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_request_body_json(
3193 transcoded_request
3194 )
3195
3196 # Jsonify the query params
3197 query_params = _BaseSecretManagerServiceRestTransport._BaseTestIamPermissions._get_query_params_json(
3198 transcoded_request
3199 )
3200
3201 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3202 logging.DEBUG
3203 ): # pragma: NO COVER
3204 request_url = "{host}{uri}".format(
3205 host=self._host, uri=transcoded_request["uri"]
3206 )
3207 method = transcoded_request["method"]
3208 try:
3209 request_payload = json_format.MessageToJson(request)
3210 except:
3211 request_payload = None
3212 http_request = {
3213 "payload": request_payload,
3214 "requestMethod": method,
3215 "requestUrl": request_url,
3216 "headers": dict(metadata),
3217 }
3218 _LOGGER.debug(
3219 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.TestIamPermissions",
3220 extra={
3221 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3222 "rpcName": "TestIamPermissions",
3223 "httpRequest": http_request,
3224 "metadata": http_request["headers"],
3225 },
3226 )
3227
3228 # Send the request
3229 response = (
3230 SecretManagerServiceRestTransport._TestIamPermissions._get_response(
3231 self._host,
3232 metadata,
3233 query_params,
3234 self._session,
3235 timeout,
3236 transcoded_request,
3237 body,
3238 )
3239 )
3240
3241 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3242 # subclass.
3243 if response.status_code >= 400:
3244 raise core_exceptions.from_http_response(response)
3245
3246 # Return the response
3247 resp = iam_policy_pb2.TestIamPermissionsResponse()
3248 pb_resp = resp
3249
3250 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
3251
3252 resp = self._interceptor.post_test_iam_permissions(resp)
3253 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
3254 resp, _ = self._interceptor.post_test_iam_permissions_with_metadata(
3255 resp, response_metadata
3256 )
3257 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3258 logging.DEBUG
3259 ): # pragma: NO COVER
3260 try:
3261 response_payload = json_format.MessageToJson(resp)
3262 except:
3263 response_payload = None
3264 http_response = {
3265 "payload": response_payload,
3266 "headers": dict(response.headers),
3267 "status": response.status_code,
3268 }
3269 _LOGGER.debug(
3270 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.test_iam_permissions",
3271 extra={
3272 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3273 "rpcName": "TestIamPermissions",
3274 "metadata": http_response["headers"],
3275 "httpResponse": http_response,
3276 },
3277 )
3278 return resp
3279
3280 class _UpdateSecret(
3281 _BaseSecretManagerServiceRestTransport._BaseUpdateSecret,
3282 SecretManagerServiceRestStub,
3283 ):
3284 def __hash__(self):
3285 return hash("SecretManagerServiceRestTransport.UpdateSecret")
3286
3287 @staticmethod
3288 def _get_response(
3289 host,
3290 metadata,
3291 query_params,
3292 session,
3293 timeout,
3294 transcoded_request,
3295 body=None,
3296 ):
3297 uri = transcoded_request["uri"]
3298 method = transcoded_request["method"]
3299 headers = dict(metadata)
3300 headers["Content-Type"] = "application/json"
3301 response = getattr(session, method)(
3302 "{host}{uri}".format(host=host, uri=uri),
3303 timeout=timeout,
3304 headers=headers,
3305 params=rest_helpers.flatten_query_params(query_params, strict=True),
3306 data=body,
3307 )
3308 return response
3309
3310 def __call__(
3311 self,
3312 request: service.UpdateSecretRequest,
3313 *,
3314 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3315 timeout: Optional[float] = None,
3316 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3317 ) -> resources.Secret:
3318 r"""Call the update secret method over HTTP.
3319
3320 Args:
3321 request (~.service.UpdateSecretRequest):
3322 The request object. Request message for
3323 [SecretManagerService.UpdateSecret][google.cloud.secrets.v1beta1.SecretManagerService.UpdateSecret].
3324 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3325 should be retried.
3326 timeout (float): The timeout for this request.
3327 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3328 sent along with the request as metadata. Normally, each value must be of type `str`,
3329 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3330 be of type `bytes`.
3331
3332 Returns:
3333 ~.resources.Secret:
3334 A [Secret][google.cloud.secrets.v1beta1.Secret] is a
3335 logical secret whose value and versions can be accessed.
3336
3337 A [Secret][google.cloud.secrets.v1beta1.Secret] is made
3338 up of zero or more
3339 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]
3340 that represent the secret data.
3341
3342 """
3343
3344 http_options = (
3345 _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_http_options()
3346 )
3347
3348 request, metadata = self._interceptor.pre_update_secret(request, metadata)
3349 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_transcoded_request(
3350 http_options, request
3351 )
3352
3353 body = _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_request_body_json(
3354 transcoded_request
3355 )
3356
3357 # Jsonify the query params
3358 query_params = _BaseSecretManagerServiceRestTransport._BaseUpdateSecret._get_query_params_json(
3359 transcoded_request
3360 )
3361
3362 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3363 logging.DEBUG
3364 ): # pragma: NO COVER
3365 request_url = "{host}{uri}".format(
3366 host=self._host, uri=transcoded_request["uri"]
3367 )
3368 method = transcoded_request["method"]
3369 try:
3370 request_payload = type(request).to_json(request)
3371 except:
3372 request_payload = None
3373 http_request = {
3374 "payload": request_payload,
3375 "requestMethod": method,
3376 "requestUrl": request_url,
3377 "headers": dict(metadata),
3378 }
3379 _LOGGER.debug(
3380 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.UpdateSecret",
3381 extra={
3382 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3383 "rpcName": "UpdateSecret",
3384 "httpRequest": http_request,
3385 "metadata": http_request["headers"],
3386 },
3387 )
3388
3389 # Send the request
3390 response = SecretManagerServiceRestTransport._UpdateSecret._get_response(
3391 self._host,
3392 metadata,
3393 query_params,
3394 self._session,
3395 timeout,
3396 transcoded_request,
3397 body,
3398 )
3399
3400 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3401 # subclass.
3402 if response.status_code >= 400:
3403 raise core_exceptions.from_http_response(response)
3404
3405 # Return the response
3406 resp = resources.Secret()
3407 pb_resp = resources.Secret.pb(resp)
3408
3409 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
3410
3411 resp = self._interceptor.post_update_secret(resp)
3412 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
3413 resp, _ = self._interceptor.post_update_secret_with_metadata(
3414 resp, response_metadata
3415 )
3416 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3417 logging.DEBUG
3418 ): # pragma: NO COVER
3419 try:
3420 response_payload = resources.Secret.to_json(response)
3421 except:
3422 response_payload = None
3423 http_response = {
3424 "payload": response_payload,
3425 "headers": dict(response.headers),
3426 "status": response.status_code,
3427 }
3428 _LOGGER.debug(
3429 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceClient.update_secret",
3430 extra={
3431 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3432 "rpcName": "UpdateSecret",
3433 "metadata": http_response["headers"],
3434 "httpResponse": http_response,
3435 },
3436 )
3437 return resp
3438
3439 @property
3440 def access_secret_version(
3441 self,
3442 ) -> Callable[
3443 [service.AccessSecretVersionRequest], service.AccessSecretVersionResponse
3444 ]:
3445 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3446 # In C++ this would require a dynamic_cast
3447 return self._AccessSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3448
3449 @property
3450 def add_secret_version(
3451 self,
3452 ) -> Callable[[service.AddSecretVersionRequest], resources.SecretVersion]:
3453 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3454 # In C++ this would require a dynamic_cast
3455 return self._AddSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3456
3457 @property
3458 def create_secret(
3459 self,
3460 ) -> Callable[[service.CreateSecretRequest], resources.Secret]:
3461 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3462 # In C++ this would require a dynamic_cast
3463 return self._CreateSecret(self._session, self._host, self._interceptor) # type: ignore
3464
3465 @property
3466 def delete_secret(self) -> Callable[[service.DeleteSecretRequest], empty_pb2.Empty]:
3467 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3468 # In C++ this would require a dynamic_cast
3469 return self._DeleteSecret(self._session, self._host, self._interceptor) # type: ignore
3470
3471 @property
3472 def destroy_secret_version(
3473 self,
3474 ) -> Callable[[service.DestroySecretVersionRequest], resources.SecretVersion]:
3475 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3476 # In C++ this would require a dynamic_cast
3477 return self._DestroySecretVersion(self._session, self._host, self._interceptor) # type: ignore
3478
3479 @property
3480 def disable_secret_version(
3481 self,
3482 ) -> Callable[[service.DisableSecretVersionRequest], resources.SecretVersion]:
3483 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3484 # In C++ this would require a dynamic_cast
3485 return self._DisableSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3486
3487 @property
3488 def enable_secret_version(
3489 self,
3490 ) -> Callable[[service.EnableSecretVersionRequest], resources.SecretVersion]:
3491 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3492 # In C++ this would require a dynamic_cast
3493 return self._EnableSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3494
3495 @property
3496 def get_iam_policy(
3497 self,
3498 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]:
3499 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3500 # In C++ this would require a dynamic_cast
3501 return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore
3502
3503 @property
3504 def get_secret(self) -> Callable[[service.GetSecretRequest], resources.Secret]:
3505 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3506 # In C++ this would require a dynamic_cast
3507 return self._GetSecret(self._session, self._host, self._interceptor) # type: ignore
3508
3509 @property
3510 def get_secret_version(
3511 self,
3512 ) -> Callable[[service.GetSecretVersionRequest], resources.SecretVersion]:
3513 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3514 # In C++ this would require a dynamic_cast
3515 return self._GetSecretVersion(self._session, self._host, self._interceptor) # type: ignore
3516
3517 @property
3518 def list_secrets(
3519 self,
3520 ) -> Callable[[service.ListSecretsRequest], service.ListSecretsResponse]:
3521 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3522 # In C++ this would require a dynamic_cast
3523 return self._ListSecrets(self._session, self._host, self._interceptor) # type: ignore
3524
3525 @property
3526 def list_secret_versions(
3527 self,
3528 ) -> Callable[
3529 [service.ListSecretVersionsRequest], service.ListSecretVersionsResponse
3530 ]:
3531 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3532 # In C++ this would require a dynamic_cast
3533 return self._ListSecretVersions(self._session, self._host, self._interceptor) # type: ignore
3534
3535 @property
3536 def set_iam_policy(
3537 self,
3538 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]:
3539 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3540 # In C++ this would require a dynamic_cast
3541 return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore
3542
3543 @property
3544 def test_iam_permissions(
3545 self,
3546 ) -> Callable[
3547 [iam_policy_pb2.TestIamPermissionsRequest],
3548 iam_policy_pb2.TestIamPermissionsResponse,
3549 ]:
3550 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3551 # In C++ this would require a dynamic_cast
3552 return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore
3553
3554 @property
3555 def update_secret(
3556 self,
3557 ) -> Callable[[service.UpdateSecretRequest], resources.Secret]:
3558 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
3559 # In C++ this would require a dynamic_cast
3560 return self._UpdateSecret(self._session, self._host, self._interceptor) # type: ignore
3561
3562 @property
3563 def get_location(self):
3564 return self._GetLocation(self._session, self._host, self._interceptor) # type: ignore
3565
3566 class _GetLocation(
3567 _BaseSecretManagerServiceRestTransport._BaseGetLocation,
3568 SecretManagerServiceRestStub,
3569 ):
3570 def __hash__(self):
3571 return hash("SecretManagerServiceRestTransport.GetLocation")
3572
3573 @staticmethod
3574 def _get_response(
3575 host,
3576 metadata,
3577 query_params,
3578 session,
3579 timeout,
3580 transcoded_request,
3581 body=None,
3582 ):
3583 uri = transcoded_request["uri"]
3584 method = transcoded_request["method"]
3585 headers = dict(metadata)
3586 headers["Content-Type"] = "application/json"
3587 response = getattr(session, method)(
3588 "{host}{uri}".format(host=host, uri=uri),
3589 timeout=timeout,
3590 headers=headers,
3591 params=rest_helpers.flatten_query_params(query_params, strict=True),
3592 )
3593 return response
3594
3595 def __call__(
3596 self,
3597 request: locations_pb2.GetLocationRequest,
3598 *,
3599 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3600 timeout: Optional[float] = None,
3601 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3602 ) -> locations_pb2.Location:
3603 r"""Call the get location method over HTTP.
3604
3605 Args:
3606 request (locations_pb2.GetLocationRequest):
3607 The request object for GetLocation method.
3608 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3609 should be retried.
3610 timeout (float): The timeout for this request.
3611 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3612 sent along with the request as metadata. Normally, each value must be of type `str`,
3613 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3614 be of type `bytes`.
3615
3616 Returns:
3617 locations_pb2.Location: Response from GetLocation method.
3618 """
3619
3620 http_options = (
3621 _BaseSecretManagerServiceRestTransport._BaseGetLocation._get_http_options()
3622 )
3623
3624 request, metadata = self._interceptor.pre_get_location(request, metadata)
3625 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseGetLocation._get_transcoded_request(
3626 http_options, request
3627 )
3628
3629 # Jsonify the query params
3630 query_params = _BaseSecretManagerServiceRestTransport._BaseGetLocation._get_query_params_json(
3631 transcoded_request
3632 )
3633
3634 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3635 logging.DEBUG
3636 ): # pragma: NO COVER
3637 request_url = "{host}{uri}".format(
3638 host=self._host, uri=transcoded_request["uri"]
3639 )
3640 method = transcoded_request["method"]
3641 try:
3642 request_payload = json_format.MessageToJson(request)
3643 except:
3644 request_payload = None
3645 http_request = {
3646 "payload": request_payload,
3647 "requestMethod": method,
3648 "requestUrl": request_url,
3649 "headers": dict(metadata),
3650 }
3651 _LOGGER.debug(
3652 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.GetLocation",
3653 extra={
3654 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3655 "rpcName": "GetLocation",
3656 "httpRequest": http_request,
3657 "metadata": http_request["headers"],
3658 },
3659 )
3660
3661 # Send the request
3662 response = SecretManagerServiceRestTransport._GetLocation._get_response(
3663 self._host,
3664 metadata,
3665 query_params,
3666 self._session,
3667 timeout,
3668 transcoded_request,
3669 )
3670
3671 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3672 # subclass.
3673 if response.status_code >= 400:
3674 raise core_exceptions.from_http_response(response)
3675
3676 content = response.content.decode("utf-8")
3677 resp = locations_pb2.Location()
3678 resp = json_format.Parse(content, resp)
3679 resp = self._interceptor.post_get_location(resp)
3680 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3681 logging.DEBUG
3682 ): # pragma: NO COVER
3683 try:
3684 response_payload = json_format.MessageToJson(resp)
3685 except:
3686 response_payload = None
3687 http_response = {
3688 "payload": response_payload,
3689 "headers": dict(response.headers),
3690 "status": response.status_code,
3691 }
3692 _LOGGER.debug(
3693 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceAsyncClient.GetLocation",
3694 extra={
3695 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3696 "rpcName": "GetLocation",
3697 "httpResponse": http_response,
3698 "metadata": http_response["headers"],
3699 },
3700 )
3701 return resp
3702
3703 @property
3704 def list_locations(self):
3705 return self._ListLocations(self._session, self._host, self._interceptor) # type: ignore
3706
3707 class _ListLocations(
3708 _BaseSecretManagerServiceRestTransport._BaseListLocations,
3709 SecretManagerServiceRestStub,
3710 ):
3711 def __hash__(self):
3712 return hash("SecretManagerServiceRestTransport.ListLocations")
3713
3714 @staticmethod
3715 def _get_response(
3716 host,
3717 metadata,
3718 query_params,
3719 session,
3720 timeout,
3721 transcoded_request,
3722 body=None,
3723 ):
3724 uri = transcoded_request["uri"]
3725 method = transcoded_request["method"]
3726 headers = dict(metadata)
3727 headers["Content-Type"] = "application/json"
3728 response = getattr(session, method)(
3729 "{host}{uri}".format(host=host, uri=uri),
3730 timeout=timeout,
3731 headers=headers,
3732 params=rest_helpers.flatten_query_params(query_params, strict=True),
3733 )
3734 return response
3735
3736 def __call__(
3737 self,
3738 request: locations_pb2.ListLocationsRequest,
3739 *,
3740 retry: OptionalRetry = gapic_v1.method.DEFAULT,
3741 timeout: Optional[float] = None,
3742 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3743 ) -> locations_pb2.ListLocationsResponse:
3744 r"""Call the list locations method over HTTP.
3745
3746 Args:
3747 request (locations_pb2.ListLocationsRequest):
3748 The request object for ListLocations method.
3749 retry (google.api_core.retry.Retry): Designation of what errors, if any,
3750 should be retried.
3751 timeout (float): The timeout for this request.
3752 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3753 sent along with the request as metadata. Normally, each value must be of type `str`,
3754 but for metadata keys ending with the suffix `-bin`, the corresponding values must
3755 be of type `bytes`.
3756
3757 Returns:
3758 locations_pb2.ListLocationsResponse: Response from ListLocations method.
3759 """
3760
3761 http_options = (
3762 _BaseSecretManagerServiceRestTransport._BaseListLocations._get_http_options()
3763 )
3764
3765 request, metadata = self._interceptor.pre_list_locations(request, metadata)
3766 transcoded_request = _BaseSecretManagerServiceRestTransport._BaseListLocations._get_transcoded_request(
3767 http_options, request
3768 )
3769
3770 # Jsonify the query params
3771 query_params = _BaseSecretManagerServiceRestTransport._BaseListLocations._get_query_params_json(
3772 transcoded_request
3773 )
3774
3775 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3776 logging.DEBUG
3777 ): # pragma: NO COVER
3778 request_url = "{host}{uri}".format(
3779 host=self._host, uri=transcoded_request["uri"]
3780 )
3781 method = transcoded_request["method"]
3782 try:
3783 request_payload = json_format.MessageToJson(request)
3784 except:
3785 request_payload = None
3786 http_request = {
3787 "payload": request_payload,
3788 "requestMethod": method,
3789 "requestUrl": request_url,
3790 "headers": dict(metadata),
3791 }
3792 _LOGGER.debug(
3793 f"Sending request for google.cloud.secrets_v1beta1.SecretManagerServiceClient.ListLocations",
3794 extra={
3795 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3796 "rpcName": "ListLocations",
3797 "httpRequest": http_request,
3798 "metadata": http_request["headers"],
3799 },
3800 )
3801
3802 # Send the request
3803 response = SecretManagerServiceRestTransport._ListLocations._get_response(
3804 self._host,
3805 metadata,
3806 query_params,
3807 self._session,
3808 timeout,
3809 transcoded_request,
3810 )
3811
3812 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
3813 # subclass.
3814 if response.status_code >= 400:
3815 raise core_exceptions.from_http_response(response)
3816
3817 content = response.content.decode("utf-8")
3818 resp = locations_pb2.ListLocationsResponse()
3819 resp = json_format.Parse(content, resp)
3820 resp = self._interceptor.post_list_locations(resp)
3821 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
3822 logging.DEBUG
3823 ): # pragma: NO COVER
3824 try:
3825 response_payload = json_format.MessageToJson(resp)
3826 except:
3827 response_payload = None
3828 http_response = {
3829 "payload": response_payload,
3830 "headers": dict(response.headers),
3831 "status": response.status_code,
3832 }
3833 _LOGGER.debug(
3834 "Received response for google.cloud.secrets_v1beta1.SecretManagerServiceAsyncClient.ListLocations",
3835 extra={
3836 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService",
3837 "rpcName": "ListLocations",
3838 "httpResponse": http_response,
3839 "metadata": http_response["headers"],
3840 },
3841 )
3842 return resp
3843
3844 @property
3845 def kind(self) -> str:
3846 return "rest"
3847
3848 def close(self):
3849 self._session.close()
3850
3851
3852__all__ = ("SecretManagerServiceRestTransport",)