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