Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/secretmanager_v1beta1/services/secret_manager_service/async_client.py: 29%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

265 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2024 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16from collections import OrderedDict 

17import functools 

18import re 

19from typing import ( 

20 Callable, 

21 Dict, 

22 Mapping, 

23 MutableMapping, 

24 MutableSequence, 

25 Optional, 

26 Sequence, 

27 Tuple, 

28 Type, 

29 Union, 

30) 

31 

32from google.api_core import exceptions as core_exceptions 

33from google.api_core import gapic_v1 

34from google.api_core import retry_async as retries 

35from google.api_core.client_options import ClientOptions 

36from google.auth import credentials as ga_credentials # type: ignore 

37from google.oauth2 import service_account # type: ignore 

38 

39from google.cloud.secretmanager_v1beta1 import gapic_version as package_version 

40 

41try: 

42 OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] 

43except AttributeError: # pragma: NO COVER 

44 OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore 

45 

46from google.iam.v1 import iam_policy_pb2 # type: ignore 

47from google.iam.v1 import policy_pb2 # type: ignore 

48from google.protobuf import field_mask_pb2 # type: ignore 

49from google.protobuf import timestamp_pb2 # type: ignore 

50 

51from google.cloud.secretmanager_v1beta1.services.secret_manager_service import pagers 

52from google.cloud.secretmanager_v1beta1.types import resources, service 

53 

54from .client import SecretManagerServiceClient 

55from .transports.base import DEFAULT_CLIENT_INFO, SecretManagerServiceTransport 

56from .transports.grpc_asyncio import SecretManagerServiceGrpcAsyncIOTransport 

57 

58 

59class SecretManagerServiceAsyncClient: 

60 """Secret Manager Service 

61 

62 Manages secrets and operations using those secrets. Implements a 

63 REST model with the following objects: 

64 

65 - [Secret][google.cloud.secrets.v1beta1.Secret] 

66 - [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

67 """ 

68 

69 _client: SecretManagerServiceClient 

70 

71 # Copy defaults from the synchronous client for use here. 

72 # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. 

73 DEFAULT_ENDPOINT = SecretManagerServiceClient.DEFAULT_ENDPOINT 

74 DEFAULT_MTLS_ENDPOINT = SecretManagerServiceClient.DEFAULT_MTLS_ENDPOINT 

75 _DEFAULT_ENDPOINT_TEMPLATE = SecretManagerServiceClient._DEFAULT_ENDPOINT_TEMPLATE 

76 _DEFAULT_UNIVERSE = SecretManagerServiceClient._DEFAULT_UNIVERSE 

77 

78 secret_path = staticmethod(SecretManagerServiceClient.secret_path) 

79 parse_secret_path = staticmethod(SecretManagerServiceClient.parse_secret_path) 

80 secret_version_path = staticmethod(SecretManagerServiceClient.secret_version_path) 

81 parse_secret_version_path = staticmethod( 

82 SecretManagerServiceClient.parse_secret_version_path 

83 ) 

84 common_billing_account_path = staticmethod( 

85 SecretManagerServiceClient.common_billing_account_path 

86 ) 

87 parse_common_billing_account_path = staticmethod( 

88 SecretManagerServiceClient.parse_common_billing_account_path 

89 ) 

90 common_folder_path = staticmethod(SecretManagerServiceClient.common_folder_path) 

91 parse_common_folder_path = staticmethod( 

92 SecretManagerServiceClient.parse_common_folder_path 

93 ) 

94 common_organization_path = staticmethod( 

95 SecretManagerServiceClient.common_organization_path 

96 ) 

97 parse_common_organization_path = staticmethod( 

98 SecretManagerServiceClient.parse_common_organization_path 

99 ) 

100 common_project_path = staticmethod(SecretManagerServiceClient.common_project_path) 

101 parse_common_project_path = staticmethod( 

102 SecretManagerServiceClient.parse_common_project_path 

103 ) 

104 common_location_path = staticmethod(SecretManagerServiceClient.common_location_path) 

105 parse_common_location_path = staticmethod( 

106 SecretManagerServiceClient.parse_common_location_path 

107 ) 

108 

109 @classmethod 

110 def from_service_account_info(cls, info: dict, *args, **kwargs): 

111 """Creates an instance of this client using the provided credentials 

112 info. 

113 

114 Args: 

115 info (dict): The service account private key info. 

116 args: Additional arguments to pass to the constructor. 

117 kwargs: Additional arguments to pass to the constructor. 

118 

119 Returns: 

120 SecretManagerServiceAsyncClient: The constructed client. 

121 """ 

122 return SecretManagerServiceClient.from_service_account_info.__func__(SecretManagerServiceAsyncClient, info, *args, **kwargs) # type: ignore 

123 

124 @classmethod 

125 def from_service_account_file(cls, filename: str, *args, **kwargs): 

126 """Creates an instance of this client using the provided credentials 

127 file. 

128 

129 Args: 

130 filename (str): The path to the service account private key json 

131 file. 

132 args: Additional arguments to pass to the constructor. 

133 kwargs: Additional arguments to pass to the constructor. 

134 

135 Returns: 

136 SecretManagerServiceAsyncClient: The constructed client. 

137 """ 

138 return SecretManagerServiceClient.from_service_account_file.__func__(SecretManagerServiceAsyncClient, filename, *args, **kwargs) # type: ignore 

139 

140 from_service_account_json = from_service_account_file 

141 

142 @classmethod 

143 def get_mtls_endpoint_and_cert_source( 

144 cls, client_options: Optional[ClientOptions] = None 

145 ): 

146 """Return the API endpoint and client cert source for mutual TLS. 

147 

148 The client cert source is determined in the following order: 

149 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the 

150 client cert source is None. 

151 (2) if `client_options.client_cert_source` is provided, use the provided one; if the 

152 default client cert source exists, use the default one; otherwise the client cert 

153 source is None. 

154 

155 The API endpoint is determined in the following order: 

156 (1) if `client_options.api_endpoint` if provided, use the provided one. 

157 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the 

158 default mTLS endpoint; if the environment variable is "never", use the default API 

159 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise 

160 use the default API endpoint. 

161 

162 More details can be found at https://google.aip.dev/auth/4114. 

163 

164 Args: 

165 client_options (google.api_core.client_options.ClientOptions): Custom options for the 

166 client. Only the `api_endpoint` and `client_cert_source` properties may be used 

167 in this method. 

168 

169 Returns: 

170 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the 

171 client cert source to use. 

172 

173 Raises: 

174 google.auth.exceptions.MutualTLSChannelError: If any errors happen. 

175 """ 

176 return SecretManagerServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

177 

178 @property 

179 def transport(self) -> SecretManagerServiceTransport: 

180 """Returns the transport used by the client instance. 

181 

182 Returns: 

183 SecretManagerServiceTransport: The transport used by the client instance. 

184 """ 

185 return self._client.transport 

186 

187 @property 

188 def api_endpoint(self): 

189 """Return the API endpoint used by the client instance. 

190 

191 Returns: 

192 str: The API endpoint used by the client instance. 

193 """ 

194 return self._client._api_endpoint 

195 

196 @property 

197 def universe_domain(self) -> str: 

198 """Return the universe domain used by the client instance. 

199 

200 Returns: 

201 str: The universe domain used 

202 by the client instance. 

203 """ 

204 return self._client._universe_domain 

205 

206 get_transport_class = functools.partial( 

207 type(SecretManagerServiceClient).get_transport_class, 

208 type(SecretManagerServiceClient), 

209 ) 

210 

211 def __init__( 

212 self, 

213 *, 

214 credentials: Optional[ga_credentials.Credentials] = None, 

215 transport: Optional[ 

216 Union[ 

217 str, 

218 SecretManagerServiceTransport, 

219 Callable[..., SecretManagerServiceTransport], 

220 ] 

221 ] = "grpc_asyncio", 

222 client_options: Optional[ClientOptions] = None, 

223 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

224 ) -> None: 

225 """Instantiates the secret manager service async client. 

226 

227 Args: 

228 credentials (Optional[google.auth.credentials.Credentials]): The 

229 authorization credentials to attach to requests. These 

230 credentials identify the application to the service; if none 

231 are specified, the client will attempt to ascertain the 

232 credentials from the environment. 

233 transport (Optional[Union[str,SecretManagerServiceTransport,Callable[..., SecretManagerServiceTransport]]]): 

234 The transport to use, or a Callable that constructs and returns a new transport to use. 

235 If a Callable is given, it will be called with the same set of initialization 

236 arguments as used in the SecretManagerServiceTransport constructor. 

237 If set to None, a transport is chosen automatically. 

238 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): 

239 Custom options for the client. 

240 

241 1. The ``api_endpoint`` property can be used to override the 

242 default endpoint provided by the client when ``transport`` is 

243 not explicitly provided. Only if this property is not set and 

244 ``transport`` was not explicitly provided, the endpoint is 

245 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment 

246 variable, which have one of the following values: 

247 "always" (always use the default mTLS endpoint), "never" (always 

248 use the default regular endpoint) and "auto" (auto-switch to the 

249 default mTLS endpoint if client certificate is present; this is 

250 the default value). 

251 

252 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

253 is "true", then the ``client_cert_source`` property can be used 

254 to provide a client certificate for mTLS transport. If 

255 not provided, the default SSL client certificate will be used if 

256 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

257 set, no client certificate will be used. 

258 

259 3. The ``universe_domain`` property can be used to override the 

260 default "googleapis.com" universe. Note that ``api_endpoint`` 

261 property still takes precedence; and ``universe_domain`` is 

262 currently not supported for mTLS. 

263 

264 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

265 The client info used to send a user-agent string along with 

266 API requests. If ``None``, then default info will be used. 

267 Generally, you only need to set this if you're developing 

268 your own client library. 

269 

270 Raises: 

271 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 

272 creation failed for any reason. 

273 """ 

274 self._client = SecretManagerServiceClient( 

275 credentials=credentials, 

276 transport=transport, 

277 client_options=client_options, 

278 client_info=client_info, 

279 ) 

280 

281 async def list_secrets( 

282 self, 

283 request: Optional[Union[service.ListSecretsRequest, dict]] = None, 

284 *, 

285 parent: Optional[str] = None, 

286 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

287 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

288 metadata: Sequence[Tuple[str, str]] = (), 

289 ) -> pagers.ListSecretsAsyncPager: 

290 r"""Lists [Secrets][google.cloud.secrets.v1beta1.Secret]. 

291 

292 .. code-block:: python 

293 

294 # This snippet has been automatically generated and should be regarded as a 

295 # code template only. 

296 # It will require modifications to work: 

297 # - It may require correct/in-range values for request initialization. 

298 # - It may require specifying regional endpoints when creating the service 

299 # client as shown in: 

300 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

301 from google.cloud import secretmanager_v1beta1 

302 

303 async def sample_list_secrets(): 

304 # Create a client 

305 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

306 

307 # Initialize request argument(s) 

308 request = secretmanager_v1beta1.ListSecretsRequest( 

309 parent="parent_value", 

310 ) 

311 

312 # Make the request 

313 page_result = client.list_secrets(request=request) 

314 

315 # Handle the response 

316 async for response in page_result: 

317 print(response) 

318 

319 Args: 

320 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.ListSecretsRequest, dict]]): 

321 The request object. Request message for 

322 [SecretManagerService.ListSecrets][google.cloud.secrets.v1beta1.SecretManagerService.ListSecrets]. 

323 parent (:class:`str`): 

324 Required. The resource name of the project associated 

325 with the [Secrets][google.cloud.secrets.v1beta1.Secret], 

326 in the format ``projects/*``. 

327 

328 This corresponds to the ``parent`` field 

329 on the ``request`` instance; if ``request`` is provided, this 

330 should not be set. 

331 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

332 should be retried. 

333 timeout (float): The timeout for this request. 

334 metadata (Sequence[Tuple[str, str]]): Strings which should be 

335 sent along with the request as metadata. 

336 

337 Returns: 

338 google.cloud.secretmanager_v1beta1.services.secret_manager_service.pagers.ListSecretsAsyncPager: 

339 Response message for 

340 [SecretManagerService.ListSecrets][google.cloud.secrets.v1beta1.SecretManagerService.ListSecrets]. 

341 

342 Iterating over this object will yield results and 

343 resolve additional pages automatically. 

344 

345 """ 

346 # Create or coerce a protobuf request object. 

347 # - Quick check: If we got a request object, we should *not* have 

348 # gotten any keyword arguments that map to the request. 

349 has_flattened_params = any([parent]) 

350 if request is not None and has_flattened_params: 

351 raise ValueError( 

352 "If the `request` argument is set, then none of " 

353 "the individual field arguments should be set." 

354 ) 

355 

356 # - Use the request object if provided (there's no risk of modifying the input as 

357 # there are no flattened fields), or create one. 

358 if not isinstance(request, service.ListSecretsRequest): 

359 request = service.ListSecretsRequest(request) 

360 

361 # If we have keyword arguments corresponding to fields on the 

362 # request, apply these. 

363 if parent is not None: 

364 request.parent = parent 

365 

366 # Wrap the RPC method; this adds retry and timeout information, 

367 # and friendly error handling. 

368 rpc = self._client._transport._wrapped_methods[ 

369 self._client._transport.list_secrets 

370 ] 

371 

372 # Certain fields should be provided within the metadata header; 

373 # add these here. 

374 metadata = tuple(metadata) + ( 

375 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

376 ) 

377 

378 # Validate the universe domain. 

379 self._client._validate_universe_domain() 

380 

381 # Send the request. 

382 response = await rpc( 

383 request, 

384 retry=retry, 

385 timeout=timeout, 

386 metadata=metadata, 

387 ) 

388 

389 # This method is paged; wrap the response in a pager, which provides 

390 # an `__aiter__` convenience method. 

391 response = pagers.ListSecretsAsyncPager( 

392 method=rpc, 

393 request=request, 

394 response=response, 

395 metadata=metadata, 

396 ) 

397 

398 # Done; return the response. 

399 return response 

400 

401 async def create_secret( 

402 self, 

403 request: Optional[Union[service.CreateSecretRequest, dict]] = None, 

404 *, 

405 parent: Optional[str] = None, 

406 secret_id: Optional[str] = None, 

407 secret: Optional[resources.Secret] = None, 

408 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

409 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

410 metadata: Sequence[Tuple[str, str]] = (), 

411 ) -> resources.Secret: 

412 r"""Creates a new [Secret][google.cloud.secrets.v1beta1.Secret] 

413 containing no 

414 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]. 

415 

416 .. code-block:: python 

417 

418 # This snippet has been automatically generated and should be regarded as a 

419 # code template only. 

420 # It will require modifications to work: 

421 # - It may require correct/in-range values for request initialization. 

422 # - It may require specifying regional endpoints when creating the service 

423 # client as shown in: 

424 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

425 from google.cloud import secretmanager_v1beta1 

426 

427 async def sample_create_secret(): 

428 # Create a client 

429 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

430 

431 # Initialize request argument(s) 

432 request = secretmanager_v1beta1.CreateSecretRequest( 

433 parent="parent_value", 

434 secret_id="secret_id_value", 

435 ) 

436 

437 # Make the request 

438 response = await client.create_secret(request=request) 

439 

440 # Handle the response 

441 print(response) 

442 

443 Args: 

444 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.CreateSecretRequest, dict]]): 

445 The request object. Request message for 

446 [SecretManagerService.CreateSecret][google.cloud.secrets.v1beta1.SecretManagerService.CreateSecret]. 

447 parent (:class:`str`): 

448 Required. The resource name of the project to associate 

449 with the [Secret][google.cloud.secrets.v1beta1.Secret], 

450 in the format ``projects/*``. 

451 

452 This corresponds to the ``parent`` field 

453 on the ``request`` instance; if ``request`` is provided, this 

454 should not be set. 

455 secret_id (:class:`str`): 

456 Required. This must be unique within the project. 

457 

458 A secret ID is a string with a maximum length of 255 

459 characters and can contain uppercase and lowercase 

460 letters, numerals, and the hyphen (``-``) and underscore 

461 (``_``) characters. 

462 

463 This corresponds to the ``secret_id`` field 

464 on the ``request`` instance; if ``request`` is provided, this 

465 should not be set. 

466 secret (:class:`google.cloud.secretmanager_v1beta1.types.Secret`): 

467 Required. A 

468 [Secret][google.cloud.secrets.v1beta1.Secret] with 

469 initial field values. 

470 

471 This corresponds to the ``secret`` field 

472 on the ``request`` instance; if ``request`` is provided, this 

473 should not be set. 

474 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

475 should be retried. 

476 timeout (float): The timeout for this request. 

477 metadata (Sequence[Tuple[str, str]]): Strings which should be 

478 sent along with the request as metadata. 

479 

480 Returns: 

481 google.cloud.secretmanager_v1beta1.types.Secret: 

482 A [Secret][google.cloud.secrets.v1beta1.Secret] is a logical secret whose value and versions can 

483 be accessed. 

484 

485 A [Secret][google.cloud.secrets.v1beta1.Secret] is 

486 made up of zero or more 

487 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] 

488 that represent the secret data. 

489 

490 """ 

491 # Create or coerce a protobuf request object. 

492 # - Quick check: If we got a request object, we should *not* have 

493 # gotten any keyword arguments that map to the request. 

494 has_flattened_params = any([parent, secret_id, secret]) 

495 if request is not None and has_flattened_params: 

496 raise ValueError( 

497 "If the `request` argument is set, then none of " 

498 "the individual field arguments should be set." 

499 ) 

500 

501 # - Use the request object if provided (there's no risk of modifying the input as 

502 # there are no flattened fields), or create one. 

503 if not isinstance(request, service.CreateSecretRequest): 

504 request = service.CreateSecretRequest(request) 

505 

506 # If we have keyword arguments corresponding to fields on the 

507 # request, apply these. 

508 if parent is not None: 

509 request.parent = parent 

510 if secret_id is not None: 

511 request.secret_id = secret_id 

512 if secret is not None: 

513 request.secret = secret 

514 

515 # Wrap the RPC method; this adds retry and timeout information, 

516 # and friendly error handling. 

517 rpc = self._client._transport._wrapped_methods[ 

518 self._client._transport.create_secret 

519 ] 

520 

521 # Certain fields should be provided within the metadata header; 

522 # add these here. 

523 metadata = tuple(metadata) + ( 

524 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

525 ) 

526 

527 # Validate the universe domain. 

528 self._client._validate_universe_domain() 

529 

530 # Send the request. 

531 response = await rpc( 

532 request, 

533 retry=retry, 

534 timeout=timeout, 

535 metadata=metadata, 

536 ) 

537 

538 # Done; return the response. 

539 return response 

540 

541 async def add_secret_version( 

542 self, 

543 request: Optional[Union[service.AddSecretVersionRequest, dict]] = None, 

544 *, 

545 parent: Optional[str] = None, 

546 payload: Optional[resources.SecretPayload] = None, 

547 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

548 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

549 metadata: Sequence[Tuple[str, str]] = (), 

550 ) -> resources.SecretVersion: 

551 r"""Creates a new 

552 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

553 containing secret data and attaches it to an existing 

554 [Secret][google.cloud.secrets.v1beta1.Secret]. 

555 

556 .. code-block:: python 

557 

558 # This snippet has been automatically generated and should be regarded as a 

559 # code template only. 

560 # It will require modifications to work: 

561 # - It may require correct/in-range values for request initialization. 

562 # - It may require specifying regional endpoints when creating the service 

563 # client as shown in: 

564 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

565 from google.cloud import secretmanager_v1beta1 

566 

567 async def sample_add_secret_version(): 

568 # Create a client 

569 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

570 

571 # Initialize request argument(s) 

572 request = secretmanager_v1beta1.AddSecretVersionRequest( 

573 parent="parent_value", 

574 ) 

575 

576 # Make the request 

577 response = await client.add_secret_version(request=request) 

578 

579 # Handle the response 

580 print(response) 

581 

582 Args: 

583 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.AddSecretVersionRequest, dict]]): 

584 The request object. Request message for 

585 [SecretManagerService.AddSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AddSecretVersion]. 

586 parent (:class:`str`): 

587 Required. The resource name of the 

588 [Secret][google.cloud.secrets.v1beta1.Secret] to 

589 associate with the 

590 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

591 in the format ``projects/*/secrets/*``. 

592 

593 This corresponds to the ``parent`` field 

594 on the ``request`` instance; if ``request`` is provided, this 

595 should not be set. 

596 payload (:class:`google.cloud.secretmanager_v1beta1.types.SecretPayload`): 

597 Required. The secret payload of the 

598 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

599 

600 This corresponds to the ``payload`` field 

601 on the ``request`` instance; if ``request`` is provided, this 

602 should not be set. 

603 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

604 should be retried. 

605 timeout (float): The timeout for this request. 

606 metadata (Sequence[Tuple[str, str]]): Strings which should be 

607 sent along with the request as metadata. 

608 

609 Returns: 

610 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

611 A secret version resource in the 

612 Secret Manager API. 

613 

614 """ 

615 # Create or coerce a protobuf request object. 

616 # - Quick check: If we got a request object, we should *not* have 

617 # gotten any keyword arguments that map to the request. 

618 has_flattened_params = any([parent, payload]) 

619 if request is not None and has_flattened_params: 

620 raise ValueError( 

621 "If the `request` argument is set, then none of " 

622 "the individual field arguments should be set." 

623 ) 

624 

625 # - Use the request object if provided (there's no risk of modifying the input as 

626 # there are no flattened fields), or create one. 

627 if not isinstance(request, service.AddSecretVersionRequest): 

628 request = service.AddSecretVersionRequest(request) 

629 

630 # If we have keyword arguments corresponding to fields on the 

631 # request, apply these. 

632 if parent is not None: 

633 request.parent = parent 

634 if payload is not None: 

635 request.payload = payload 

636 

637 # Wrap the RPC method; this adds retry and timeout information, 

638 # and friendly error handling. 

639 rpc = self._client._transport._wrapped_methods[ 

640 self._client._transport.add_secret_version 

641 ] 

642 

643 # Certain fields should be provided within the metadata header; 

644 # add these here. 

645 metadata = tuple(metadata) + ( 

646 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

647 ) 

648 

649 # Validate the universe domain. 

650 self._client._validate_universe_domain() 

651 

652 # Send the request. 

653 response = await rpc( 

654 request, 

655 retry=retry, 

656 timeout=timeout, 

657 metadata=metadata, 

658 ) 

659 

660 # Done; return the response. 

661 return response 

662 

663 async def get_secret( 

664 self, 

665 request: Optional[Union[service.GetSecretRequest, dict]] = None, 

666 *, 

667 name: Optional[str] = None, 

668 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

669 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

670 metadata: Sequence[Tuple[str, str]] = (), 

671 ) -> resources.Secret: 

672 r"""Gets metadata for a given 

673 [Secret][google.cloud.secrets.v1beta1.Secret]. 

674 

675 .. code-block:: python 

676 

677 # This snippet has been automatically generated and should be regarded as a 

678 # code template only. 

679 # It will require modifications to work: 

680 # - It may require correct/in-range values for request initialization. 

681 # - It may require specifying regional endpoints when creating the service 

682 # client as shown in: 

683 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

684 from google.cloud import secretmanager_v1beta1 

685 

686 async def sample_get_secret(): 

687 # Create a client 

688 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

689 

690 # Initialize request argument(s) 

691 request = secretmanager_v1beta1.GetSecretRequest( 

692 name="name_value", 

693 ) 

694 

695 # Make the request 

696 response = await client.get_secret(request=request) 

697 

698 # Handle the response 

699 print(response) 

700 

701 Args: 

702 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.GetSecretRequest, dict]]): 

703 The request object. Request message for 

704 [SecretManagerService.GetSecret][google.cloud.secrets.v1beta1.SecretManagerService.GetSecret]. 

705 name (:class:`str`): 

706 Required. The resource name of the 

707 [Secret][google.cloud.secrets.v1beta1.Secret], in the 

708 format ``projects/*/secrets/*``. 

709 

710 This corresponds to the ``name`` field 

711 on the ``request`` instance; if ``request`` is provided, this 

712 should not be set. 

713 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

714 should be retried. 

715 timeout (float): The timeout for this request. 

716 metadata (Sequence[Tuple[str, str]]): Strings which should be 

717 sent along with the request as metadata. 

718 

719 Returns: 

720 google.cloud.secretmanager_v1beta1.types.Secret: 

721 A [Secret][google.cloud.secrets.v1beta1.Secret] is a logical secret whose value and versions can 

722 be accessed. 

723 

724 A [Secret][google.cloud.secrets.v1beta1.Secret] is 

725 made up of zero or more 

726 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] 

727 that represent the secret data. 

728 

729 """ 

730 # Create or coerce a protobuf request object. 

731 # - Quick check: If we got a request object, we should *not* have 

732 # gotten any keyword arguments that map to the request. 

733 has_flattened_params = any([name]) 

734 if request is not None and has_flattened_params: 

735 raise ValueError( 

736 "If the `request` argument is set, then none of " 

737 "the individual field arguments should be set." 

738 ) 

739 

740 # - Use the request object if provided (there's no risk of modifying the input as 

741 # there are no flattened fields), or create one. 

742 if not isinstance(request, service.GetSecretRequest): 

743 request = service.GetSecretRequest(request) 

744 

745 # If we have keyword arguments corresponding to fields on the 

746 # request, apply these. 

747 if name is not None: 

748 request.name = name 

749 

750 # Wrap the RPC method; this adds retry and timeout information, 

751 # and friendly error handling. 

752 rpc = self._client._transport._wrapped_methods[ 

753 self._client._transport.get_secret 

754 ] 

755 

756 # Certain fields should be provided within the metadata header; 

757 # add these here. 

758 metadata = tuple(metadata) + ( 

759 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

760 ) 

761 

762 # Validate the universe domain. 

763 self._client._validate_universe_domain() 

764 

765 # Send the request. 

766 response = await rpc( 

767 request, 

768 retry=retry, 

769 timeout=timeout, 

770 metadata=metadata, 

771 ) 

772 

773 # Done; return the response. 

774 return response 

775 

776 async def update_secret( 

777 self, 

778 request: Optional[Union[service.UpdateSecretRequest, dict]] = None, 

779 *, 

780 secret: Optional[resources.Secret] = None, 

781 update_mask: Optional[field_mask_pb2.FieldMask] = None, 

782 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

783 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

784 metadata: Sequence[Tuple[str, str]] = (), 

785 ) -> resources.Secret: 

786 r"""Updates metadata of an existing 

787 [Secret][google.cloud.secrets.v1beta1.Secret]. 

788 

789 .. code-block:: python 

790 

791 # This snippet has been automatically generated and should be regarded as a 

792 # code template only. 

793 # It will require modifications to work: 

794 # - It may require correct/in-range values for request initialization. 

795 # - It may require specifying regional endpoints when creating the service 

796 # client as shown in: 

797 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

798 from google.cloud import secretmanager_v1beta1 

799 

800 async def sample_update_secret(): 

801 # Create a client 

802 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

803 

804 # Initialize request argument(s) 

805 request = secretmanager_v1beta1.UpdateSecretRequest( 

806 ) 

807 

808 # Make the request 

809 response = await client.update_secret(request=request) 

810 

811 # Handle the response 

812 print(response) 

813 

814 Args: 

815 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.UpdateSecretRequest, dict]]): 

816 The request object. Request message for 

817 [SecretManagerService.UpdateSecret][google.cloud.secrets.v1beta1.SecretManagerService.UpdateSecret]. 

818 secret (:class:`google.cloud.secretmanager_v1beta1.types.Secret`): 

819 Required. [Secret][google.cloud.secrets.v1beta1.Secret] 

820 with updated field values. 

821 

822 This corresponds to the ``secret`` field 

823 on the ``request`` instance; if ``request`` is provided, this 

824 should not be set. 

825 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): 

826 Required. Specifies the fields to be 

827 updated. 

828 

829 This corresponds to the ``update_mask`` field 

830 on the ``request`` instance; if ``request`` is provided, this 

831 should not be set. 

832 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

833 should be retried. 

834 timeout (float): The timeout for this request. 

835 metadata (Sequence[Tuple[str, str]]): Strings which should be 

836 sent along with the request as metadata. 

837 

838 Returns: 

839 google.cloud.secretmanager_v1beta1.types.Secret: 

840 A [Secret][google.cloud.secrets.v1beta1.Secret] is a logical secret whose value and versions can 

841 be accessed. 

842 

843 A [Secret][google.cloud.secrets.v1beta1.Secret] is 

844 made up of zero or more 

845 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] 

846 that represent the secret data. 

847 

848 """ 

849 # Create or coerce a protobuf request object. 

850 # - Quick check: If we got a request object, we should *not* have 

851 # gotten any keyword arguments that map to the request. 

852 has_flattened_params = any([secret, update_mask]) 

853 if request is not None and has_flattened_params: 

854 raise ValueError( 

855 "If the `request` argument is set, then none of " 

856 "the individual field arguments should be set." 

857 ) 

858 

859 # - Use the request object if provided (there's no risk of modifying the input as 

860 # there are no flattened fields), or create one. 

861 if not isinstance(request, service.UpdateSecretRequest): 

862 request = service.UpdateSecretRequest(request) 

863 

864 # If we have keyword arguments corresponding to fields on the 

865 # request, apply these. 

866 if secret is not None: 

867 request.secret = secret 

868 if update_mask is not None: 

869 request.update_mask = update_mask 

870 

871 # Wrap the RPC method; this adds retry and timeout information, 

872 # and friendly error handling. 

873 rpc = self._client._transport._wrapped_methods[ 

874 self._client._transport.update_secret 

875 ] 

876 

877 # Certain fields should be provided within the metadata header; 

878 # add these here. 

879 metadata = tuple(metadata) + ( 

880 gapic_v1.routing_header.to_grpc_metadata( 

881 (("secret.name", request.secret.name),) 

882 ), 

883 ) 

884 

885 # Validate the universe domain. 

886 self._client._validate_universe_domain() 

887 

888 # Send the request. 

889 response = await rpc( 

890 request, 

891 retry=retry, 

892 timeout=timeout, 

893 metadata=metadata, 

894 ) 

895 

896 # Done; return the response. 

897 return response 

898 

899 async def delete_secret( 

900 self, 

901 request: Optional[Union[service.DeleteSecretRequest, dict]] = None, 

902 *, 

903 name: Optional[str] = None, 

904 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

905 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

906 metadata: Sequence[Tuple[str, str]] = (), 

907 ) -> None: 

908 r"""Deletes a [Secret][google.cloud.secrets.v1beta1.Secret]. 

909 

910 .. code-block:: python 

911 

912 # This snippet has been automatically generated and should be regarded as a 

913 # code template only. 

914 # It will require modifications to work: 

915 # - It may require correct/in-range values for request initialization. 

916 # - It may require specifying regional endpoints when creating the service 

917 # client as shown in: 

918 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

919 from google.cloud import secretmanager_v1beta1 

920 

921 async def sample_delete_secret(): 

922 # Create a client 

923 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

924 

925 # Initialize request argument(s) 

926 request = secretmanager_v1beta1.DeleteSecretRequest( 

927 name="name_value", 

928 ) 

929 

930 # Make the request 

931 await client.delete_secret(request=request) 

932 

933 Args: 

934 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.DeleteSecretRequest, dict]]): 

935 The request object. Request message for 

936 [SecretManagerService.DeleteSecret][google.cloud.secrets.v1beta1.SecretManagerService.DeleteSecret]. 

937 name (:class:`str`): 

938 Required. The resource name of the 

939 [Secret][google.cloud.secrets.v1beta1.Secret] to delete 

940 in the format ``projects/*/secrets/*``. 

941 

942 This corresponds to the ``name`` field 

943 on the ``request`` instance; if ``request`` is provided, this 

944 should not be set. 

945 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

946 should be retried. 

947 timeout (float): The timeout for this request. 

948 metadata (Sequence[Tuple[str, str]]): Strings which should be 

949 sent along with the request as metadata. 

950 """ 

951 # Create or coerce a protobuf request object. 

952 # - Quick check: If we got a request object, we should *not* have 

953 # gotten any keyword arguments that map to the request. 

954 has_flattened_params = any([name]) 

955 if request is not None and has_flattened_params: 

956 raise ValueError( 

957 "If the `request` argument is set, then none of " 

958 "the individual field arguments should be set." 

959 ) 

960 

961 # - Use the request object if provided (there's no risk of modifying the input as 

962 # there are no flattened fields), or create one. 

963 if not isinstance(request, service.DeleteSecretRequest): 

964 request = service.DeleteSecretRequest(request) 

965 

966 # If we have keyword arguments corresponding to fields on the 

967 # request, apply these. 

968 if name is not None: 

969 request.name = name 

970 

971 # Wrap the RPC method; this adds retry and timeout information, 

972 # and friendly error handling. 

973 rpc = self._client._transport._wrapped_methods[ 

974 self._client._transport.delete_secret 

975 ] 

976 

977 # Certain fields should be provided within the metadata header; 

978 # add these here. 

979 metadata = tuple(metadata) + ( 

980 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

981 ) 

982 

983 # Validate the universe domain. 

984 self._client._validate_universe_domain() 

985 

986 # Send the request. 

987 await rpc( 

988 request, 

989 retry=retry, 

990 timeout=timeout, 

991 metadata=metadata, 

992 ) 

993 

994 async def list_secret_versions( 

995 self, 

996 request: Optional[Union[service.ListSecretVersionsRequest, dict]] = None, 

997 *, 

998 parent: Optional[str] = None, 

999 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1000 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1001 metadata: Sequence[Tuple[str, str]] = (), 

1002 ) -> pagers.ListSecretVersionsAsyncPager: 

1003 r"""Lists 

1004 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]. 

1005 This call does not return secret data. 

1006 

1007 .. code-block:: python 

1008 

1009 # This snippet has been automatically generated and should be regarded as a 

1010 # code template only. 

1011 # It will require modifications to work: 

1012 # - It may require correct/in-range values for request initialization. 

1013 # - It may require specifying regional endpoints when creating the service 

1014 # client as shown in: 

1015 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1016 from google.cloud import secretmanager_v1beta1 

1017 

1018 async def sample_list_secret_versions(): 

1019 # Create a client 

1020 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1021 

1022 # Initialize request argument(s) 

1023 request = secretmanager_v1beta1.ListSecretVersionsRequest( 

1024 parent="parent_value", 

1025 ) 

1026 

1027 # Make the request 

1028 page_result = client.list_secret_versions(request=request) 

1029 

1030 # Handle the response 

1031 async for response in page_result: 

1032 print(response) 

1033 

1034 Args: 

1035 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.ListSecretVersionsRequest, dict]]): 

1036 The request object. Request message for 

1037 [SecretManagerService.ListSecretVersions][google.cloud.secrets.v1beta1.SecretManagerService.ListSecretVersions]. 

1038 parent (:class:`str`): 

1039 Required. The resource name of the 

1040 [Secret][google.cloud.secrets.v1beta1.Secret] associated 

1041 with the 

1042 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] 

1043 to list, in the format ``projects/*/secrets/*``. 

1044 

1045 This corresponds to the ``parent`` field 

1046 on the ``request`` instance; if ``request`` is provided, this 

1047 should not be set. 

1048 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1049 should be retried. 

1050 timeout (float): The timeout for this request. 

1051 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1052 sent along with the request as metadata. 

1053 

1054 Returns: 

1055 google.cloud.secretmanager_v1beta1.services.secret_manager_service.pagers.ListSecretVersionsAsyncPager: 

1056 Response message for 

1057 [SecretManagerService.ListSecretVersions][google.cloud.secrets.v1beta1.SecretManagerService.ListSecretVersions]. 

1058 

1059 Iterating over this object will yield results and 

1060 resolve additional pages automatically. 

1061 

1062 """ 

1063 # Create or coerce a protobuf request object. 

1064 # - Quick check: If we got a request object, we should *not* have 

1065 # gotten any keyword arguments that map to the request. 

1066 has_flattened_params = any([parent]) 

1067 if request is not None and has_flattened_params: 

1068 raise ValueError( 

1069 "If the `request` argument is set, then none of " 

1070 "the individual field arguments should be set." 

1071 ) 

1072 

1073 # - Use the request object if provided (there's no risk of modifying the input as 

1074 # there are no flattened fields), or create one. 

1075 if not isinstance(request, service.ListSecretVersionsRequest): 

1076 request = service.ListSecretVersionsRequest(request) 

1077 

1078 # If we have keyword arguments corresponding to fields on the 

1079 # request, apply these. 

1080 if parent is not None: 

1081 request.parent = parent 

1082 

1083 # Wrap the RPC method; this adds retry and timeout information, 

1084 # and friendly error handling. 

1085 rpc = self._client._transport._wrapped_methods[ 

1086 self._client._transport.list_secret_versions 

1087 ] 

1088 

1089 # Certain fields should be provided within the metadata header; 

1090 # add these here. 

1091 metadata = tuple(metadata) + ( 

1092 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

1093 ) 

1094 

1095 # Validate the universe domain. 

1096 self._client._validate_universe_domain() 

1097 

1098 # Send the request. 

1099 response = await rpc( 

1100 request, 

1101 retry=retry, 

1102 timeout=timeout, 

1103 metadata=metadata, 

1104 ) 

1105 

1106 # This method is paged; wrap the response in a pager, which provides 

1107 # an `__aiter__` convenience method. 

1108 response = pagers.ListSecretVersionsAsyncPager( 

1109 method=rpc, 

1110 request=request, 

1111 response=response, 

1112 metadata=metadata, 

1113 ) 

1114 

1115 # Done; return the response. 

1116 return response 

1117 

1118 async def get_secret_version( 

1119 self, 

1120 request: Optional[Union[service.GetSecretVersionRequest, dict]] = None, 

1121 *, 

1122 name: Optional[str] = None, 

1123 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1124 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1125 metadata: Sequence[Tuple[str, str]] = (), 

1126 ) -> resources.SecretVersion: 

1127 r"""Gets metadata for a 

1128 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1129 

1130 ``projects/*/secrets/*/versions/latest`` is an alias to the 

1131 ``latest`` 

1132 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1133 

1134 .. code-block:: python 

1135 

1136 # This snippet has been automatically generated and should be regarded as a 

1137 # code template only. 

1138 # It will require modifications to work: 

1139 # - It may require correct/in-range values for request initialization. 

1140 # - It may require specifying regional endpoints when creating the service 

1141 # client as shown in: 

1142 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1143 from google.cloud import secretmanager_v1beta1 

1144 

1145 async def sample_get_secret_version(): 

1146 # Create a client 

1147 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1148 

1149 # Initialize request argument(s) 

1150 request = secretmanager_v1beta1.GetSecretVersionRequest( 

1151 name="name_value", 

1152 ) 

1153 

1154 # Make the request 

1155 response = await client.get_secret_version(request=request) 

1156 

1157 # Handle the response 

1158 print(response) 

1159 

1160 Args: 

1161 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.GetSecretVersionRequest, dict]]): 

1162 The request object. Request message for 

1163 [SecretManagerService.GetSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.GetSecretVersion]. 

1164 name (:class:`str`): 

1165 Required. The resource name of the 

1166 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

1167 in the format ``projects/*/secrets/*/versions/*``. 

1168 ``projects/*/secrets/*/versions/latest`` is an alias to 

1169 the ``latest`` 

1170 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1171 

1172 This corresponds to the ``name`` field 

1173 on the ``request`` instance; if ``request`` is provided, this 

1174 should not be set. 

1175 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1176 should be retried. 

1177 timeout (float): The timeout for this request. 

1178 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1179 sent along with the request as metadata. 

1180 

1181 Returns: 

1182 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1183 A secret version resource in the 

1184 Secret Manager API. 

1185 

1186 """ 

1187 # Create or coerce a protobuf request object. 

1188 # - Quick check: If we got a request object, we should *not* have 

1189 # gotten any keyword arguments that map to the request. 

1190 has_flattened_params = any([name]) 

1191 if request is not None and has_flattened_params: 

1192 raise ValueError( 

1193 "If the `request` argument is set, then none of " 

1194 "the individual field arguments should be set." 

1195 ) 

1196 

1197 # - Use the request object if provided (there's no risk of modifying the input as 

1198 # there are no flattened fields), or create one. 

1199 if not isinstance(request, service.GetSecretVersionRequest): 

1200 request = service.GetSecretVersionRequest(request) 

1201 

1202 # If we have keyword arguments corresponding to fields on the 

1203 # request, apply these. 

1204 if name is not None: 

1205 request.name = name 

1206 

1207 # Wrap the RPC method; this adds retry and timeout information, 

1208 # and friendly error handling. 

1209 rpc = self._client._transport._wrapped_methods[ 

1210 self._client._transport.get_secret_version 

1211 ] 

1212 

1213 # Certain fields should be provided within the metadata header; 

1214 # add these here. 

1215 metadata = tuple(metadata) + ( 

1216 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1217 ) 

1218 

1219 # Validate the universe domain. 

1220 self._client._validate_universe_domain() 

1221 

1222 # Send the request. 

1223 response = await rpc( 

1224 request, 

1225 retry=retry, 

1226 timeout=timeout, 

1227 metadata=metadata, 

1228 ) 

1229 

1230 # Done; return the response. 

1231 return response 

1232 

1233 async def access_secret_version( 

1234 self, 

1235 request: Optional[Union[service.AccessSecretVersionRequest, dict]] = None, 

1236 *, 

1237 name: Optional[str] = None, 

1238 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1239 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1240 metadata: Sequence[Tuple[str, str]] = (), 

1241 ) -> service.AccessSecretVersionResponse: 

1242 r"""Accesses a 

1243 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1244 This call returns the secret data. 

1245 

1246 ``projects/*/secrets/*/versions/latest`` is an alias to the 

1247 ``latest`` 

1248 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1249 

1250 .. code-block:: python 

1251 

1252 # This snippet has been automatically generated and should be regarded as a 

1253 # code template only. 

1254 # It will require modifications to work: 

1255 # - It may require correct/in-range values for request initialization. 

1256 # - It may require specifying regional endpoints when creating the service 

1257 # client as shown in: 

1258 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1259 from google.cloud import secretmanager_v1beta1 

1260 

1261 async def sample_access_secret_version(): 

1262 # Create a client 

1263 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1264 

1265 # Initialize request argument(s) 

1266 request = secretmanager_v1beta1.AccessSecretVersionRequest( 

1267 name="name_value", 

1268 ) 

1269 

1270 # Make the request 

1271 response = await client.access_secret_version(request=request) 

1272 

1273 # Handle the response 

1274 print(response) 

1275 

1276 Args: 

1277 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.AccessSecretVersionRequest, dict]]): 

1278 The request object. Request message for 

1279 [SecretManagerService.AccessSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AccessSecretVersion]. 

1280 name (:class:`str`): 

1281 Required. The resource name of the 

1282 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

1283 in the format ``projects/*/secrets/*/versions/*``. 

1284 

1285 This corresponds to the ``name`` field 

1286 on the ``request`` instance; if ``request`` is provided, this 

1287 should not be set. 

1288 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1289 should be retried. 

1290 timeout (float): The timeout for this request. 

1291 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1292 sent along with the request as metadata. 

1293 

1294 Returns: 

1295 google.cloud.secretmanager_v1beta1.types.AccessSecretVersionResponse: 

1296 Response message for 

1297 [SecretManagerService.AccessSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.AccessSecretVersion]. 

1298 

1299 """ 

1300 # Create or coerce a protobuf request object. 

1301 # - Quick check: If we got a request object, we should *not* have 

1302 # gotten any keyword arguments that map to the request. 

1303 has_flattened_params = any([name]) 

1304 if request is not None and has_flattened_params: 

1305 raise ValueError( 

1306 "If the `request` argument is set, then none of " 

1307 "the individual field arguments should be set." 

1308 ) 

1309 

1310 # - Use the request object if provided (there's no risk of modifying the input as 

1311 # there are no flattened fields), or create one. 

1312 if not isinstance(request, service.AccessSecretVersionRequest): 

1313 request = service.AccessSecretVersionRequest(request) 

1314 

1315 # If we have keyword arguments corresponding to fields on the 

1316 # request, apply these. 

1317 if name is not None: 

1318 request.name = name 

1319 

1320 # Wrap the RPC method; this adds retry and timeout information, 

1321 # and friendly error handling. 

1322 rpc = self._client._transport._wrapped_methods[ 

1323 self._client._transport.access_secret_version 

1324 ] 

1325 

1326 # Certain fields should be provided within the metadata header; 

1327 # add these here. 

1328 metadata = tuple(metadata) + ( 

1329 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1330 ) 

1331 

1332 # Validate the universe domain. 

1333 self._client._validate_universe_domain() 

1334 

1335 # Send the request. 

1336 response = await rpc( 

1337 request, 

1338 retry=retry, 

1339 timeout=timeout, 

1340 metadata=metadata, 

1341 ) 

1342 

1343 # Done; return the response. 

1344 return response 

1345 

1346 async def disable_secret_version( 

1347 self, 

1348 request: Optional[Union[service.DisableSecretVersionRequest, dict]] = None, 

1349 *, 

1350 name: Optional[str] = None, 

1351 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1352 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1353 metadata: Sequence[Tuple[str, str]] = (), 

1354 ) -> resources.SecretVersion: 

1355 r"""Disables a 

1356 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1357 

1358 Sets the 

1359 [state][google.cloud.secrets.v1beta1.SecretVersion.state] of the 

1360 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to 

1361 [DISABLED][google.cloud.secrets.v1beta1.SecretVersion.State.DISABLED]. 

1362 

1363 .. code-block:: python 

1364 

1365 # This snippet has been automatically generated and should be regarded as a 

1366 # code template only. 

1367 # It will require modifications to work: 

1368 # - It may require correct/in-range values for request initialization. 

1369 # - It may require specifying regional endpoints when creating the service 

1370 # client as shown in: 

1371 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1372 from google.cloud import secretmanager_v1beta1 

1373 

1374 async def sample_disable_secret_version(): 

1375 # Create a client 

1376 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1377 

1378 # Initialize request argument(s) 

1379 request = secretmanager_v1beta1.DisableSecretVersionRequest( 

1380 name="name_value", 

1381 ) 

1382 

1383 # Make the request 

1384 response = await client.disable_secret_version(request=request) 

1385 

1386 # Handle the response 

1387 print(response) 

1388 

1389 Args: 

1390 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.DisableSecretVersionRequest, dict]]): 

1391 The request object. Request message for 

1392 [SecretManagerService.DisableSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.DisableSecretVersion]. 

1393 name (:class:`str`): 

1394 Required. The resource name of the 

1395 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

1396 to disable in the format 

1397 ``projects/*/secrets/*/versions/*``. 

1398 

1399 This corresponds to the ``name`` field 

1400 on the ``request`` instance; if ``request`` is provided, this 

1401 should not be set. 

1402 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1403 should be retried. 

1404 timeout (float): The timeout for this request. 

1405 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1406 sent along with the request as metadata. 

1407 

1408 Returns: 

1409 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1410 A secret version resource in the 

1411 Secret Manager API. 

1412 

1413 """ 

1414 # Create or coerce a protobuf request object. 

1415 # - Quick check: If we got a request object, we should *not* have 

1416 # gotten any keyword arguments that map to the request. 

1417 has_flattened_params = any([name]) 

1418 if request is not None and has_flattened_params: 

1419 raise ValueError( 

1420 "If the `request` argument is set, then none of " 

1421 "the individual field arguments should be set." 

1422 ) 

1423 

1424 # - Use the request object if provided (there's no risk of modifying the input as 

1425 # there are no flattened fields), or create one. 

1426 if not isinstance(request, service.DisableSecretVersionRequest): 

1427 request = service.DisableSecretVersionRequest(request) 

1428 

1429 # If we have keyword arguments corresponding to fields on the 

1430 # request, apply these. 

1431 if name is not None: 

1432 request.name = name 

1433 

1434 # Wrap the RPC method; this adds retry and timeout information, 

1435 # and friendly error handling. 

1436 rpc = self._client._transport._wrapped_methods[ 

1437 self._client._transport.disable_secret_version 

1438 ] 

1439 

1440 # Certain fields should be provided within the metadata header; 

1441 # add these here. 

1442 metadata = tuple(metadata) + ( 

1443 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1444 ) 

1445 

1446 # Validate the universe domain. 

1447 self._client._validate_universe_domain() 

1448 

1449 # Send the request. 

1450 response = await rpc( 

1451 request, 

1452 retry=retry, 

1453 timeout=timeout, 

1454 metadata=metadata, 

1455 ) 

1456 

1457 # Done; return the response. 

1458 return response 

1459 

1460 async def enable_secret_version( 

1461 self, 

1462 request: Optional[Union[service.EnableSecretVersionRequest, dict]] = None, 

1463 *, 

1464 name: Optional[str] = None, 

1465 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1466 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1467 metadata: Sequence[Tuple[str, str]] = (), 

1468 ) -> resources.SecretVersion: 

1469 r"""Enables a 

1470 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1471 

1472 Sets the 

1473 [state][google.cloud.secrets.v1beta1.SecretVersion.state] of the 

1474 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to 

1475 [ENABLED][google.cloud.secrets.v1beta1.SecretVersion.State.ENABLED]. 

1476 

1477 .. code-block:: python 

1478 

1479 # This snippet has been automatically generated and should be regarded as a 

1480 # code template only. 

1481 # It will require modifications to work: 

1482 # - It may require correct/in-range values for request initialization. 

1483 # - It may require specifying regional endpoints when creating the service 

1484 # client as shown in: 

1485 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1486 from google.cloud import secretmanager_v1beta1 

1487 

1488 async def sample_enable_secret_version(): 

1489 # Create a client 

1490 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1491 

1492 # Initialize request argument(s) 

1493 request = secretmanager_v1beta1.EnableSecretVersionRequest( 

1494 name="name_value", 

1495 ) 

1496 

1497 # Make the request 

1498 response = await client.enable_secret_version(request=request) 

1499 

1500 # Handle the response 

1501 print(response) 

1502 

1503 Args: 

1504 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.EnableSecretVersionRequest, dict]]): 

1505 The request object. Request message for 

1506 [SecretManagerService.EnableSecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.EnableSecretVersion]. 

1507 name (:class:`str`): 

1508 Required. The resource name of the 

1509 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

1510 to enable in the format 

1511 ``projects/*/secrets/*/versions/*``. 

1512 

1513 This corresponds to the ``name`` field 

1514 on the ``request`` instance; if ``request`` is provided, this 

1515 should not be set. 

1516 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1517 should be retried. 

1518 timeout (float): The timeout for this request. 

1519 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1520 sent along with the request as metadata. 

1521 

1522 Returns: 

1523 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1524 A secret version resource in the 

1525 Secret Manager API. 

1526 

1527 """ 

1528 # Create or coerce a protobuf request object. 

1529 # - Quick check: If we got a request object, we should *not* have 

1530 # gotten any keyword arguments that map to the request. 

1531 has_flattened_params = any([name]) 

1532 if request is not None and has_flattened_params: 

1533 raise ValueError( 

1534 "If the `request` argument is set, then none of " 

1535 "the individual field arguments should be set." 

1536 ) 

1537 

1538 # - Use the request object if provided (there's no risk of modifying the input as 

1539 # there are no flattened fields), or create one. 

1540 if not isinstance(request, service.EnableSecretVersionRequest): 

1541 request = service.EnableSecretVersionRequest(request) 

1542 

1543 # If we have keyword arguments corresponding to fields on the 

1544 # request, apply these. 

1545 if name is not None: 

1546 request.name = name 

1547 

1548 # Wrap the RPC method; this adds retry and timeout information, 

1549 # and friendly error handling. 

1550 rpc = self._client._transport._wrapped_methods[ 

1551 self._client._transport.enable_secret_version 

1552 ] 

1553 

1554 # Certain fields should be provided within the metadata header; 

1555 # add these here. 

1556 metadata = tuple(metadata) + ( 

1557 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1558 ) 

1559 

1560 # Validate the universe domain. 

1561 self._client._validate_universe_domain() 

1562 

1563 # Send the request. 

1564 response = await rpc( 

1565 request, 

1566 retry=retry, 

1567 timeout=timeout, 

1568 metadata=metadata, 

1569 ) 

1570 

1571 # Done; return the response. 

1572 return response 

1573 

1574 async def destroy_secret_version( 

1575 self, 

1576 request: Optional[Union[service.DestroySecretVersionRequest, dict]] = None, 

1577 *, 

1578 name: Optional[str] = None, 

1579 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1580 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1581 metadata: Sequence[Tuple[str, str]] = (), 

1582 ) -> resources.SecretVersion: 

1583 r"""Destroys a 

1584 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. 

1585 

1586 Sets the 

1587 [state][google.cloud.secrets.v1beta1.SecretVersion.state] of the 

1588 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to 

1589 [DESTROYED][google.cloud.secrets.v1beta1.SecretVersion.State.DESTROYED] 

1590 and irrevocably destroys the secret data. 

1591 

1592 .. code-block:: python 

1593 

1594 # This snippet has been automatically generated and should be regarded as a 

1595 # code template only. 

1596 # It will require modifications to work: 

1597 # - It may require correct/in-range values for request initialization. 

1598 # - It may require specifying regional endpoints when creating the service 

1599 # client as shown in: 

1600 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1601 from google.cloud import secretmanager_v1beta1 

1602 

1603 async def sample_destroy_secret_version(): 

1604 # Create a client 

1605 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1606 

1607 # Initialize request argument(s) 

1608 request = secretmanager_v1beta1.DestroySecretVersionRequest( 

1609 name="name_value", 

1610 ) 

1611 

1612 # Make the request 

1613 response = await client.destroy_secret_version(request=request) 

1614 

1615 # Handle the response 

1616 print(response) 

1617 

1618 Args: 

1619 request (Optional[Union[google.cloud.secretmanager_v1beta1.types.DestroySecretVersionRequest, dict]]): 

1620 The request object. Request message for 

1621 [SecretManagerService.DestroySecretVersion][google.cloud.secrets.v1beta1.SecretManagerService.DestroySecretVersion]. 

1622 name (:class:`str`): 

1623 Required. The resource name of the 

1624 [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] 

1625 to destroy in the format 

1626 ``projects/*/secrets/*/versions/*``. 

1627 

1628 This corresponds to the ``name`` field 

1629 on the ``request`` instance; if ``request`` is provided, this 

1630 should not be set. 

1631 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1632 should be retried. 

1633 timeout (float): The timeout for this request. 

1634 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1635 sent along with the request as metadata. 

1636 

1637 Returns: 

1638 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1639 A secret version resource in the 

1640 Secret Manager API. 

1641 

1642 """ 

1643 # Create or coerce a protobuf request object. 

1644 # - Quick check: If we got a request object, we should *not* have 

1645 # gotten any keyword arguments that map to the request. 

1646 has_flattened_params = any([name]) 

1647 if request is not None and has_flattened_params: 

1648 raise ValueError( 

1649 "If the `request` argument is set, then none of " 

1650 "the individual field arguments should be set." 

1651 ) 

1652 

1653 # - Use the request object if provided (there's no risk of modifying the input as 

1654 # there are no flattened fields), or create one. 

1655 if not isinstance(request, service.DestroySecretVersionRequest): 

1656 request = service.DestroySecretVersionRequest(request) 

1657 

1658 # If we have keyword arguments corresponding to fields on the 

1659 # request, apply these. 

1660 if name is not None: 

1661 request.name = name 

1662 

1663 # Wrap the RPC method; this adds retry and timeout information, 

1664 # and friendly error handling. 

1665 rpc = self._client._transport._wrapped_methods[ 

1666 self._client._transport.destroy_secret_version 

1667 ] 

1668 

1669 # Certain fields should be provided within the metadata header; 

1670 # add these here. 

1671 metadata = tuple(metadata) + ( 

1672 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1673 ) 

1674 

1675 # Validate the universe domain. 

1676 self._client._validate_universe_domain() 

1677 

1678 # Send the request. 

1679 response = await rpc( 

1680 request, 

1681 retry=retry, 

1682 timeout=timeout, 

1683 metadata=metadata, 

1684 ) 

1685 

1686 # Done; return the response. 

1687 return response 

1688 

1689 async def set_iam_policy( 

1690 self, 

1691 request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, 

1692 *, 

1693 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1694 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1695 metadata: Sequence[Tuple[str, str]] = (), 

1696 ) -> policy_pb2.Policy: 

1697 r"""Sets the access control policy on the specified secret. Replaces 

1698 any existing policy. 

1699 

1700 Permissions on 

1701 [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] are 

1702 enforced according to the policy set on the associated 

1703 [Secret][google.cloud.secrets.v1beta1.Secret]. 

1704 

1705 .. code-block:: python 

1706 

1707 # This snippet has been automatically generated and should be regarded as a 

1708 # code template only. 

1709 # It will require modifications to work: 

1710 # - It may require correct/in-range values for request initialization. 

1711 # - It may require specifying regional endpoints when creating the service 

1712 # client as shown in: 

1713 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1714 from google.cloud import secretmanager_v1beta1 

1715 from google.iam.v1 import iam_policy_pb2 # type: ignore 

1716 

1717 async def sample_set_iam_policy(): 

1718 # Create a client 

1719 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1720 

1721 # Initialize request argument(s) 

1722 request = iam_policy_pb2.SetIamPolicyRequest( 

1723 resource="resource_value", 

1724 ) 

1725 

1726 # Make the request 

1727 response = await client.set_iam_policy(request=request) 

1728 

1729 # Handle the response 

1730 print(response) 

1731 

1732 Args: 

1733 request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]): 

1734 The request object. Request message for ``SetIamPolicy`` method. 

1735 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1736 should be retried. 

1737 timeout (float): The timeout for this request. 

1738 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1739 sent along with the request as metadata. 

1740 

1741 Returns: 

1742 google.iam.v1.policy_pb2.Policy: 

1743 An Identity and Access Management (IAM) policy, which specifies access 

1744 controls for Google Cloud resources. 

1745 

1746 A Policy is a collection of bindings. A binding binds 

1747 one or more members, or principals, to a single role. 

1748 Principals can be user accounts, service accounts, 

1749 Google groups, and domains (such as G Suite). A role 

1750 is a named list of permissions; each role can be an 

1751 IAM predefined role or a user-created custom role. 

1752 

1753 For some types of Google Cloud resources, a binding 

1754 can also specify a condition, which is a logical 

1755 expression that allows access to a resource only if 

1756 the expression evaluates to true. A condition can add 

1757 constraints based on attributes of the request, the 

1758 resource, or both. To learn which resources support 

1759 conditions in their IAM policies, see the [IAM 

1760 documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). 

1761 

1762 **JSON example:** 

1763 

1764 :literal:`\` { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 }`\ \` 

1765 

1766 **YAML example:** 

1767 

1768 :literal:`\` bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3`\ \` 

1769 

1770 For a description of IAM and its features, see the 

1771 [IAM 

1772 documentation](\ https://cloud.google.com/iam/docs/). 

1773 

1774 """ 

1775 # Create or coerce a protobuf request object. 

1776 # - The request isn't a proto-plus wrapped type, 

1777 # so it must be constructed via keyword expansion. 

1778 if isinstance(request, dict): 

1779 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1780 elif not request: 

1781 request = iam_policy_pb2.SetIamPolicyRequest() 

1782 

1783 # Wrap the RPC method; this adds retry and timeout information, 

1784 # and friendly error handling. 

1785 rpc = self._client._transport._wrapped_methods[ 

1786 self._client._transport.set_iam_policy 

1787 ] 

1788 

1789 # Certain fields should be provided within the metadata header; 

1790 # add these here. 

1791 metadata = tuple(metadata) + ( 

1792 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1793 ) 

1794 

1795 # Validate the universe domain. 

1796 self._client._validate_universe_domain() 

1797 

1798 # Send the request. 

1799 response = await rpc( 

1800 request, 

1801 retry=retry, 

1802 timeout=timeout, 

1803 metadata=metadata, 

1804 ) 

1805 

1806 # Done; return the response. 

1807 return response 

1808 

1809 async def get_iam_policy( 

1810 self, 

1811 request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, 

1812 *, 

1813 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1814 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1815 metadata: Sequence[Tuple[str, str]] = (), 

1816 ) -> policy_pb2.Policy: 

1817 r"""Gets the access control policy for a secret. 

1818 Returns empty policy if the secret exists and does not 

1819 have a policy set. 

1820 

1821 .. code-block:: python 

1822 

1823 # This snippet has been automatically generated and should be regarded as a 

1824 # code template only. 

1825 # It will require modifications to work: 

1826 # - It may require correct/in-range values for request initialization. 

1827 # - It may require specifying regional endpoints when creating the service 

1828 # client as shown in: 

1829 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1830 from google.cloud import secretmanager_v1beta1 

1831 from google.iam.v1 import iam_policy_pb2 # type: ignore 

1832 

1833 async def sample_get_iam_policy(): 

1834 # Create a client 

1835 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1836 

1837 # Initialize request argument(s) 

1838 request = iam_policy_pb2.GetIamPolicyRequest( 

1839 resource="resource_value", 

1840 ) 

1841 

1842 # Make the request 

1843 response = await client.get_iam_policy(request=request) 

1844 

1845 # Handle the response 

1846 print(response) 

1847 

1848 Args: 

1849 request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]): 

1850 The request object. Request message for ``GetIamPolicy`` method. 

1851 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1852 should be retried. 

1853 timeout (float): The timeout for this request. 

1854 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1855 sent along with the request as metadata. 

1856 

1857 Returns: 

1858 google.iam.v1.policy_pb2.Policy: 

1859 An Identity and Access Management (IAM) policy, which specifies access 

1860 controls for Google Cloud resources. 

1861 

1862 A Policy is a collection of bindings. A binding binds 

1863 one or more members, or principals, to a single role. 

1864 Principals can be user accounts, service accounts, 

1865 Google groups, and domains (such as G Suite). A role 

1866 is a named list of permissions; each role can be an 

1867 IAM predefined role or a user-created custom role. 

1868 

1869 For some types of Google Cloud resources, a binding 

1870 can also specify a condition, which is a logical 

1871 expression that allows access to a resource only if 

1872 the expression evaluates to true. A condition can add 

1873 constraints based on attributes of the request, the 

1874 resource, or both. To learn which resources support 

1875 conditions in their IAM policies, see the [IAM 

1876 documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). 

1877 

1878 **JSON example:** 

1879 

1880 :literal:`\` { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 }`\ \` 

1881 

1882 **YAML example:** 

1883 

1884 :literal:`\` bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3`\ \` 

1885 

1886 For a description of IAM and its features, see the 

1887 [IAM 

1888 documentation](\ https://cloud.google.com/iam/docs/). 

1889 

1890 """ 

1891 # Create or coerce a protobuf request object. 

1892 # - The request isn't a proto-plus wrapped type, 

1893 # so it must be constructed via keyword expansion. 

1894 if isinstance(request, dict): 

1895 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1896 elif not request: 

1897 request = iam_policy_pb2.GetIamPolicyRequest() 

1898 

1899 # Wrap the RPC method; this adds retry and timeout information, 

1900 # and friendly error handling. 

1901 rpc = self._client._transport._wrapped_methods[ 

1902 self._client._transport.get_iam_policy 

1903 ] 

1904 

1905 # Certain fields should be provided within the metadata header; 

1906 # add these here. 

1907 metadata = tuple(metadata) + ( 

1908 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1909 ) 

1910 

1911 # Validate the universe domain. 

1912 self._client._validate_universe_domain() 

1913 

1914 # Send the request. 

1915 response = await rpc( 

1916 request, 

1917 retry=retry, 

1918 timeout=timeout, 

1919 metadata=metadata, 

1920 ) 

1921 

1922 # Done; return the response. 

1923 return response 

1924 

1925 async def test_iam_permissions( 

1926 self, 

1927 request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, 

1928 *, 

1929 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1930 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1931 metadata: Sequence[Tuple[str, str]] = (), 

1932 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1933 r"""Returns permissions that a caller has for the specified secret. 

1934 If the secret does not exist, this call returns an empty set of 

1935 permissions, not a NOT_FOUND error. 

1936 

1937 Note: This operation is designed to be used for building 

1938 permission-aware UIs and command-line tools, not for 

1939 authorization checking. This operation may "fail open" without 

1940 warning. 

1941 

1942 .. code-block:: python 

1943 

1944 # This snippet has been automatically generated and should be regarded as a 

1945 # code template only. 

1946 # It will require modifications to work: 

1947 # - It may require correct/in-range values for request initialization. 

1948 # - It may require specifying regional endpoints when creating the service 

1949 # client as shown in: 

1950 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1951 from google.cloud import secretmanager_v1beta1 

1952 from google.iam.v1 import iam_policy_pb2 # type: ignore 

1953 

1954 async def sample_test_iam_permissions(): 

1955 # Create a client 

1956 client = secretmanager_v1beta1.SecretManagerServiceAsyncClient() 

1957 

1958 # Initialize request argument(s) 

1959 request = iam_policy_pb2.TestIamPermissionsRequest( 

1960 resource="resource_value", 

1961 permissions=['permissions_value1', 'permissions_value2'], 

1962 ) 

1963 

1964 # Make the request 

1965 response = await client.test_iam_permissions(request=request) 

1966 

1967 # Handle the response 

1968 print(response) 

1969 

1970 Args: 

1971 request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]): 

1972 The request object. Request message for ``TestIamPermissions`` method. 

1973 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1974 should be retried. 

1975 timeout (float): The timeout for this request. 

1976 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1977 sent along with the request as metadata. 

1978 

1979 Returns: 

1980 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: 

1981 Response message for TestIamPermissions method. 

1982 """ 

1983 # Create or coerce a protobuf request object. 

1984 # - The request isn't a proto-plus wrapped type, 

1985 # so it must be constructed via keyword expansion. 

1986 if isinstance(request, dict): 

1987 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1988 elif not request: 

1989 request = iam_policy_pb2.TestIamPermissionsRequest() 

1990 

1991 # Wrap the RPC method; this adds retry and timeout information, 

1992 # and friendly error handling. 

1993 rpc = self._client._transport._wrapped_methods[ 

1994 self._client._transport.test_iam_permissions 

1995 ] 

1996 

1997 # Certain fields should be provided within the metadata header; 

1998 # add these here. 

1999 metadata = tuple(metadata) + ( 

2000 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

2001 ) 

2002 

2003 # Validate the universe domain. 

2004 self._client._validate_universe_domain() 

2005 

2006 # Send the request. 

2007 response = await rpc( 

2008 request, 

2009 retry=retry, 

2010 timeout=timeout, 

2011 metadata=metadata, 

2012 ) 

2013 

2014 # Done; return the response. 

2015 return response 

2016 

2017 async def __aenter__(self) -> "SecretManagerServiceAsyncClient": 

2018 return self 

2019 

2020 async def __aexit__(self, exc_type, exc, tb): 

2021 await self.transport.close() 

2022 

2023 

2024DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

2025 gapic_version=package_version.__version__ 

2026) 

2027 

2028 

2029__all__ = ("SecretManagerServiceAsyncClient",)