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