Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/secretmanager_v1beta1/services/secret_manager_service/client.py: 42%

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

472 statements  

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 json 

17import logging as std_logging 

18import os 

19import re 

20import warnings 

21from collections import OrderedDict 

22from http import HTTPStatus 

23from typing import ( 

24 Callable, 

25 Dict, 

26 Mapping, 

27 MutableMapping, 

28 MutableSequence, 

29 Optional, 

30 Sequence, 

31 Tuple, 

32 Type, 

33 Union, 

34 cast, 

35) 

36 

37import google.protobuf 

38from google.api_core import client_options as client_options_lib 

39from google.api_core import exceptions as core_exceptions 

40from google.api_core import gapic_v1 

41from google.api_core import retry as retries 

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

43from google.auth.exceptions import MutualTLSChannelError # type: ignore 

44from google.auth.transport import mtls # type: ignore 

45from google.auth.transport.grpc import SslCredentials # type: ignore 

46from google.oauth2 import service_account # type: ignore 

47 

48from google.cloud.secretmanager_v1beta1 import gapic_version as package_version 

49 

50try: 

51 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] 

52except AttributeError: # pragma: NO COVER 

53 OptionalRetry = Union[retries.Retry, object, None] # type: ignore 

54 

55try: 

56 from google.api_core import client_logging # type: ignore 

57 

58 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

59except ImportError: # pragma: NO COVER 

60 CLIENT_LOGGING_SUPPORTED = False 

61 

62_LOGGER = std_logging.getLogger(__name__) 

63 

64import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore 

65import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore 

66import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore 

67import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore 

68from google.cloud.location import locations_pb2 # type: ignore 

69 

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

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

72 

73from .transports.base import DEFAULT_CLIENT_INFO, SecretManagerServiceTransport 

74from .transports.grpc import SecretManagerServiceGrpcTransport 

75from .transports.grpc_asyncio import SecretManagerServiceGrpcAsyncIOTransport 

76from .transports.rest import SecretManagerServiceRestTransport 

77 

78 

79class SecretManagerServiceClientMeta(type): 

80 """Metaclass for the SecretManagerService client. 

81 

82 This provides class-level methods for building and retrieving 

83 support objects (e.g. transport) without polluting the client instance 

84 objects. 

85 """ 

86 

87 _transport_registry = OrderedDict() # type: Dict[str, Type[SecretManagerServiceTransport]] 

88 _transport_registry["grpc"] = SecretManagerServiceGrpcTransport 

89 _transport_registry["grpc_asyncio"] = SecretManagerServiceGrpcAsyncIOTransport 

90 _transport_registry["rest"] = SecretManagerServiceRestTransport 

91 

92 def get_transport_class( 

93 cls, 

94 label: Optional[str] = None, 

95 ) -> Type[SecretManagerServiceTransport]: 

96 """Returns an appropriate transport class. 

97 

98 Args: 

99 label: The name of the desired transport. If none is 

100 provided, then the first transport in the registry is used. 

101 

102 Returns: 

103 The transport class to use. 

104 """ 

105 # If a specific transport is requested, return that one. 

106 if label: 

107 return cls._transport_registry[label] 

108 

109 # No transport is requested; return the default (that is, the first one 

110 # in the dictionary). 

111 return next(iter(cls._transport_registry.values())) 

112 

113 

114class SecretManagerServiceClient(metaclass=SecretManagerServiceClientMeta): 

115 """Secret Manager Service 

116 

117 Manages secrets and operations using those secrets. Implements a 

118 REST model with the following objects: 

119 

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

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

122 """ 

123 

124 @staticmethod 

125 def _get_default_mtls_endpoint(api_endpoint): 

126 """Converts api endpoint to mTLS endpoint. 

127 

128 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to 

129 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. 

130 Args: 

131 api_endpoint (Optional[str]): the api endpoint to convert. 

132 Returns: 

133 str: converted mTLS api endpoint. 

134 """ 

135 if not api_endpoint: 

136 return api_endpoint 

137 

138 mtls_endpoint_re = re.compile( 

139 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?" 

140 ) 

141 

142 m = mtls_endpoint_re.match(api_endpoint) 

143 name, mtls, sandbox, googledomain = m.groups() 

144 if mtls or not googledomain: 

145 return api_endpoint 

146 

147 if sandbox: 

148 return api_endpoint.replace( 

149 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

150 ) 

151 

152 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") 

153 

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

155 DEFAULT_ENDPOINT = "secretmanager.googleapis.com" 

156 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

157 DEFAULT_ENDPOINT 

158 ) 

159 

160 _DEFAULT_ENDPOINT_TEMPLATE = "secretmanager.{UNIVERSE_DOMAIN}" 

161 _DEFAULT_UNIVERSE = "googleapis.com" 

162 

163 @staticmethod 

164 def _use_client_cert_effective(): 

165 """Returns whether client certificate should be used for mTLS if the 

166 google-auth version supports should_use_client_cert automatic mTLS enablement. 

167 

168 Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. 

169 

170 Returns: 

171 bool: whether client certificate should be used for mTLS 

172 Raises: 

173 ValueError: (If using a version of google-auth without should_use_client_cert and 

174 GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) 

175 """ 

176 # check if google-auth version supports should_use_client_cert for automatic mTLS enablement 

177 if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER 

178 return mtls.should_use_client_cert() 

179 else: # pragma: NO COVER 

180 # if unsupported, fallback to reading from env var 

181 use_client_cert_str = os.getenv( 

182 "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" 

183 ).lower() 

184 if use_client_cert_str not in ("true", "false"): 

185 raise ValueError( 

186 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" 

187 " either `true` or `false`" 

188 ) 

189 return use_client_cert_str == "true" 

190 

191 @classmethod 

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

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

194 info. 

195 

196 Args: 

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

198 args: Additional arguments to pass to the constructor. 

199 kwargs: Additional arguments to pass to the constructor. 

200 

201 Returns: 

202 SecretManagerServiceClient: The constructed client. 

203 """ 

204 credentials = service_account.Credentials.from_service_account_info(info) 

205 kwargs["credentials"] = credentials 

206 return cls(*args, **kwargs) 

207 

208 @classmethod 

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

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

211 file. 

212 

213 Args: 

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

215 file. 

216 args: Additional arguments to pass to the constructor. 

217 kwargs: Additional arguments to pass to the constructor. 

218 

219 Returns: 

220 SecretManagerServiceClient: The constructed client. 

221 """ 

222 credentials = service_account.Credentials.from_service_account_file(filename) 

223 kwargs["credentials"] = credentials 

224 return cls(*args, **kwargs) 

225 

226 from_service_account_json = from_service_account_file 

227 

228 @property 

229 def transport(self) -> SecretManagerServiceTransport: 

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

231 

232 Returns: 

233 SecretManagerServiceTransport: The transport used by the client 

234 instance. 

235 """ 

236 return self._transport 

237 

238 @staticmethod 

239 def secret_path( 

240 project: str, 

241 secret: str, 

242 ) -> str: 

243 """Returns a fully-qualified secret string.""" 

244 return "projects/{project}/secrets/{secret}".format( 

245 project=project, 

246 secret=secret, 

247 ) 

248 

249 @staticmethod 

250 def parse_secret_path(path: str) -> Dict[str, str]: 

251 """Parses a secret path into its component segments.""" 

252 m = re.match(r"^projects/(?P<project>.+?)/secrets/(?P<secret>.+?)$", path) 

253 return m.groupdict() if m else {} 

254 

255 @staticmethod 

256 def secret_version_path( 

257 project: str, 

258 secret: str, 

259 secret_version: str, 

260 ) -> str: 

261 """Returns a fully-qualified secret_version string.""" 

262 return "projects/{project}/secrets/{secret}/versions/{secret_version}".format( 

263 project=project, 

264 secret=secret, 

265 secret_version=secret_version, 

266 ) 

267 

268 @staticmethod 

269 def parse_secret_version_path(path: str) -> Dict[str, str]: 

270 """Parses a secret_version path into its component segments.""" 

271 m = re.match( 

272 r"^projects/(?P<project>.+?)/secrets/(?P<secret>.+?)/versions/(?P<secret_version>.+?)$", 

273 path, 

274 ) 

275 return m.groupdict() if m else {} 

276 

277 @staticmethod 

278 def common_billing_account_path( 

279 billing_account: str, 

280 ) -> str: 

281 """Returns a fully-qualified billing_account string.""" 

282 return "billingAccounts/{billing_account}".format( 

283 billing_account=billing_account, 

284 ) 

285 

286 @staticmethod 

287 def parse_common_billing_account_path(path: str) -> Dict[str, str]: 

288 """Parse a billing_account path into its component segments.""" 

289 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path) 

290 return m.groupdict() if m else {} 

291 

292 @staticmethod 

293 def common_folder_path( 

294 folder: str, 

295 ) -> str: 

296 """Returns a fully-qualified folder string.""" 

297 return "folders/{folder}".format( 

298 folder=folder, 

299 ) 

300 

301 @staticmethod 

302 def parse_common_folder_path(path: str) -> Dict[str, str]: 

303 """Parse a folder path into its component segments.""" 

304 m = re.match(r"^folders/(?P<folder>.+?)$", path) 

305 return m.groupdict() if m else {} 

306 

307 @staticmethod 

308 def common_organization_path( 

309 organization: str, 

310 ) -> str: 

311 """Returns a fully-qualified organization string.""" 

312 return "organizations/{organization}".format( 

313 organization=organization, 

314 ) 

315 

316 @staticmethod 

317 def parse_common_organization_path(path: str) -> Dict[str, str]: 

318 """Parse a organization path into its component segments.""" 

319 m = re.match(r"^organizations/(?P<organization>.+?)$", path) 

320 return m.groupdict() if m else {} 

321 

322 @staticmethod 

323 def common_project_path( 

324 project: str, 

325 ) -> str: 

326 """Returns a fully-qualified project string.""" 

327 return "projects/{project}".format( 

328 project=project, 

329 ) 

330 

331 @staticmethod 

332 def parse_common_project_path(path: str) -> Dict[str, str]: 

333 """Parse a project path into its component segments.""" 

334 m = re.match(r"^projects/(?P<project>.+?)$", path) 

335 return m.groupdict() if m else {} 

336 

337 @staticmethod 

338 def common_location_path( 

339 project: str, 

340 location: str, 

341 ) -> str: 

342 """Returns a fully-qualified location string.""" 

343 return "projects/{project}/locations/{location}".format( 

344 project=project, 

345 location=location, 

346 ) 

347 

348 @staticmethod 

349 def parse_common_location_path(path: str) -> Dict[str, str]: 

350 """Parse a location path into its component segments.""" 

351 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path) 

352 return m.groupdict() if m else {} 

353 

354 @classmethod 

355 def get_mtls_endpoint_and_cert_source( 

356 cls, client_options: Optional[client_options_lib.ClientOptions] = None 

357 ): 

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

359 

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

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

362 client cert source is None. 

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

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

365 source is None. 

366 

367 The API endpoint is determined in the following order: 

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

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

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

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

372 use the default API endpoint. 

373 

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

375 

376 Args: 

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

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

379 in this method. 

380 

381 Returns: 

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

383 client cert source to use. 

384 

385 Raises: 

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

387 """ 

388 

389 warnings.warn( 

390 "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", 

391 DeprecationWarning, 

392 ) 

393 if client_options is None: 

394 client_options = client_options_lib.ClientOptions() 

395 use_client_cert = SecretManagerServiceClient._use_client_cert_effective() 

396 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") 

397 if use_mtls_endpoint not in ("auto", "never", "always"): 

398 raise MutualTLSChannelError( 

399 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" 

400 ) 

401 

402 # Figure out the client cert source to use. 

403 client_cert_source = None 

404 if use_client_cert: 

405 if client_options.client_cert_source: 

406 client_cert_source = client_options.client_cert_source 

407 elif mtls.has_default_client_cert_source(): 

408 client_cert_source = mtls.default_client_cert_source() 

409 

410 # Figure out which api endpoint to use. 

411 if client_options.api_endpoint is not None: 

412 api_endpoint = client_options.api_endpoint 

413 elif use_mtls_endpoint == "always" or ( 

414 use_mtls_endpoint == "auto" and client_cert_source 

415 ): 

416 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

417 else: 

418 api_endpoint = cls.DEFAULT_ENDPOINT 

419 

420 return api_endpoint, client_cert_source 

421 

422 @staticmethod 

423 def _read_environment_variables(): 

424 """Returns the environment variables used by the client. 

425 

426 Returns: 

427 Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, 

428 GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. 

429 

430 Raises: 

431 ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not 

432 any of ["true", "false"]. 

433 google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT 

434 is not any of ["auto", "never", "always"]. 

435 """ 

436 use_client_cert = SecretManagerServiceClient._use_client_cert_effective() 

437 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() 

438 universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") 

439 if use_mtls_endpoint not in ("auto", "never", "always"): 

440 raise MutualTLSChannelError( 

441 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" 

442 ) 

443 return use_client_cert, use_mtls_endpoint, universe_domain_env 

444 

445 @staticmethod 

446 def _get_client_cert_source(provided_cert_source, use_cert_flag): 

447 """Return the client cert source to be used by the client. 

448 

449 Args: 

450 provided_cert_source (bytes): The client certificate source provided. 

451 use_cert_flag (bool): A flag indicating whether to use the client certificate. 

452 

453 Returns: 

454 bytes or None: The client cert source to be used by the client. 

455 """ 

456 client_cert_source = None 

457 if use_cert_flag: 

458 if provided_cert_source: 

459 client_cert_source = provided_cert_source 

460 elif mtls.has_default_client_cert_source(): 

461 client_cert_source = mtls.default_client_cert_source() 

462 return client_cert_source 

463 

464 @staticmethod 

465 def _get_api_endpoint( 

466 api_override, client_cert_source, universe_domain, use_mtls_endpoint 

467 ): 

468 """Return the API endpoint used by the client. 

469 

470 Args: 

471 api_override (str): The API endpoint override. If specified, this is always 

472 the return value of this function and the other arguments are not used. 

473 client_cert_source (bytes): The client certificate source used by the client. 

474 universe_domain (str): The universe domain used by the client. 

475 use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. 

476 Possible values are "always", "auto", or "never". 

477 

478 Returns: 

479 str: The API endpoint to be used by the client. 

480 """ 

481 if api_override is not None: 

482 api_endpoint = api_override 

483 elif use_mtls_endpoint == "always" or ( 

484 use_mtls_endpoint == "auto" and client_cert_source 

485 ): 

486 _default_universe = SecretManagerServiceClient._DEFAULT_UNIVERSE 

487 if universe_domain != _default_universe: 

488 raise MutualTLSChannelError( 

489 f"mTLS is not supported in any universe other than {_default_universe}." 

490 ) 

491 api_endpoint = SecretManagerServiceClient.DEFAULT_MTLS_ENDPOINT 

492 else: 

493 api_endpoint = SecretManagerServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( 

494 UNIVERSE_DOMAIN=universe_domain 

495 ) 

496 return api_endpoint 

497 

498 @staticmethod 

499 def _get_universe_domain( 

500 client_universe_domain: Optional[str], universe_domain_env: Optional[str] 

501 ) -> str: 

502 """Return the universe domain used by the client. 

503 

504 Args: 

505 client_universe_domain (Optional[str]): The universe domain configured via the client options. 

506 universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. 

507 

508 Returns: 

509 str: The universe domain to be used by the client. 

510 

511 Raises: 

512 ValueError: If the universe domain is an empty string. 

513 """ 

514 universe_domain = SecretManagerServiceClient._DEFAULT_UNIVERSE 

515 if client_universe_domain is not None: 

516 universe_domain = client_universe_domain 

517 elif universe_domain_env is not None: 

518 universe_domain = universe_domain_env 

519 if len(universe_domain.strip()) == 0: 

520 raise ValueError("Universe Domain cannot be an empty string.") 

521 return universe_domain 

522 

523 def _validate_universe_domain(self): 

524 """Validates client's and credentials' universe domains are consistent. 

525 

526 Returns: 

527 bool: True iff the configured universe domain is valid. 

528 

529 Raises: 

530 ValueError: If the configured universe domain is not valid. 

531 """ 

532 

533 # NOTE (b/349488459): universe validation is disabled until further notice. 

534 return True 

535 

536 def _add_cred_info_for_auth_errors( 

537 self, error: core_exceptions.GoogleAPICallError 

538 ) -> None: 

539 """Adds credential info string to error details for 401/403/404 errors. 

540 

541 Args: 

542 error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. 

543 """ 

544 if error.code not in [ 

545 HTTPStatus.UNAUTHORIZED, 

546 HTTPStatus.FORBIDDEN, 

547 HTTPStatus.NOT_FOUND, 

548 ]: 

549 return 

550 

551 cred = self._transport._credentials 

552 

553 # get_cred_info is only available in google-auth>=2.35.0 

554 if not hasattr(cred, "get_cred_info"): 

555 return 

556 

557 # ignore the type check since pypy test fails when get_cred_info 

558 # is not available 

559 cred_info = cred.get_cred_info() # type: ignore 

560 if cred_info and hasattr(error._details, "append"): 

561 error._details.append(json.dumps(cred_info)) 

562 

563 @property 

564 def api_endpoint(self): 

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

566 

567 Returns: 

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

569 """ 

570 return self._api_endpoint 

571 

572 @property 

573 def universe_domain(self) -> str: 

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

575 

576 Returns: 

577 str: The universe domain used by the client instance. 

578 """ 

579 return self._universe_domain 

580 

581 def __init__( 

582 self, 

583 *, 

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

585 transport: Optional[ 

586 Union[ 

587 str, 

588 SecretManagerServiceTransport, 

589 Callable[..., SecretManagerServiceTransport], 

590 ] 

591 ] = None, 

592 client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, 

593 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

594 ) -> None: 

595 """Instantiates the secret manager service client. 

596 

597 Args: 

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

599 authorization credentials to attach to requests. These 

600 credentials identify the application to the service; if none 

601 are specified, the client will attempt to ascertain the 

602 credentials from the environment. 

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

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

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

606 arguments as used in the SecretManagerServiceTransport constructor. 

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

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

609 Custom options for the client. 

610 

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

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

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

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

615 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment 

616 variable, which have one of the following values: 

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

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

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

620 the default value). 

621 

622 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

624 to provide a client certificate for mTLS transport. If 

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

626 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

627 set, no client certificate will be used. 

628 

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

630 default "googleapis.com" universe. Note that the ``api_endpoint`` 

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

632 currently not supported for mTLS. 

633 

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

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

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

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

638 your own client library. 

639 

640 Raises: 

641 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 

642 creation failed for any reason. 

643 """ 

644 self._client_options = client_options 

645 if isinstance(self._client_options, dict): 

646 self._client_options = client_options_lib.from_dict(self._client_options) 

647 if self._client_options is None: 

648 self._client_options = client_options_lib.ClientOptions() 

649 self._client_options = cast( 

650 client_options_lib.ClientOptions, self._client_options 

651 ) 

652 

653 universe_domain_opt = getattr(self._client_options, "universe_domain", None) 

654 

655 self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( 

656 SecretManagerServiceClient._read_environment_variables() 

657 ) 

658 self._client_cert_source = SecretManagerServiceClient._get_client_cert_source( 

659 self._client_options.client_cert_source, self._use_client_cert 

660 ) 

661 self._universe_domain = SecretManagerServiceClient._get_universe_domain( 

662 universe_domain_opt, self._universe_domain_env 

663 ) 

664 self._api_endpoint = None # updated below, depending on `transport` 

665 

666 # Initialize the universe domain validation. 

667 self._is_universe_domain_valid = False 

668 

669 if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER 

670 # Setup logging. 

671 client_logging.initialize_logging() 

672 

673 api_key_value = getattr(self._client_options, "api_key", None) 

674 if api_key_value and credentials: 

675 raise ValueError( 

676 "client_options.api_key and credentials are mutually exclusive" 

677 ) 

678 

679 # Save or instantiate the transport. 

680 # Ordinarily, we provide the transport, but allowing a custom transport 

681 # instance provides an extensibility point for unusual situations. 

682 transport_provided = isinstance(transport, SecretManagerServiceTransport) 

683 if transport_provided: 

684 # transport is a SecretManagerServiceTransport instance. 

685 if credentials or self._client_options.credentials_file or api_key_value: 

686 raise ValueError( 

687 "When providing a transport instance, " 

688 "provide its credentials directly." 

689 ) 

690 if self._client_options.scopes: 

691 raise ValueError( 

692 "When providing a transport instance, provide its scopes directly." 

693 ) 

694 self._transport = cast(SecretManagerServiceTransport, transport) 

695 self._api_endpoint = self._transport.host 

696 

697 self._api_endpoint = ( 

698 self._api_endpoint 

699 or SecretManagerServiceClient._get_api_endpoint( 

700 self._client_options.api_endpoint, 

701 self._client_cert_source, 

702 self._universe_domain, 

703 self._use_mtls_endpoint, 

704 ) 

705 ) 

706 

707 if not transport_provided: 

708 import google.auth._default # type: ignore 

709 

710 if api_key_value and hasattr( 

711 google.auth._default, "get_api_key_credentials" 

712 ): 

713 credentials = google.auth._default.get_api_key_credentials( 

714 api_key_value 

715 ) 

716 

717 transport_init: Union[ 

718 Type[SecretManagerServiceTransport], 

719 Callable[..., SecretManagerServiceTransport], 

720 ] = ( 

721 SecretManagerServiceClient.get_transport_class(transport) 

722 if isinstance(transport, str) or transport is None 

723 else cast(Callable[..., SecretManagerServiceTransport], transport) 

724 ) 

725 # initialize with the provided callable or the passed in class 

726 self._transport = transport_init( 

727 credentials=credentials, 

728 credentials_file=self._client_options.credentials_file, 

729 host=self._api_endpoint, 

730 scopes=self._client_options.scopes, 

731 client_cert_source_for_mtls=self._client_cert_source, 

732 quota_project_id=self._client_options.quota_project_id, 

733 client_info=client_info, 

734 always_use_jwt_access=True, 

735 api_audience=self._client_options.api_audience, 

736 ) 

737 

738 if "async" not in str(self._transport): 

739 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

740 std_logging.DEBUG 

741 ): # pragma: NO COVER 

742 _LOGGER.debug( 

743 "Created client `google.cloud.secrets_v1beta1.SecretManagerServiceClient`.", 

744 extra={ 

745 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService", 

746 "universeDomain": getattr( 

747 self._transport._credentials, "universe_domain", "" 

748 ), 

749 "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", 

750 "credentialsInfo": getattr( 

751 self.transport._credentials, "get_cred_info", lambda: None 

752 )(), 

753 } 

754 if hasattr(self._transport, "_credentials") 

755 else { 

756 "serviceName": "google.cloud.secrets.v1beta1.SecretManagerService", 

757 "credentialsType": None, 

758 }, 

759 ) 

760 

761 def list_secrets( 

762 self, 

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

764 *, 

765 parent: Optional[str] = None, 

766 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

768 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

769 ) -> pagers.ListSecretsPager: 

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

771 

772 .. code-block:: python 

773 

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

775 # code template only. 

776 # It will require modifications to work: 

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

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

779 # client as shown in: 

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

781 from google.cloud import secretmanager_v1beta1 

782 

783 def sample_list_secrets(): 

784 # Create a client 

785 client = secretmanager_v1beta1.SecretManagerServiceClient() 

786 

787 # Initialize request argument(s) 

788 request = secretmanager_v1beta1.ListSecretsRequest( 

789 parent="parent_value", 

790 ) 

791 

792 # Make the request 

793 page_result = client.list_secrets(request=request) 

794 

795 # Handle the response 

796 for response in page_result: 

797 print(response) 

798 

799 Args: 

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

801 The request object. Request message for 

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

803 parent (str): 

804 Required. The resource name of the project associated 

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

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

807 

808 This corresponds to the ``parent`` field 

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

810 should not be set. 

811 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

812 should be retried. 

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

814 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

815 sent along with the request as metadata. Normally, each value must be of type `str`, 

816 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

817 be of type `bytes`. 

818 

819 Returns: 

820 google.cloud.secretmanager_v1beta1.services.secret_manager_service.pagers.ListSecretsPager: 

821 Response message for 

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

823 

824 Iterating over this object will yield results and 

825 resolve additional pages automatically. 

826 

827 """ 

828 # Create or coerce a protobuf request object. 

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

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

831 flattened_params = [parent] 

832 has_flattened_params = ( 

833 len([param for param in flattened_params if param is not None]) > 0 

834 ) 

835 if request is not None and has_flattened_params: 

836 raise ValueError( 

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

838 "the individual field arguments should be set." 

839 ) 

840 

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

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

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

844 request = service.ListSecretsRequest(request) 

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

846 # request, apply these. 

847 if parent is not None: 

848 request.parent = parent 

849 

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

851 # and friendly error handling. 

852 rpc = self._transport._wrapped_methods[self._transport.list_secrets] 

853 

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

855 # add these here. 

856 metadata = tuple(metadata) + ( 

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

858 ) 

859 

860 # Validate the universe domain. 

861 self._validate_universe_domain() 

862 

863 # Send the request. 

864 response = rpc( 

865 request, 

866 retry=retry, 

867 timeout=timeout, 

868 metadata=metadata, 

869 ) 

870 

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

872 # an `__iter__` convenience method. 

873 response = pagers.ListSecretsPager( 

874 method=rpc, 

875 request=request, 

876 response=response, 

877 retry=retry, 

878 timeout=timeout, 

879 metadata=metadata, 

880 ) 

881 

882 # Done; return the response. 

883 return response 

884 

885 def create_secret( 

886 self, 

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

888 *, 

889 parent: Optional[str] = None, 

890 secret_id: Optional[str] = None, 

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

892 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

894 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

895 ) -> resources.Secret: 

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

897 containing no 

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

899 

900 .. code-block:: python 

901 

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

903 # code template only. 

904 # It will require modifications to work: 

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

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

907 # client as shown in: 

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

909 from google.cloud import secretmanager_v1beta1 

910 

911 def sample_create_secret(): 

912 # Create a client 

913 client = secretmanager_v1beta1.SecretManagerServiceClient() 

914 

915 # Initialize request argument(s) 

916 request = secretmanager_v1beta1.CreateSecretRequest( 

917 parent="parent_value", 

918 secret_id="secret_id_value", 

919 ) 

920 

921 # Make the request 

922 response = client.create_secret(request=request) 

923 

924 # Handle the response 

925 print(response) 

926 

927 Args: 

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

929 The request object. Request message for 

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

931 parent (str): 

932 Required. The resource name of the project to associate 

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

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

935 

936 This corresponds to the ``parent`` field 

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

938 should not be set. 

939 secret_id (str): 

940 Required. This must be unique within the project. 

941 

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

943 characters and can contain uppercase and lowercase 

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

945 (``_``) characters. 

946 

947 This corresponds to the ``secret_id`` field 

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

949 should not be set. 

950 secret (google.cloud.secretmanager_v1beta1.types.Secret): 

951 Required. A 

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

953 initial field values. 

954 

955 This corresponds to the ``secret`` field 

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

957 should not be set. 

958 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

959 should be retried. 

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

961 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

962 sent along with the request as metadata. Normally, each value must be of type `str`, 

963 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

964 be of type `bytes`. 

965 

966 Returns: 

967 google.cloud.secretmanager_v1beta1.types.Secret: 

968 A [Secret][google.cloud.secrets.v1beta1.Secret] is a logical secret whose 

969 value and versions can be accessed. 

970 

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

972 made up of zero or more 

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

974 that represent the secret data. 

975 

976 """ 

977 # Create or coerce a protobuf request object. 

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

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

980 flattened_params = [parent, secret_id, secret] 

981 has_flattened_params = ( 

982 len([param for param in flattened_params if param is not None]) > 0 

983 ) 

984 if request is not None and has_flattened_params: 

985 raise ValueError( 

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

987 "the individual field arguments should be set." 

988 ) 

989 

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

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

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

993 request = service.CreateSecretRequest(request) 

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

995 # request, apply these. 

996 if parent is not None: 

997 request.parent = parent 

998 if secret_id is not None: 

999 request.secret_id = secret_id 

1000 if secret is not None: 

1001 request.secret = secret 

1002 

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

1004 # and friendly error handling. 

1005 rpc = self._transport._wrapped_methods[self._transport.create_secret] 

1006 

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

1008 # add these here. 

1009 metadata = tuple(metadata) + ( 

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

1011 ) 

1012 

1013 # Validate the universe domain. 

1014 self._validate_universe_domain() 

1015 

1016 # Send the request. 

1017 response = rpc( 

1018 request, 

1019 retry=retry, 

1020 timeout=timeout, 

1021 metadata=metadata, 

1022 ) 

1023 

1024 # Done; return the response. 

1025 return response 

1026 

1027 def add_secret_version( 

1028 self, 

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

1030 *, 

1031 parent: Optional[str] = None, 

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

1033 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1035 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1036 ) -> resources.SecretVersion: 

1037 r"""Creates a new 

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

1039 containing secret data and attaches it to an existing 

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

1041 

1042 .. code-block:: python 

1043 

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

1045 # code template only. 

1046 # It will require modifications to work: 

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

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

1049 # client as shown in: 

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

1051 from google.cloud import secretmanager_v1beta1 

1052 

1053 def sample_add_secret_version(): 

1054 # Create a client 

1055 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1056 

1057 # Initialize request argument(s) 

1058 request = secretmanager_v1beta1.AddSecretVersionRequest( 

1059 parent="parent_value", 

1060 ) 

1061 

1062 # Make the request 

1063 response = client.add_secret_version(request=request) 

1064 

1065 # Handle the response 

1066 print(response) 

1067 

1068 Args: 

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

1070 The request object. Request message for 

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

1072 parent (str): 

1073 Required. The resource name of the 

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

1075 associate with the 

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

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

1078 

1079 This corresponds to the ``parent`` field 

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

1081 should not be set. 

1082 payload (google.cloud.secretmanager_v1beta1.types.SecretPayload): 

1083 Required. The secret payload of the 

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

1085 

1086 This corresponds to the ``payload`` field 

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

1088 should not be set. 

1089 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1090 should be retried. 

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

1092 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1093 sent along with the request as metadata. Normally, each value must be of type `str`, 

1094 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1095 be of type `bytes`. 

1096 

1097 Returns: 

1098 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1099 A secret version resource in the 

1100 Secret Manager API. 

1101 

1102 """ 

1103 # Create or coerce a protobuf request object. 

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

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

1106 flattened_params = [parent, payload] 

1107 has_flattened_params = ( 

1108 len([param for param in flattened_params if param is not None]) > 0 

1109 ) 

1110 if request is not None and has_flattened_params: 

1111 raise ValueError( 

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

1113 "the individual field arguments should be set." 

1114 ) 

1115 

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

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

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

1119 request = service.AddSecretVersionRequest(request) 

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

1121 # request, apply these. 

1122 if parent is not None: 

1123 request.parent = parent 

1124 if payload is not None: 

1125 request.payload = payload 

1126 

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

1128 # and friendly error handling. 

1129 rpc = self._transport._wrapped_methods[self._transport.add_secret_version] 

1130 

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

1132 # add these here. 

1133 metadata = tuple(metadata) + ( 

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

1135 ) 

1136 

1137 # Validate the universe domain. 

1138 self._validate_universe_domain() 

1139 

1140 # Send the request. 

1141 response = rpc( 

1142 request, 

1143 retry=retry, 

1144 timeout=timeout, 

1145 metadata=metadata, 

1146 ) 

1147 

1148 # Done; return the response. 

1149 return response 

1150 

1151 def get_secret( 

1152 self, 

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

1154 *, 

1155 name: Optional[str] = None, 

1156 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1158 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1159 ) -> resources.Secret: 

1160 r"""Gets metadata for a given 

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

1162 

1163 .. code-block:: python 

1164 

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

1166 # code template only. 

1167 # It will require modifications to work: 

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

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

1170 # client as shown in: 

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

1172 from google.cloud import secretmanager_v1beta1 

1173 

1174 def sample_get_secret(): 

1175 # Create a client 

1176 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1177 

1178 # Initialize request argument(s) 

1179 request = secretmanager_v1beta1.GetSecretRequest( 

1180 name="name_value", 

1181 ) 

1182 

1183 # Make the request 

1184 response = client.get_secret(request=request) 

1185 

1186 # Handle the response 

1187 print(response) 

1188 

1189 Args: 

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

1191 The request object. Request message for 

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

1193 name (str): 

1194 Required. The resource name of the 

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

1196 format ``projects/*/secrets/*``. 

1197 

1198 This corresponds to the ``name`` field 

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

1200 should not be set. 

1201 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1202 should be retried. 

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

1204 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1205 sent along with the request as metadata. Normally, each value must be of type `str`, 

1206 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1207 be of type `bytes`. 

1208 

1209 Returns: 

1210 google.cloud.secretmanager_v1beta1.types.Secret: 

1211 A [Secret][google.cloud.secrets.v1beta1.Secret] is a logical secret whose 

1212 value and versions can be accessed. 

1213 

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

1215 made up of zero or more 

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

1217 that represent the secret data. 

1218 

1219 """ 

1220 # Create or coerce a protobuf request object. 

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

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

1223 flattened_params = [name] 

1224 has_flattened_params = ( 

1225 len([param for param in flattened_params if param is not None]) > 0 

1226 ) 

1227 if request is not None and has_flattened_params: 

1228 raise ValueError( 

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

1230 "the individual field arguments should be set." 

1231 ) 

1232 

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

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

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

1236 request = service.GetSecretRequest(request) 

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

1238 # request, apply these. 

1239 if name is not None: 

1240 request.name = name 

1241 

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

1243 # and friendly error handling. 

1244 rpc = self._transport._wrapped_methods[self._transport.get_secret] 

1245 

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

1247 # add these here. 

1248 metadata = tuple(metadata) + ( 

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

1250 ) 

1251 

1252 # Validate the universe domain. 

1253 self._validate_universe_domain() 

1254 

1255 # Send the request. 

1256 response = rpc( 

1257 request, 

1258 retry=retry, 

1259 timeout=timeout, 

1260 metadata=metadata, 

1261 ) 

1262 

1263 # Done; return the response. 

1264 return response 

1265 

1266 def update_secret( 

1267 self, 

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

1269 *, 

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

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

1272 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1274 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1275 ) -> resources.Secret: 

1276 r"""Updates metadata of an existing 

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

1278 

1279 .. code-block:: python 

1280 

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

1282 # code template only. 

1283 # It will require modifications to work: 

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

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

1286 # client as shown in: 

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

1288 from google.cloud import secretmanager_v1beta1 

1289 

1290 def sample_update_secret(): 

1291 # Create a client 

1292 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1293 

1294 # Initialize request argument(s) 

1295 request = secretmanager_v1beta1.UpdateSecretRequest( 

1296 ) 

1297 

1298 # Make the request 

1299 response = client.update_secret(request=request) 

1300 

1301 # Handle the response 

1302 print(response) 

1303 

1304 Args: 

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

1306 The request object. Request message for 

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

1308 secret (google.cloud.secretmanager_v1beta1.types.Secret): 

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

1310 with updated field values. 

1311 

1312 This corresponds to the ``secret`` field 

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

1314 should not be set. 

1315 update_mask (google.protobuf.field_mask_pb2.FieldMask): 

1316 Required. Specifies the fields to be 

1317 updated. 

1318 

1319 This corresponds to the ``update_mask`` field 

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

1321 should not be set. 

1322 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1323 should be retried. 

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

1325 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1326 sent along with the request as metadata. Normally, each value must be of type `str`, 

1327 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1328 be of type `bytes`. 

1329 

1330 Returns: 

1331 google.cloud.secretmanager_v1beta1.types.Secret: 

1332 A [Secret][google.cloud.secrets.v1beta1.Secret] is a logical secret whose 

1333 value and versions can be accessed. 

1334 

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

1336 made up of zero or more 

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

1338 that represent the secret data. 

1339 

1340 """ 

1341 # Create or coerce a protobuf request object. 

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

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

1344 flattened_params = [secret, update_mask] 

1345 has_flattened_params = ( 

1346 len([param for param in flattened_params if param is not None]) > 0 

1347 ) 

1348 if request is not None and has_flattened_params: 

1349 raise ValueError( 

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

1351 "the individual field arguments should be set." 

1352 ) 

1353 

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

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

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

1357 request = service.UpdateSecretRequest(request) 

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

1359 # request, apply these. 

1360 if secret is not None: 

1361 request.secret = secret 

1362 if update_mask is not None: 

1363 request.update_mask = update_mask 

1364 

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

1366 # and friendly error handling. 

1367 rpc = self._transport._wrapped_methods[self._transport.update_secret] 

1368 

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

1370 # add these here. 

1371 metadata = tuple(metadata) + ( 

1372 gapic_v1.routing_header.to_grpc_metadata( 

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

1374 ), 

1375 ) 

1376 

1377 # Validate the universe domain. 

1378 self._validate_universe_domain() 

1379 

1380 # Send the request. 

1381 response = rpc( 

1382 request, 

1383 retry=retry, 

1384 timeout=timeout, 

1385 metadata=metadata, 

1386 ) 

1387 

1388 # Done; return the response. 

1389 return response 

1390 

1391 def delete_secret( 

1392 self, 

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

1394 *, 

1395 name: Optional[str] = None, 

1396 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1398 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1399 ) -> None: 

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

1401 

1402 .. code-block:: python 

1403 

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

1405 # code template only. 

1406 # It will require modifications to work: 

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

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

1409 # client as shown in: 

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

1411 from google.cloud import secretmanager_v1beta1 

1412 

1413 def sample_delete_secret(): 

1414 # Create a client 

1415 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1416 

1417 # Initialize request argument(s) 

1418 request = secretmanager_v1beta1.DeleteSecretRequest( 

1419 name="name_value", 

1420 ) 

1421 

1422 # Make the request 

1423 client.delete_secret(request=request) 

1424 

1425 Args: 

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

1427 The request object. Request message for 

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

1429 name (str): 

1430 Required. The resource name of the 

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

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

1433 

1434 This corresponds to the ``name`` field 

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

1436 should not be set. 

1437 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1438 should be retried. 

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

1440 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1441 sent along with the request as metadata. Normally, each value must be of type `str`, 

1442 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1443 be of type `bytes`. 

1444 """ 

1445 # Create or coerce a protobuf request object. 

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

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

1448 flattened_params = [name] 

1449 has_flattened_params = ( 

1450 len([param for param in flattened_params if param is not None]) > 0 

1451 ) 

1452 if request is not None and has_flattened_params: 

1453 raise ValueError( 

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

1455 "the individual field arguments should be set." 

1456 ) 

1457 

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

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

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

1461 request = service.DeleteSecretRequest(request) 

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

1463 # request, apply these. 

1464 if name is not None: 

1465 request.name = name 

1466 

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

1468 # and friendly error handling. 

1469 rpc = self._transport._wrapped_methods[self._transport.delete_secret] 

1470 

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

1472 # add these here. 

1473 metadata = tuple(metadata) + ( 

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

1475 ) 

1476 

1477 # Validate the universe domain. 

1478 self._validate_universe_domain() 

1479 

1480 # Send the request. 

1481 rpc( 

1482 request, 

1483 retry=retry, 

1484 timeout=timeout, 

1485 metadata=metadata, 

1486 ) 

1487 

1488 def list_secret_versions( 

1489 self, 

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

1491 *, 

1492 parent: Optional[str] = None, 

1493 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1495 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1496 ) -> pagers.ListSecretVersionsPager: 

1497 r"""Lists 

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

1499 This call does not return secret data. 

1500 

1501 .. code-block:: python 

1502 

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

1504 # code template only. 

1505 # It will require modifications to work: 

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

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

1508 # client as shown in: 

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

1510 from google.cloud import secretmanager_v1beta1 

1511 

1512 def sample_list_secret_versions(): 

1513 # Create a client 

1514 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1515 

1516 # Initialize request argument(s) 

1517 request = secretmanager_v1beta1.ListSecretVersionsRequest( 

1518 parent="parent_value", 

1519 ) 

1520 

1521 # Make the request 

1522 page_result = client.list_secret_versions(request=request) 

1523 

1524 # Handle the response 

1525 for response in page_result: 

1526 print(response) 

1527 

1528 Args: 

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

1530 The request object. Request message for 

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

1532 parent (str): 

1533 Required. The resource name of the 

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

1535 with the 

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

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

1538 

1539 This corresponds to the ``parent`` field 

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

1541 should not be set. 

1542 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1543 should be retried. 

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

1545 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1546 sent along with the request as metadata. Normally, each value must be of type `str`, 

1547 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1548 be of type `bytes`. 

1549 

1550 Returns: 

1551 google.cloud.secretmanager_v1beta1.services.secret_manager_service.pagers.ListSecretVersionsPager: 

1552 Response message for 

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

1554 

1555 Iterating over this object will yield results and 

1556 resolve additional pages automatically. 

1557 

1558 """ 

1559 # Create or coerce a protobuf request object. 

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

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

1562 flattened_params = [parent] 

1563 has_flattened_params = ( 

1564 len([param for param in flattened_params if param is not None]) > 0 

1565 ) 

1566 if request is not None and has_flattened_params: 

1567 raise ValueError( 

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

1569 "the individual field arguments should be set." 

1570 ) 

1571 

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

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

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

1575 request = service.ListSecretVersionsRequest(request) 

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

1577 # request, apply these. 

1578 if parent is not None: 

1579 request.parent = parent 

1580 

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

1582 # and friendly error handling. 

1583 rpc = self._transport._wrapped_methods[self._transport.list_secret_versions] 

1584 

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

1586 # add these here. 

1587 metadata = tuple(metadata) + ( 

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

1589 ) 

1590 

1591 # Validate the universe domain. 

1592 self._validate_universe_domain() 

1593 

1594 # Send the request. 

1595 response = rpc( 

1596 request, 

1597 retry=retry, 

1598 timeout=timeout, 

1599 metadata=metadata, 

1600 ) 

1601 

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

1603 # an `__iter__` convenience method. 

1604 response = pagers.ListSecretVersionsPager( 

1605 method=rpc, 

1606 request=request, 

1607 response=response, 

1608 retry=retry, 

1609 timeout=timeout, 

1610 metadata=metadata, 

1611 ) 

1612 

1613 # Done; return the response. 

1614 return response 

1615 

1616 def get_secret_version( 

1617 self, 

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

1619 *, 

1620 name: Optional[str] = None, 

1621 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1623 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1624 ) -> resources.SecretVersion: 

1625 r"""Gets metadata for a 

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

1627 

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

1629 ``latest`` 

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

1631 

1632 .. code-block:: python 

1633 

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

1635 # code template only. 

1636 # It will require modifications to work: 

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

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

1639 # client as shown in: 

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

1641 from google.cloud import secretmanager_v1beta1 

1642 

1643 def sample_get_secret_version(): 

1644 # Create a client 

1645 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1646 

1647 # Initialize request argument(s) 

1648 request = secretmanager_v1beta1.GetSecretVersionRequest( 

1649 name="name_value", 

1650 ) 

1651 

1652 # Make the request 

1653 response = client.get_secret_version(request=request) 

1654 

1655 # Handle the response 

1656 print(response) 

1657 

1658 Args: 

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

1660 The request object. Request message for 

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

1662 name (str): 

1663 Required. The resource name of the 

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

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

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

1667 the ``latest`` 

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

1669 

1670 This corresponds to the ``name`` field 

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

1672 should not be set. 

1673 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1674 should be retried. 

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

1676 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1677 sent along with the request as metadata. Normally, each value must be of type `str`, 

1678 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1679 be of type `bytes`. 

1680 

1681 Returns: 

1682 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1683 A secret version resource in the 

1684 Secret Manager API. 

1685 

1686 """ 

1687 # Create or coerce a protobuf request object. 

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

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

1690 flattened_params = [name] 

1691 has_flattened_params = ( 

1692 len([param for param in flattened_params if param is not None]) > 0 

1693 ) 

1694 if request is not None and has_flattened_params: 

1695 raise ValueError( 

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

1697 "the individual field arguments should be set." 

1698 ) 

1699 

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

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

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

1703 request = service.GetSecretVersionRequest(request) 

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

1705 # request, apply these. 

1706 if name is not None: 

1707 request.name = name 

1708 

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

1710 # and friendly error handling. 

1711 rpc = self._transport._wrapped_methods[self._transport.get_secret_version] 

1712 

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

1714 # add these here. 

1715 metadata = tuple(metadata) + ( 

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

1717 ) 

1718 

1719 # Validate the universe domain. 

1720 self._validate_universe_domain() 

1721 

1722 # Send the request. 

1723 response = rpc( 

1724 request, 

1725 retry=retry, 

1726 timeout=timeout, 

1727 metadata=metadata, 

1728 ) 

1729 

1730 # Done; return the response. 

1731 return response 

1732 

1733 def access_secret_version( 

1734 self, 

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

1736 *, 

1737 name: Optional[str] = None, 

1738 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1740 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1741 ) -> service.AccessSecretVersionResponse: 

1742 r"""Accesses a 

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

1744 This call returns the secret data. 

1745 

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

1747 ``latest`` 

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

1749 

1750 .. code-block:: python 

1751 

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

1753 # code template only. 

1754 # It will require modifications to work: 

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

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

1757 # client as shown in: 

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

1759 from google.cloud import secretmanager_v1beta1 

1760 

1761 def sample_access_secret_version(): 

1762 # Create a client 

1763 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1764 

1765 # Initialize request argument(s) 

1766 request = secretmanager_v1beta1.AccessSecretVersionRequest( 

1767 name="name_value", 

1768 ) 

1769 

1770 # Make the request 

1771 response = client.access_secret_version(request=request) 

1772 

1773 # Handle the response 

1774 print(response) 

1775 

1776 Args: 

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

1778 The request object. Request message for 

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

1780 name (str): 

1781 Required. The resource name of the 

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

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

1784 

1785 This corresponds to the ``name`` field 

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

1787 should not be set. 

1788 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1789 should be retried. 

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

1791 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1792 sent along with the request as metadata. Normally, each value must be of type `str`, 

1793 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1794 be of type `bytes`. 

1795 

1796 Returns: 

1797 google.cloud.secretmanager_v1beta1.types.AccessSecretVersionResponse: 

1798 Response message for 

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

1800 

1801 """ 

1802 # Create or coerce a protobuf request object. 

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

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

1805 flattened_params = [name] 

1806 has_flattened_params = ( 

1807 len([param for param in flattened_params if param is not None]) > 0 

1808 ) 

1809 if request is not None and has_flattened_params: 

1810 raise ValueError( 

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

1812 "the individual field arguments should be set." 

1813 ) 

1814 

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

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

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

1818 request = service.AccessSecretVersionRequest(request) 

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

1820 # request, apply these. 

1821 if name is not None: 

1822 request.name = name 

1823 

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

1825 # and friendly error handling. 

1826 rpc = self._transport._wrapped_methods[self._transport.access_secret_version] 

1827 

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

1829 # add these here. 

1830 metadata = tuple(metadata) + ( 

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

1832 ) 

1833 

1834 # Validate the universe domain. 

1835 self._validate_universe_domain() 

1836 

1837 # Send the request. 

1838 response = rpc( 

1839 request, 

1840 retry=retry, 

1841 timeout=timeout, 

1842 metadata=metadata, 

1843 ) 

1844 

1845 # Done; return the response. 

1846 return response 

1847 

1848 def disable_secret_version( 

1849 self, 

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

1851 *, 

1852 name: Optional[str] = None, 

1853 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1855 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1856 ) -> resources.SecretVersion: 

1857 r"""Disables a 

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

1859 

1860 Sets the 

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

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

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

1864 

1865 .. code-block:: python 

1866 

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

1868 # code template only. 

1869 # It will require modifications to work: 

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

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

1872 # client as shown in: 

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

1874 from google.cloud import secretmanager_v1beta1 

1875 

1876 def sample_disable_secret_version(): 

1877 # Create a client 

1878 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1879 

1880 # Initialize request argument(s) 

1881 request = secretmanager_v1beta1.DisableSecretVersionRequest( 

1882 name="name_value", 

1883 ) 

1884 

1885 # Make the request 

1886 response = client.disable_secret_version(request=request) 

1887 

1888 # Handle the response 

1889 print(response) 

1890 

1891 Args: 

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

1893 The request object. Request message for 

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

1895 name (str): 

1896 Required. The resource name of the 

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

1898 to disable in the format 

1899 ``projects/*/secrets/*/versions/*``. 

1900 

1901 This corresponds to the ``name`` field 

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

1903 should not be set. 

1904 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1905 should be retried. 

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

1907 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1908 sent along with the request as metadata. Normally, each value must be of type `str`, 

1909 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1910 be of type `bytes`. 

1911 

1912 Returns: 

1913 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1914 A secret version resource in the 

1915 Secret Manager API. 

1916 

1917 """ 

1918 # Create or coerce a protobuf request object. 

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

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

1921 flattened_params = [name] 

1922 has_flattened_params = ( 

1923 len([param for param in flattened_params if param is not None]) > 0 

1924 ) 

1925 if request is not None and has_flattened_params: 

1926 raise ValueError( 

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

1928 "the individual field arguments should be set." 

1929 ) 

1930 

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

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

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

1934 request = service.DisableSecretVersionRequest(request) 

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

1936 # request, apply these. 

1937 if name is not None: 

1938 request.name = name 

1939 

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

1941 # and friendly error handling. 

1942 rpc = self._transport._wrapped_methods[self._transport.disable_secret_version] 

1943 

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

1945 # add these here. 

1946 metadata = tuple(metadata) + ( 

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

1948 ) 

1949 

1950 # Validate the universe domain. 

1951 self._validate_universe_domain() 

1952 

1953 # Send the request. 

1954 response = rpc( 

1955 request, 

1956 retry=retry, 

1957 timeout=timeout, 

1958 metadata=metadata, 

1959 ) 

1960 

1961 # Done; return the response. 

1962 return response 

1963 

1964 def enable_secret_version( 

1965 self, 

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

1967 *, 

1968 name: Optional[str] = None, 

1969 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1971 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1972 ) -> resources.SecretVersion: 

1973 r"""Enables a 

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

1975 

1976 Sets the 

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

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

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

1980 

1981 .. code-block:: python 

1982 

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

1984 # code template only. 

1985 # It will require modifications to work: 

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

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

1988 # client as shown in: 

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

1990 from google.cloud import secretmanager_v1beta1 

1991 

1992 def sample_enable_secret_version(): 

1993 # Create a client 

1994 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1995 

1996 # Initialize request argument(s) 

1997 request = secretmanager_v1beta1.EnableSecretVersionRequest( 

1998 name="name_value", 

1999 ) 

2000 

2001 # Make the request 

2002 response = client.enable_secret_version(request=request) 

2003 

2004 # Handle the response 

2005 print(response) 

2006 

2007 Args: 

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

2009 The request object. Request message for 

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

2011 name (str): 

2012 Required. The resource name of the 

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

2014 to enable in the format 

2015 ``projects/*/secrets/*/versions/*``. 

2016 

2017 This corresponds to the ``name`` field 

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

2019 should not be set. 

2020 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2021 should be retried. 

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

2023 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2024 sent along with the request as metadata. Normally, each value must be of type `str`, 

2025 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2026 be of type `bytes`. 

2027 

2028 Returns: 

2029 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

2030 A secret version resource in the 

2031 Secret Manager API. 

2032 

2033 """ 

2034 # Create or coerce a protobuf request object. 

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

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

2037 flattened_params = [name] 

2038 has_flattened_params = ( 

2039 len([param for param in flattened_params if param is not None]) > 0 

2040 ) 

2041 if request is not None and has_flattened_params: 

2042 raise ValueError( 

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

2044 "the individual field arguments should be set." 

2045 ) 

2046 

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

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

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

2050 request = service.EnableSecretVersionRequest(request) 

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

2052 # request, apply these. 

2053 if name is not None: 

2054 request.name = name 

2055 

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

2057 # and friendly error handling. 

2058 rpc = self._transport._wrapped_methods[self._transport.enable_secret_version] 

2059 

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

2061 # add these here. 

2062 metadata = tuple(metadata) + ( 

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

2064 ) 

2065 

2066 # Validate the universe domain. 

2067 self._validate_universe_domain() 

2068 

2069 # Send the request. 

2070 response = rpc( 

2071 request, 

2072 retry=retry, 

2073 timeout=timeout, 

2074 metadata=metadata, 

2075 ) 

2076 

2077 # Done; return the response. 

2078 return response 

2079 

2080 def destroy_secret_version( 

2081 self, 

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

2083 *, 

2084 name: Optional[str] = None, 

2085 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2087 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2088 ) -> resources.SecretVersion: 

2089 r"""Destroys a 

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

2091 

2092 Sets the 

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

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

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

2096 and irrevocably destroys the secret data. 

2097 

2098 .. code-block:: python 

2099 

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

2101 # code template only. 

2102 # It will require modifications to work: 

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

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

2105 # client as shown in: 

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

2107 from google.cloud import secretmanager_v1beta1 

2108 

2109 def sample_destroy_secret_version(): 

2110 # Create a client 

2111 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2112 

2113 # Initialize request argument(s) 

2114 request = secretmanager_v1beta1.DestroySecretVersionRequest( 

2115 name="name_value", 

2116 ) 

2117 

2118 # Make the request 

2119 response = client.destroy_secret_version(request=request) 

2120 

2121 # Handle the response 

2122 print(response) 

2123 

2124 Args: 

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

2126 The request object. Request message for 

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

2128 name (str): 

2129 Required. The resource name of the 

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

2131 to destroy in the format 

2132 ``projects/*/secrets/*/versions/*``. 

2133 

2134 This corresponds to the ``name`` field 

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

2136 should not be set. 

2137 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2138 should be retried. 

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

2140 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2141 sent along with the request as metadata. Normally, each value must be of type `str`, 

2142 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2143 be of type `bytes`. 

2144 

2145 Returns: 

2146 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

2147 A secret version resource in the 

2148 Secret Manager API. 

2149 

2150 """ 

2151 # Create or coerce a protobuf request object. 

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

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

2154 flattened_params = [name] 

2155 has_flattened_params = ( 

2156 len([param for param in flattened_params if param is not None]) > 0 

2157 ) 

2158 if request is not None and has_flattened_params: 

2159 raise ValueError( 

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

2161 "the individual field arguments should be set." 

2162 ) 

2163 

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

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

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

2167 request = service.DestroySecretVersionRequest(request) 

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

2169 # request, apply these. 

2170 if name is not None: 

2171 request.name = name 

2172 

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

2174 # and friendly error handling. 

2175 rpc = self._transport._wrapped_methods[self._transport.destroy_secret_version] 

2176 

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

2178 # add these here. 

2179 metadata = tuple(metadata) + ( 

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

2181 ) 

2182 

2183 # Validate the universe domain. 

2184 self._validate_universe_domain() 

2185 

2186 # Send the request. 

2187 response = rpc( 

2188 request, 

2189 retry=retry, 

2190 timeout=timeout, 

2191 metadata=metadata, 

2192 ) 

2193 

2194 # Done; return the response. 

2195 return response 

2196 

2197 def set_iam_policy( 

2198 self, 

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

2200 *, 

2201 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2203 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2204 ) -> policy_pb2.Policy: 

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

2206 any existing policy. 

2207 

2208 Permissions on 

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

2210 enforced according to the policy set on the associated 

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

2212 

2213 .. code-block:: python 

2214 

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

2216 # code template only. 

2217 # It will require modifications to work: 

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

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

2220 # client as shown in: 

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

2222 from google.cloud import secretmanager_v1beta1 

2223 import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore 

2224 

2225 def sample_set_iam_policy(): 

2226 # Create a client 

2227 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2228 

2229 # Initialize request argument(s) 

2230 request = iam_policy_pb2.SetIamPolicyRequest( 

2231 resource="resource_value", 

2232 ) 

2233 

2234 # Make the request 

2235 response = client.set_iam_policy(request=request) 

2236 

2237 # Handle the response 

2238 print(response) 

2239 

2240 Args: 

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

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

2243 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2244 should be retried. 

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

2246 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2247 sent along with the request as metadata. Normally, each value must be of type `str`, 

2248 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2249 be of type `bytes`. 

2250 

2251 Returns: 

2252 google.iam.v1.policy_pb2.Policy: 

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

2254 controls for Google Cloud resources. 

2255 

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

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

2258 Principals can be user accounts, service accounts, 

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

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

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

2262 

2263 For some types of Google Cloud resources, a binding 

2264 can also specify a condition, which is a logical 

2265 expression that allows access to a resource only if 

2266 the expression evaluates to true. A condition can add 

2267 constraints based on attributes of the request, the 

2268 resource, or both. To learn which resources support 

2269 conditions in their IAM policies, see the [IAM 

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

2271 

2272 **JSON example:** 

2273 

2274 :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 }`\ \` 

2275 

2276 **YAML example:** 

2277 

2278 :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`\ \` 

2279 

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

2281 [IAM 

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

2283 

2284 """ 

2285 # Create or coerce a protobuf request object. 

2286 if isinstance(request, dict): 

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

2288 # so it must be constructed via keyword expansion. 

2289 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

2290 elif not request: 

2291 # Null request, just make one. 

2292 request = iam_policy_pb2.SetIamPolicyRequest() 

2293 

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

2295 # and friendly error handling. 

2296 rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] 

2297 

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

2299 # add these here. 

2300 metadata = tuple(metadata) + ( 

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

2302 ) 

2303 

2304 # Validate the universe domain. 

2305 self._validate_universe_domain() 

2306 

2307 # Send the request. 

2308 response = rpc( 

2309 request, 

2310 retry=retry, 

2311 timeout=timeout, 

2312 metadata=metadata, 

2313 ) 

2314 

2315 # Done; return the response. 

2316 return response 

2317 

2318 def get_iam_policy( 

2319 self, 

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

2321 *, 

2322 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2324 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2325 ) -> policy_pb2.Policy: 

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

2327 Returns empty policy if the secret exists and does not 

2328 have a policy set. 

2329 

2330 .. code-block:: python 

2331 

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

2333 # code template only. 

2334 # It will require modifications to work: 

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

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

2337 # client as shown in: 

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

2339 from google.cloud import secretmanager_v1beta1 

2340 import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore 

2341 

2342 def sample_get_iam_policy(): 

2343 # Create a client 

2344 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2345 

2346 # Initialize request argument(s) 

2347 request = iam_policy_pb2.GetIamPolicyRequest( 

2348 resource="resource_value", 

2349 ) 

2350 

2351 # Make the request 

2352 response = client.get_iam_policy(request=request) 

2353 

2354 # Handle the response 

2355 print(response) 

2356 

2357 Args: 

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

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

2360 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2361 should be retried. 

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

2363 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2364 sent along with the request as metadata. Normally, each value must be of type `str`, 

2365 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2366 be of type `bytes`. 

2367 

2368 Returns: 

2369 google.iam.v1.policy_pb2.Policy: 

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

2371 controls for Google Cloud resources. 

2372 

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

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

2375 Principals can be user accounts, service accounts, 

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

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

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

2379 

2380 For some types of Google Cloud resources, a binding 

2381 can also specify a condition, which is a logical 

2382 expression that allows access to a resource only if 

2383 the expression evaluates to true. A condition can add 

2384 constraints based on attributes of the request, the 

2385 resource, or both. To learn which resources support 

2386 conditions in their IAM policies, see the [IAM 

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

2388 

2389 **JSON example:** 

2390 

2391 :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 }`\ \` 

2392 

2393 **YAML example:** 

2394 

2395 :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`\ \` 

2396 

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

2398 [IAM 

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

2400 

2401 """ 

2402 # Create or coerce a protobuf request object. 

2403 if isinstance(request, dict): 

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

2405 # so it must be constructed via keyword expansion. 

2406 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

2407 elif not request: 

2408 # Null request, just make one. 

2409 request = iam_policy_pb2.GetIamPolicyRequest() 

2410 

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

2412 # and friendly error handling. 

2413 rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] 

2414 

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

2416 # add these here. 

2417 metadata = tuple(metadata) + ( 

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

2419 ) 

2420 

2421 # Validate the universe domain. 

2422 self._validate_universe_domain() 

2423 

2424 # Send the request. 

2425 response = rpc( 

2426 request, 

2427 retry=retry, 

2428 timeout=timeout, 

2429 metadata=metadata, 

2430 ) 

2431 

2432 # Done; return the response. 

2433 return response 

2434 

2435 def test_iam_permissions( 

2436 self, 

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

2438 *, 

2439 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2441 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2442 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

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

2445 permissions, not a NOT_FOUND error. 

2446 

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

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

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

2450 warning. 

2451 

2452 .. code-block:: python 

2453 

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

2455 # code template only. 

2456 # It will require modifications to work: 

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

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

2459 # client as shown in: 

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

2461 from google.cloud import secretmanager_v1beta1 

2462 import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore 

2463 

2464 def sample_test_iam_permissions(): 

2465 # Create a client 

2466 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2467 

2468 # Initialize request argument(s) 

2469 request = iam_policy_pb2.TestIamPermissionsRequest( 

2470 resource="resource_value", 

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

2472 ) 

2473 

2474 # Make the request 

2475 response = client.test_iam_permissions(request=request) 

2476 

2477 # Handle the response 

2478 print(response) 

2479 

2480 Args: 

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

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

2483 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2484 should be retried. 

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

2486 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2487 sent along with the request as metadata. Normally, each value must be of type `str`, 

2488 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2489 be of type `bytes`. 

2490 

2491 Returns: 

2492 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: 

2493 Response message for TestIamPermissions method. 

2494 """ 

2495 # Create or coerce a protobuf request object. 

2496 if isinstance(request, dict): 

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

2498 # so it must be constructed via keyword expansion. 

2499 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

2500 elif not request: 

2501 # Null request, just make one. 

2502 request = iam_policy_pb2.TestIamPermissionsRequest() 

2503 

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

2505 # and friendly error handling. 

2506 rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] 

2507 

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

2509 # add these here. 

2510 metadata = tuple(metadata) + ( 

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

2512 ) 

2513 

2514 # Validate the universe domain. 

2515 self._validate_universe_domain() 

2516 

2517 # Send the request. 

2518 response = rpc( 

2519 request, 

2520 retry=retry, 

2521 timeout=timeout, 

2522 metadata=metadata, 

2523 ) 

2524 

2525 # Done; return the response. 

2526 return response 

2527 

2528 def __enter__(self) -> "SecretManagerServiceClient": 

2529 return self 

2530 

2531 def __exit__(self, type, value, traceback): 

2532 """Releases underlying transport's resources. 

2533 

2534 .. warning:: 

2535 ONLY use as a context manager if the transport is NOT shared 

2536 with other clients! Exiting the with block will CLOSE the transport 

2537 and may cause errors in other clients! 

2538 """ 

2539 self.transport.close() 

2540 

2541 def get_location( 

2542 self, 

2543 request: Optional[locations_pb2.GetLocationRequest] = None, 

2544 *, 

2545 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2547 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2548 ) -> locations_pb2.Location: 

2549 r"""Gets information about a location. 

2550 

2551 Args: 

2552 request (:class:`~.location_pb2.GetLocationRequest`): 

2553 The request object. Request message for 

2554 `GetLocation` method. 

2555 retry (google.api_core.retry.Retry): Designation of what errors, 

2556 if any, should be retried. 

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

2558 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2559 sent along with the request as metadata. Normally, each value must be of type `str`, 

2560 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2561 be of type `bytes`. 

2562 Returns: 

2563 ~.location_pb2.Location: 

2564 Location object. 

2565 """ 

2566 # Create or coerce a protobuf request object. 

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

2568 # so it must be constructed via keyword expansion. 

2569 if isinstance(request, dict): 

2570 request = locations_pb2.GetLocationRequest(**request) 

2571 

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

2573 # and friendly error handling. 

2574 rpc = self._transport._wrapped_methods[self._transport.get_location] 

2575 

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

2577 # add these here. 

2578 metadata = tuple(metadata) + ( 

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

2580 ) 

2581 

2582 # Validate the universe domain. 

2583 self._validate_universe_domain() 

2584 

2585 try: 

2586 # Send the request. 

2587 response = rpc( 

2588 request, 

2589 retry=retry, 

2590 timeout=timeout, 

2591 metadata=metadata, 

2592 ) 

2593 

2594 # Done; return the response. 

2595 return response 

2596 except core_exceptions.GoogleAPICallError as e: 

2597 self._add_cred_info_for_auth_errors(e) 

2598 raise e 

2599 

2600 def list_locations( 

2601 self, 

2602 request: Optional[locations_pb2.ListLocationsRequest] = None, 

2603 *, 

2604 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2606 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2607 ) -> locations_pb2.ListLocationsResponse: 

2608 r"""Lists information about the supported locations for this service. 

2609 

2610 Args: 

2611 request (:class:`~.location_pb2.ListLocationsRequest`): 

2612 The request object. Request message for 

2613 `ListLocations` method. 

2614 retry (google.api_core.retry.Retry): Designation of what errors, 

2615 if any, should be retried. 

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

2617 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2618 sent along with the request as metadata. Normally, each value must be of type `str`, 

2619 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2620 be of type `bytes`. 

2621 Returns: 

2622 ~.location_pb2.ListLocationsResponse: 

2623 Response message for ``ListLocations`` method. 

2624 """ 

2625 # Create or coerce a protobuf request object. 

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

2627 # so it must be constructed via keyword expansion. 

2628 if isinstance(request, dict): 

2629 request = locations_pb2.ListLocationsRequest(**request) 

2630 

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

2632 # and friendly error handling. 

2633 rpc = self._transport._wrapped_methods[self._transport.list_locations] 

2634 

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

2636 # add these here. 

2637 metadata = tuple(metadata) + ( 

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

2639 ) 

2640 

2641 # Validate the universe domain. 

2642 self._validate_universe_domain() 

2643 

2644 try: 

2645 # Send the request. 

2646 response = rpc( 

2647 request, 

2648 retry=retry, 

2649 timeout=timeout, 

2650 metadata=metadata, 

2651 ) 

2652 

2653 # Done; return the response. 

2654 return response 

2655 except core_exceptions.GoogleAPICallError as e: 

2656 self._add_cred_info_for_auth_errors(e) 

2657 raise e 

2658 

2659 

2660DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

2661 gapic_version=package_version.__version__ 

2662) 

2663 

2664if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

2665 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

2666 

2667__all__ = ("SecretManagerServiceClient",)