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

474 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# 

16from collections import OrderedDict 

17from http import HTTPStatus 

18import json 

19import logging as std_logging 

20import os 

21import re 

22from typing import ( 

23 Callable, 

24 Dict, 

25 Mapping, 

26 MutableMapping, 

27 MutableSequence, 

28 Optional, 

29 Sequence, 

30 Tuple, 

31 Type, 

32 Union, 

33 cast, 

34) 

35import warnings 

36 

37from google.api_core import client_options as client_options_lib 

38from google.api_core import exceptions as core_exceptions 

39from google.api_core import gapic_v1 

40from google.api_core import retry as retries 

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

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

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

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

45from google.oauth2 import service_account # type: ignore 

46import google.protobuf 

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 

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

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

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

67from google.protobuf import field_mask_pb2 # type: ignore 

68from google.protobuf import timestamp_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 = ( 

88 OrderedDict() 

89 ) # type: Dict[str, Type[SecretManagerServiceTransport]] 

90 _transport_registry["grpc"] = SecretManagerServiceGrpcTransport 

91 _transport_registry["grpc_asyncio"] = SecretManagerServiceGrpcAsyncIOTransport 

92 _transport_registry["rest"] = SecretManagerServiceRestTransport 

93 

94 def get_transport_class( 

95 cls, 

96 label: Optional[str] = None, 

97 ) -> Type[SecretManagerServiceTransport]: 

98 """Returns an appropriate transport class. 

99 

100 Args: 

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

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

103 

104 Returns: 

105 The transport class to use. 

106 """ 

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

108 if label: 

109 return cls._transport_registry[label] 

110 

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

112 # in the dictionary). 

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

114 

115 

116class SecretManagerServiceClient(metaclass=SecretManagerServiceClientMeta): 

117 """Secret Manager Service 

118 

119 Manages secrets and operations using those secrets. Implements a 

120 REST model with the following objects: 

121 

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

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

124 """ 

125 

126 @staticmethod 

127 def _get_default_mtls_endpoint(api_endpoint): 

128 """Converts api endpoint to mTLS endpoint. 

129 

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

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

132 Args: 

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

134 Returns: 

135 str: converted mTLS api endpoint. 

136 """ 

137 if not api_endpoint: 

138 return api_endpoint 

139 

140 mtls_endpoint_re = re.compile( 

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

142 ) 

143 

144 m = mtls_endpoint_re.match(api_endpoint) 

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

146 if mtls or not googledomain: 

147 return api_endpoint 

148 

149 if sandbox: 

150 return api_endpoint.replace( 

151 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

152 ) 

153 

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

155 

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

157 DEFAULT_ENDPOINT = "secretmanager.googleapis.com" 

158 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

159 DEFAULT_ENDPOINT 

160 ) 

161 

162 _DEFAULT_ENDPOINT_TEMPLATE = "secretmanager.{UNIVERSE_DOMAIN}" 

163 _DEFAULT_UNIVERSE = "googleapis.com" 

164 

165 @classmethod 

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

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

168 info. 

169 

170 Args: 

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

172 args: Additional arguments to pass to the constructor. 

173 kwargs: Additional arguments to pass to the constructor. 

174 

175 Returns: 

176 SecretManagerServiceClient: The constructed client. 

177 """ 

178 credentials = service_account.Credentials.from_service_account_info(info) 

179 kwargs["credentials"] = credentials 

180 return cls(*args, **kwargs) 

181 

182 @classmethod 

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

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

185 file. 

186 

187 Args: 

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

189 file. 

190 args: Additional arguments to pass to the constructor. 

191 kwargs: Additional arguments to pass to the constructor. 

192 

193 Returns: 

194 SecretManagerServiceClient: The constructed client. 

195 """ 

196 credentials = service_account.Credentials.from_service_account_file(filename) 

197 kwargs["credentials"] = credentials 

198 return cls(*args, **kwargs) 

199 

200 from_service_account_json = from_service_account_file 

201 

202 @property 

203 def transport(self) -> SecretManagerServiceTransport: 

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

205 

206 Returns: 

207 SecretManagerServiceTransport: The transport used by the client 

208 instance. 

209 """ 

210 return self._transport 

211 

212 @staticmethod 

213 def secret_path( 

214 project: str, 

215 secret: str, 

216 ) -> str: 

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

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

219 project=project, 

220 secret=secret, 

221 ) 

222 

223 @staticmethod 

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

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

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

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

228 

229 @staticmethod 

230 def secret_version_path( 

231 project: str, 

232 secret: str, 

233 secret_version: str, 

234 ) -> str: 

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

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

237 project=project, 

238 secret=secret, 

239 secret_version=secret_version, 

240 ) 

241 

242 @staticmethod 

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

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

245 m = re.match( 

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

247 path, 

248 ) 

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

250 

251 @staticmethod 

252 def common_billing_account_path( 

253 billing_account: str, 

254 ) -> str: 

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

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

257 billing_account=billing_account, 

258 ) 

259 

260 @staticmethod 

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

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

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

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

265 

266 @staticmethod 

267 def common_folder_path( 

268 folder: str, 

269 ) -> str: 

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

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

272 folder=folder, 

273 ) 

274 

275 @staticmethod 

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

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

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

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

280 

281 @staticmethod 

282 def common_organization_path( 

283 organization: str, 

284 ) -> str: 

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

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

287 organization=organization, 

288 ) 

289 

290 @staticmethod 

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

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

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

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

295 

296 @staticmethod 

297 def common_project_path( 

298 project: str, 

299 ) -> str: 

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

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

302 project=project, 

303 ) 

304 

305 @staticmethod 

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

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

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

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

310 

311 @staticmethod 

312 def common_location_path( 

313 project: str, 

314 location: str, 

315 ) -> str: 

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

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

318 project=project, 

319 location=location, 

320 ) 

321 

322 @staticmethod 

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

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

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

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

327 

328 @classmethod 

329 def get_mtls_endpoint_and_cert_source( 

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

331 ): 

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

333 

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

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

336 client cert source is None. 

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

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

339 source is None. 

340 

341 The API endpoint is determined in the following order: 

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

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

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

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

346 use the default API endpoint. 

347 

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

349 

350 Args: 

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

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

353 in this method. 

354 

355 Returns: 

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

357 client cert source to use. 

358 

359 Raises: 

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

361 """ 

362 

363 warnings.warn( 

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

365 DeprecationWarning, 

366 ) 

367 if client_options is None: 

368 client_options = client_options_lib.ClientOptions() 

369 use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") 

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

371 if use_client_cert not in ("true", "false"): 

372 raise ValueError( 

373 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" 

374 ) 

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

376 raise MutualTLSChannelError( 

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

378 ) 

379 

380 # Figure out the client cert source to use. 

381 client_cert_source = None 

382 if use_client_cert == "true": 

383 if client_options.client_cert_source: 

384 client_cert_source = client_options.client_cert_source 

385 elif mtls.has_default_client_cert_source(): 

386 client_cert_source = mtls.default_client_cert_source() 

387 

388 # Figure out which api endpoint to use. 

389 if client_options.api_endpoint is not None: 

390 api_endpoint = client_options.api_endpoint 

391 elif use_mtls_endpoint == "always" or ( 

392 use_mtls_endpoint == "auto" and client_cert_source 

393 ): 

394 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

395 else: 

396 api_endpoint = cls.DEFAULT_ENDPOINT 

397 

398 return api_endpoint, client_cert_source 

399 

400 @staticmethod 

401 def _read_environment_variables(): 

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

403 

404 Returns: 

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

406 GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. 

407 

408 Raises: 

409 ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not 

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

411 google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT 

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

413 """ 

414 use_client_cert = os.getenv( 

415 "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" 

416 ).lower() 

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

418 universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") 

419 if use_client_cert not in ("true", "false"): 

420 raise ValueError( 

421 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" 

422 ) 

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

424 raise MutualTLSChannelError( 

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

426 ) 

427 return use_client_cert == "true", use_mtls_endpoint, universe_domain_env 

428 

429 @staticmethod 

430 def _get_client_cert_source(provided_cert_source, use_cert_flag): 

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

432 

433 Args: 

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

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

436 

437 Returns: 

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

439 """ 

440 client_cert_source = None 

441 if use_cert_flag: 

442 if provided_cert_source: 

443 client_cert_source = provided_cert_source 

444 elif mtls.has_default_client_cert_source(): 

445 client_cert_source = mtls.default_client_cert_source() 

446 return client_cert_source 

447 

448 @staticmethod 

449 def _get_api_endpoint( 

450 api_override, client_cert_source, universe_domain, use_mtls_endpoint 

451 ): 

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

453 

454 Args: 

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

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

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

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

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

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

461 

462 Returns: 

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

464 """ 

465 if api_override is not None: 

466 api_endpoint = api_override 

467 elif use_mtls_endpoint == "always" or ( 

468 use_mtls_endpoint == "auto" and client_cert_source 

469 ): 

470 _default_universe = SecretManagerServiceClient._DEFAULT_UNIVERSE 

471 if universe_domain != _default_universe: 

472 raise MutualTLSChannelError( 

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

474 ) 

475 api_endpoint = SecretManagerServiceClient.DEFAULT_MTLS_ENDPOINT 

476 else: 

477 api_endpoint = SecretManagerServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( 

478 UNIVERSE_DOMAIN=universe_domain 

479 ) 

480 return api_endpoint 

481 

482 @staticmethod 

483 def _get_universe_domain( 

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

485 ) -> str: 

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

487 

488 Args: 

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

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

491 

492 Returns: 

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

494 

495 Raises: 

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

497 """ 

498 universe_domain = SecretManagerServiceClient._DEFAULT_UNIVERSE 

499 if client_universe_domain is not None: 

500 universe_domain = client_universe_domain 

501 elif universe_domain_env is not None: 

502 universe_domain = universe_domain_env 

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

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

505 return universe_domain 

506 

507 def _validate_universe_domain(self): 

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

509 

510 Returns: 

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

512 

513 Raises: 

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

515 """ 

516 

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

518 return True 

519 

520 def _add_cred_info_for_auth_errors( 

521 self, error: core_exceptions.GoogleAPICallError 

522 ) -> None: 

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

524 

525 Args: 

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

527 """ 

528 if error.code not in [ 

529 HTTPStatus.UNAUTHORIZED, 

530 HTTPStatus.FORBIDDEN, 

531 HTTPStatus.NOT_FOUND, 

532 ]: 

533 return 

534 

535 cred = self._transport._credentials 

536 

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

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

539 return 

540 

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

542 # is not available 

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

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

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

546 

547 @property 

548 def api_endpoint(self): 

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

550 

551 Returns: 

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

553 """ 

554 return self._api_endpoint 

555 

556 @property 

557 def universe_domain(self) -> str: 

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

559 

560 Returns: 

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

562 """ 

563 return self._universe_domain 

564 

565 def __init__( 

566 self, 

567 *, 

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

569 transport: Optional[ 

570 Union[ 

571 str, 

572 SecretManagerServiceTransport, 

573 Callable[..., SecretManagerServiceTransport], 

574 ] 

575 ] = None, 

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

577 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

578 ) -> None: 

579 """Instantiates the secret manager service client. 

580 

581 Args: 

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

583 authorization credentials to attach to requests. These 

584 credentials identify the application to the service; if none 

585 are specified, the client will attempt to ascertain the 

586 credentials from the environment. 

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

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

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

590 arguments as used in the SecretManagerServiceTransport constructor. 

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

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

593 Custom options for the client. 

594 

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

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

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

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

599 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment 

600 variable, which have one of the following values: 

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

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

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

604 the default value). 

605 

606 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

608 to provide a client certificate for mTLS transport. If 

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

610 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

611 set, no client certificate will be used. 

612 

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

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

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

616 currently not supported for mTLS. 

617 

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

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

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

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

622 your own client library. 

623 

624 Raises: 

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

626 creation failed for any reason. 

627 """ 

628 self._client_options = client_options 

629 if isinstance(self._client_options, dict): 

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

631 if self._client_options is None: 

632 self._client_options = client_options_lib.ClientOptions() 

633 self._client_options = cast( 

634 client_options_lib.ClientOptions, self._client_options 

635 ) 

636 

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

638 

639 ( 

640 self._use_client_cert, 

641 self._use_mtls_endpoint, 

642 self._universe_domain_env, 

643 ) = SecretManagerServiceClient._read_environment_variables() 

644 self._client_cert_source = SecretManagerServiceClient._get_client_cert_source( 

645 self._client_options.client_cert_source, self._use_client_cert 

646 ) 

647 self._universe_domain = SecretManagerServiceClient._get_universe_domain( 

648 universe_domain_opt, self._universe_domain_env 

649 ) 

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

651 

652 # Initialize the universe domain validation. 

653 self._is_universe_domain_valid = False 

654 

655 if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER 

656 # Setup logging. 

657 client_logging.initialize_logging() 

658 

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

660 if api_key_value and credentials: 

661 raise ValueError( 

662 "client_options.api_key and credentials are mutually exclusive" 

663 ) 

664 

665 # Save or instantiate the transport. 

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

667 # instance provides an extensibility point for unusual situations. 

668 transport_provided = isinstance(transport, SecretManagerServiceTransport) 

669 if transport_provided: 

670 # transport is a SecretManagerServiceTransport instance. 

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

672 raise ValueError( 

673 "When providing a transport instance, " 

674 "provide its credentials directly." 

675 ) 

676 if self._client_options.scopes: 

677 raise ValueError( 

678 "When providing a transport instance, provide its scopes " 

679 "directly." 

680 ) 

681 self._transport = cast(SecretManagerServiceTransport, transport) 

682 self._api_endpoint = self._transport.host 

683 

684 self._api_endpoint = ( 

685 self._api_endpoint 

686 or SecretManagerServiceClient._get_api_endpoint( 

687 self._client_options.api_endpoint, 

688 self._client_cert_source, 

689 self._universe_domain, 

690 self._use_mtls_endpoint, 

691 ) 

692 ) 

693 

694 if not transport_provided: 

695 import google.auth._default # type: ignore 

696 

697 if api_key_value and hasattr( 

698 google.auth._default, "get_api_key_credentials" 

699 ): 

700 credentials = google.auth._default.get_api_key_credentials( 

701 api_key_value 

702 ) 

703 

704 transport_init: Union[ 

705 Type[SecretManagerServiceTransport], 

706 Callable[..., SecretManagerServiceTransport], 

707 ] = ( 

708 SecretManagerServiceClient.get_transport_class(transport) 

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

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

711 ) 

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

713 self._transport = transport_init( 

714 credentials=credentials, 

715 credentials_file=self._client_options.credentials_file, 

716 host=self._api_endpoint, 

717 scopes=self._client_options.scopes, 

718 client_cert_source_for_mtls=self._client_cert_source, 

719 quota_project_id=self._client_options.quota_project_id, 

720 client_info=client_info, 

721 always_use_jwt_access=True, 

722 api_audience=self._client_options.api_audience, 

723 ) 

724 

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

726 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

727 std_logging.DEBUG 

728 ): # pragma: NO COVER 

729 _LOGGER.debug( 

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

731 extra={ 

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

733 "universeDomain": getattr( 

734 self._transport._credentials, "universe_domain", "" 

735 ), 

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

737 "credentialsInfo": getattr( 

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

739 )(), 

740 } 

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

742 else { 

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

744 "credentialsType": None, 

745 }, 

746 ) 

747 

748 def list_secrets( 

749 self, 

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

751 *, 

752 parent: Optional[str] = None, 

753 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

756 ) -> pagers.ListSecretsPager: 

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

758 

759 .. code-block:: python 

760 

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

762 # code template only. 

763 # It will require modifications to work: 

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

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

766 # client as shown in: 

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

768 from google.cloud import secretmanager_v1beta1 

769 

770 def sample_list_secrets(): 

771 # Create a client 

772 client = secretmanager_v1beta1.SecretManagerServiceClient() 

773 

774 # Initialize request argument(s) 

775 request = secretmanager_v1beta1.ListSecretsRequest( 

776 parent="parent_value", 

777 ) 

778 

779 # Make the request 

780 page_result = client.list_secrets(request=request) 

781 

782 # Handle the response 

783 for response in page_result: 

784 print(response) 

785 

786 Args: 

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

788 The request object. Request message for 

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

790 parent (str): 

791 Required. The resource name of the project associated 

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

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

794 

795 This corresponds to the ``parent`` field 

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

797 should not be set. 

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

799 should be retried. 

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

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

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

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

804 be of type `bytes`. 

805 

806 Returns: 

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

808 Response message for 

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

810 

811 Iterating over this object will yield results and 

812 resolve additional pages automatically. 

813 

814 """ 

815 # Create or coerce a protobuf request object. 

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

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

818 flattened_params = [parent] 

819 has_flattened_params = ( 

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

821 ) 

822 if request is not None and has_flattened_params: 

823 raise ValueError( 

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

825 "the individual field arguments should be set." 

826 ) 

827 

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

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

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

831 request = service.ListSecretsRequest(request) 

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

833 # request, apply these. 

834 if parent is not None: 

835 request.parent = parent 

836 

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

838 # and friendly error handling. 

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

840 

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

842 # add these here. 

843 metadata = tuple(metadata) + ( 

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

845 ) 

846 

847 # Validate the universe domain. 

848 self._validate_universe_domain() 

849 

850 # Send the request. 

851 response = rpc( 

852 request, 

853 retry=retry, 

854 timeout=timeout, 

855 metadata=metadata, 

856 ) 

857 

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

859 # an `__iter__` convenience method. 

860 response = pagers.ListSecretsPager( 

861 method=rpc, 

862 request=request, 

863 response=response, 

864 retry=retry, 

865 timeout=timeout, 

866 metadata=metadata, 

867 ) 

868 

869 # Done; return the response. 

870 return response 

871 

872 def create_secret( 

873 self, 

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

875 *, 

876 parent: Optional[str] = None, 

877 secret_id: Optional[str] = None, 

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

879 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

882 ) -> resources.Secret: 

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

884 containing no 

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

886 

887 .. code-block:: python 

888 

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

890 # code template only. 

891 # It will require modifications to work: 

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

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

894 # client as shown in: 

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

896 from google.cloud import secretmanager_v1beta1 

897 

898 def sample_create_secret(): 

899 # Create a client 

900 client = secretmanager_v1beta1.SecretManagerServiceClient() 

901 

902 # Initialize request argument(s) 

903 request = secretmanager_v1beta1.CreateSecretRequest( 

904 parent="parent_value", 

905 secret_id="secret_id_value", 

906 ) 

907 

908 # Make the request 

909 response = client.create_secret(request=request) 

910 

911 # Handle the response 

912 print(response) 

913 

914 Args: 

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

916 The request object. Request message for 

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

918 parent (str): 

919 Required. The resource name of the project to associate 

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

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

922 

923 This corresponds to the ``parent`` field 

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

925 should not be set. 

926 secret_id (str): 

927 Required. This must be unique within the project. 

928 

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

930 characters and can contain uppercase and lowercase 

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

932 (``_``) characters. 

933 

934 This corresponds to the ``secret_id`` field 

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

936 should not be set. 

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

938 Required. A 

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

940 initial field values. 

941 

942 This corresponds to the ``secret`` field 

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

944 should not be set. 

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

946 should be retried. 

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

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

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

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

951 be of type `bytes`. 

952 

953 Returns: 

954 google.cloud.secretmanager_v1beta1.types.Secret: 

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

956 value and versions can be accessed. 

957 

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

959 made up of zero or more 

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

961 that represent the secret data. 

962 

963 """ 

964 # Create or coerce a protobuf request object. 

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

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

967 flattened_params = [parent, secret_id, secret] 

968 has_flattened_params = ( 

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

970 ) 

971 if request is not None and has_flattened_params: 

972 raise ValueError( 

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

974 "the individual field arguments should be set." 

975 ) 

976 

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

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

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

980 request = service.CreateSecretRequest(request) 

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

982 # request, apply these. 

983 if parent is not None: 

984 request.parent = parent 

985 if secret_id is not None: 

986 request.secret_id = secret_id 

987 if secret is not None: 

988 request.secret = secret 

989 

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

991 # and friendly error handling. 

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

993 

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

995 # add these here. 

996 metadata = tuple(metadata) + ( 

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

998 ) 

999 

1000 # Validate the universe domain. 

1001 self._validate_universe_domain() 

1002 

1003 # Send the request. 

1004 response = rpc( 

1005 request, 

1006 retry=retry, 

1007 timeout=timeout, 

1008 metadata=metadata, 

1009 ) 

1010 

1011 # Done; return the response. 

1012 return response 

1013 

1014 def add_secret_version( 

1015 self, 

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

1017 *, 

1018 parent: Optional[str] = None, 

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

1020 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1023 ) -> resources.SecretVersion: 

1024 r"""Creates a new 

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

1026 containing secret data and attaches it to an existing 

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

1028 

1029 .. code-block:: python 

1030 

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

1032 # code template only. 

1033 # It will require modifications to work: 

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

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

1036 # client as shown in: 

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

1038 from google.cloud import secretmanager_v1beta1 

1039 

1040 def sample_add_secret_version(): 

1041 # Create a client 

1042 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1043 

1044 # Initialize request argument(s) 

1045 request = secretmanager_v1beta1.AddSecretVersionRequest( 

1046 parent="parent_value", 

1047 ) 

1048 

1049 # Make the request 

1050 response = client.add_secret_version(request=request) 

1051 

1052 # Handle the response 

1053 print(response) 

1054 

1055 Args: 

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

1057 The request object. Request message for 

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

1059 parent (str): 

1060 Required. The resource name of the 

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

1062 associate with the 

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

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

1065 

1066 This corresponds to the ``parent`` field 

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

1068 should not be set. 

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

1070 Required. The secret payload of the 

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

1072 

1073 This corresponds to the ``payload`` field 

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

1075 should not be set. 

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

1077 should be retried. 

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

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

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

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

1082 be of type `bytes`. 

1083 

1084 Returns: 

1085 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1086 A secret version resource in the 

1087 Secret Manager API. 

1088 

1089 """ 

1090 # Create or coerce a protobuf request object. 

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

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

1093 flattened_params = [parent, payload] 

1094 has_flattened_params = ( 

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

1096 ) 

1097 if request is not None and has_flattened_params: 

1098 raise ValueError( 

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

1100 "the individual field arguments should be set." 

1101 ) 

1102 

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

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

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

1106 request = service.AddSecretVersionRequest(request) 

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

1108 # request, apply these. 

1109 if parent is not None: 

1110 request.parent = parent 

1111 if payload is not None: 

1112 request.payload = payload 

1113 

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

1115 # and friendly error handling. 

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

1117 

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

1119 # add these here. 

1120 metadata = tuple(metadata) + ( 

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

1122 ) 

1123 

1124 # Validate the universe domain. 

1125 self._validate_universe_domain() 

1126 

1127 # Send the request. 

1128 response = rpc( 

1129 request, 

1130 retry=retry, 

1131 timeout=timeout, 

1132 metadata=metadata, 

1133 ) 

1134 

1135 # Done; return the response. 

1136 return response 

1137 

1138 def get_secret( 

1139 self, 

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

1141 *, 

1142 name: Optional[str] = None, 

1143 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1146 ) -> resources.Secret: 

1147 r"""Gets metadata for a given 

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

1149 

1150 .. code-block:: python 

1151 

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

1153 # code template only. 

1154 # It will require modifications to work: 

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

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

1157 # client as shown in: 

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

1159 from google.cloud import secretmanager_v1beta1 

1160 

1161 def sample_get_secret(): 

1162 # Create a client 

1163 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1164 

1165 # Initialize request argument(s) 

1166 request = secretmanager_v1beta1.GetSecretRequest( 

1167 name="name_value", 

1168 ) 

1169 

1170 # Make the request 

1171 response = client.get_secret(request=request) 

1172 

1173 # Handle the response 

1174 print(response) 

1175 

1176 Args: 

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

1178 The request object. Request message for 

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

1180 name (str): 

1181 Required. The resource name of the 

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

1183 format ``projects/*/secrets/*``. 

1184 

1185 This corresponds to the ``name`` field 

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

1187 should not be set. 

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

1189 should be retried. 

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

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

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

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

1194 be of type `bytes`. 

1195 

1196 Returns: 

1197 google.cloud.secretmanager_v1beta1.types.Secret: 

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

1199 value and versions can be accessed. 

1200 

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

1202 made up of zero or more 

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

1204 that represent the secret data. 

1205 

1206 """ 

1207 # Create or coerce a protobuf request object. 

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

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

1210 flattened_params = [name] 

1211 has_flattened_params = ( 

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

1213 ) 

1214 if request is not None and has_flattened_params: 

1215 raise ValueError( 

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

1217 "the individual field arguments should be set." 

1218 ) 

1219 

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

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

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

1223 request = service.GetSecretRequest(request) 

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

1225 # request, apply these. 

1226 if name is not None: 

1227 request.name = name 

1228 

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

1230 # and friendly error handling. 

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

1232 

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

1234 # add these here. 

1235 metadata = tuple(metadata) + ( 

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

1237 ) 

1238 

1239 # Validate the universe domain. 

1240 self._validate_universe_domain() 

1241 

1242 # Send the request. 

1243 response = rpc( 

1244 request, 

1245 retry=retry, 

1246 timeout=timeout, 

1247 metadata=metadata, 

1248 ) 

1249 

1250 # Done; return the response. 

1251 return response 

1252 

1253 def update_secret( 

1254 self, 

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

1256 *, 

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

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

1259 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1262 ) -> resources.Secret: 

1263 r"""Updates metadata of an existing 

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

1265 

1266 .. code-block:: python 

1267 

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

1269 # code template only. 

1270 # It will require modifications to work: 

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

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

1273 # client as shown in: 

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

1275 from google.cloud import secretmanager_v1beta1 

1276 

1277 def sample_update_secret(): 

1278 # Create a client 

1279 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1280 

1281 # Initialize request argument(s) 

1282 request = secretmanager_v1beta1.UpdateSecretRequest( 

1283 ) 

1284 

1285 # Make the request 

1286 response = client.update_secret(request=request) 

1287 

1288 # Handle the response 

1289 print(response) 

1290 

1291 Args: 

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

1293 The request object. Request message for 

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

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

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

1297 with updated field values. 

1298 

1299 This corresponds to the ``secret`` field 

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

1301 should not be set. 

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

1303 Required. Specifies the fields to be 

1304 updated. 

1305 

1306 This corresponds to the ``update_mask`` field 

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

1308 should not be set. 

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

1310 should be retried. 

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

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

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

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

1315 be of type `bytes`. 

1316 

1317 Returns: 

1318 google.cloud.secretmanager_v1beta1.types.Secret: 

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

1320 value and versions can be accessed. 

1321 

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

1323 made up of zero or more 

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

1325 that represent the secret data. 

1326 

1327 """ 

1328 # Create or coerce a protobuf request object. 

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

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

1331 flattened_params = [secret, update_mask] 

1332 has_flattened_params = ( 

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

1334 ) 

1335 if request is not None and has_flattened_params: 

1336 raise ValueError( 

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

1338 "the individual field arguments should be set." 

1339 ) 

1340 

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

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

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

1344 request = service.UpdateSecretRequest(request) 

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

1346 # request, apply these. 

1347 if secret is not None: 

1348 request.secret = secret 

1349 if update_mask is not None: 

1350 request.update_mask = update_mask 

1351 

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

1353 # and friendly error handling. 

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

1355 

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

1357 # add these here. 

1358 metadata = tuple(metadata) + ( 

1359 gapic_v1.routing_header.to_grpc_metadata( 

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

1361 ), 

1362 ) 

1363 

1364 # Validate the universe domain. 

1365 self._validate_universe_domain() 

1366 

1367 # Send the request. 

1368 response = rpc( 

1369 request, 

1370 retry=retry, 

1371 timeout=timeout, 

1372 metadata=metadata, 

1373 ) 

1374 

1375 # Done; return the response. 

1376 return response 

1377 

1378 def delete_secret( 

1379 self, 

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

1381 *, 

1382 name: Optional[str] = None, 

1383 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1386 ) -> None: 

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

1388 

1389 .. code-block:: python 

1390 

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

1392 # code template only. 

1393 # It will require modifications to work: 

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

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

1396 # client as shown in: 

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

1398 from google.cloud import secretmanager_v1beta1 

1399 

1400 def sample_delete_secret(): 

1401 # Create a client 

1402 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1403 

1404 # Initialize request argument(s) 

1405 request = secretmanager_v1beta1.DeleteSecretRequest( 

1406 name="name_value", 

1407 ) 

1408 

1409 # Make the request 

1410 client.delete_secret(request=request) 

1411 

1412 Args: 

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

1414 The request object. Request message for 

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

1416 name (str): 

1417 Required. The resource name of the 

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

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

1420 

1421 This corresponds to the ``name`` field 

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

1423 should not be set. 

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

1425 should be retried. 

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

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

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

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

1430 be of type `bytes`. 

1431 """ 

1432 # Create or coerce a protobuf request object. 

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

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

1435 flattened_params = [name] 

1436 has_flattened_params = ( 

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

1438 ) 

1439 if request is not None and has_flattened_params: 

1440 raise ValueError( 

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

1442 "the individual field arguments should be set." 

1443 ) 

1444 

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

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

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

1448 request = service.DeleteSecretRequest(request) 

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

1450 # request, apply these. 

1451 if name is not None: 

1452 request.name = name 

1453 

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

1455 # and friendly error handling. 

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

1457 

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

1459 # add these here. 

1460 metadata = tuple(metadata) + ( 

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

1462 ) 

1463 

1464 # Validate the universe domain. 

1465 self._validate_universe_domain() 

1466 

1467 # Send the request. 

1468 rpc( 

1469 request, 

1470 retry=retry, 

1471 timeout=timeout, 

1472 metadata=metadata, 

1473 ) 

1474 

1475 def list_secret_versions( 

1476 self, 

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

1478 *, 

1479 parent: Optional[str] = None, 

1480 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1483 ) -> pagers.ListSecretVersionsPager: 

1484 r"""Lists 

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

1486 This call does not return secret data. 

1487 

1488 .. code-block:: python 

1489 

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

1491 # code template only. 

1492 # It will require modifications to work: 

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

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

1495 # client as shown in: 

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

1497 from google.cloud import secretmanager_v1beta1 

1498 

1499 def sample_list_secret_versions(): 

1500 # Create a client 

1501 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1502 

1503 # Initialize request argument(s) 

1504 request = secretmanager_v1beta1.ListSecretVersionsRequest( 

1505 parent="parent_value", 

1506 ) 

1507 

1508 # Make the request 

1509 page_result = client.list_secret_versions(request=request) 

1510 

1511 # Handle the response 

1512 for response in page_result: 

1513 print(response) 

1514 

1515 Args: 

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

1517 The request object. Request message for 

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

1519 parent (str): 

1520 Required. The resource name of the 

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

1522 with the 

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

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

1525 

1526 This corresponds to the ``parent`` field 

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

1528 should not be set. 

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

1530 should be retried. 

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

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

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

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

1535 be of type `bytes`. 

1536 

1537 Returns: 

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

1539 Response message for 

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

1541 

1542 Iterating over this object will yield results and 

1543 resolve additional pages automatically. 

1544 

1545 """ 

1546 # Create or coerce a protobuf request object. 

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

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

1549 flattened_params = [parent] 

1550 has_flattened_params = ( 

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

1552 ) 

1553 if request is not None and has_flattened_params: 

1554 raise ValueError( 

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

1556 "the individual field arguments should be set." 

1557 ) 

1558 

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

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

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

1562 request = service.ListSecretVersionsRequest(request) 

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

1564 # request, apply these. 

1565 if parent is not None: 

1566 request.parent = parent 

1567 

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

1569 # and friendly error handling. 

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

1571 

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

1573 # add these here. 

1574 metadata = tuple(metadata) + ( 

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

1576 ) 

1577 

1578 # Validate the universe domain. 

1579 self._validate_universe_domain() 

1580 

1581 # Send the request. 

1582 response = rpc( 

1583 request, 

1584 retry=retry, 

1585 timeout=timeout, 

1586 metadata=metadata, 

1587 ) 

1588 

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

1590 # an `__iter__` convenience method. 

1591 response = pagers.ListSecretVersionsPager( 

1592 method=rpc, 

1593 request=request, 

1594 response=response, 

1595 retry=retry, 

1596 timeout=timeout, 

1597 metadata=metadata, 

1598 ) 

1599 

1600 # Done; return the response. 

1601 return response 

1602 

1603 def get_secret_version( 

1604 self, 

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

1606 *, 

1607 name: Optional[str] = None, 

1608 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1611 ) -> resources.SecretVersion: 

1612 r"""Gets metadata for a 

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

1614 

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

1616 ``latest`` 

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

1618 

1619 .. code-block:: python 

1620 

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

1622 # code template only. 

1623 # It will require modifications to work: 

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

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

1626 # client as shown in: 

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

1628 from google.cloud import secretmanager_v1beta1 

1629 

1630 def sample_get_secret_version(): 

1631 # Create a client 

1632 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1633 

1634 # Initialize request argument(s) 

1635 request = secretmanager_v1beta1.GetSecretVersionRequest( 

1636 name="name_value", 

1637 ) 

1638 

1639 # Make the request 

1640 response = client.get_secret_version(request=request) 

1641 

1642 # Handle the response 

1643 print(response) 

1644 

1645 Args: 

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

1647 The request object. Request message for 

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

1649 name (str): 

1650 Required. The resource name of the 

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

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

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

1654 the ``latest`` 

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

1656 

1657 This corresponds to the ``name`` field 

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

1659 should not be set. 

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

1661 should be retried. 

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

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

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

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

1666 be of type `bytes`. 

1667 

1668 Returns: 

1669 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1670 A secret version resource in the 

1671 Secret Manager API. 

1672 

1673 """ 

1674 # Create or coerce a protobuf request object. 

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

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

1677 flattened_params = [name] 

1678 has_flattened_params = ( 

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

1680 ) 

1681 if request is not None and has_flattened_params: 

1682 raise ValueError( 

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

1684 "the individual field arguments should be set." 

1685 ) 

1686 

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

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

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

1690 request = service.GetSecretVersionRequest(request) 

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

1692 # request, apply these. 

1693 if name is not None: 

1694 request.name = name 

1695 

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

1697 # and friendly error handling. 

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

1699 

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

1701 # add these here. 

1702 metadata = tuple(metadata) + ( 

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

1704 ) 

1705 

1706 # Validate the universe domain. 

1707 self._validate_universe_domain() 

1708 

1709 # Send the request. 

1710 response = rpc( 

1711 request, 

1712 retry=retry, 

1713 timeout=timeout, 

1714 metadata=metadata, 

1715 ) 

1716 

1717 # Done; return the response. 

1718 return response 

1719 

1720 def access_secret_version( 

1721 self, 

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

1723 *, 

1724 name: Optional[str] = None, 

1725 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1728 ) -> service.AccessSecretVersionResponse: 

1729 r"""Accesses a 

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

1731 This call returns the secret data. 

1732 

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

1734 ``latest`` 

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

1736 

1737 .. code-block:: python 

1738 

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

1740 # code template only. 

1741 # It will require modifications to work: 

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

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

1744 # client as shown in: 

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

1746 from google.cloud import secretmanager_v1beta1 

1747 

1748 def sample_access_secret_version(): 

1749 # Create a client 

1750 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1751 

1752 # Initialize request argument(s) 

1753 request = secretmanager_v1beta1.AccessSecretVersionRequest( 

1754 name="name_value", 

1755 ) 

1756 

1757 # Make the request 

1758 response = client.access_secret_version(request=request) 

1759 

1760 # Handle the response 

1761 print(response) 

1762 

1763 Args: 

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

1765 The request object. Request message for 

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

1767 name (str): 

1768 Required. The resource name of the 

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

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

1771 

1772 This corresponds to the ``name`` field 

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

1774 should not be set. 

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

1776 should be retried. 

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

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

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

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

1781 be of type `bytes`. 

1782 

1783 Returns: 

1784 google.cloud.secretmanager_v1beta1.types.AccessSecretVersionResponse: 

1785 Response message for 

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

1787 

1788 """ 

1789 # Create or coerce a protobuf request object. 

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

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

1792 flattened_params = [name] 

1793 has_flattened_params = ( 

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

1795 ) 

1796 if request is not None and has_flattened_params: 

1797 raise ValueError( 

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

1799 "the individual field arguments should be set." 

1800 ) 

1801 

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

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

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

1805 request = service.AccessSecretVersionRequest(request) 

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

1807 # request, apply these. 

1808 if name is not None: 

1809 request.name = name 

1810 

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

1812 # and friendly error handling. 

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

1814 

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

1816 # add these here. 

1817 metadata = tuple(metadata) + ( 

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

1819 ) 

1820 

1821 # Validate the universe domain. 

1822 self._validate_universe_domain() 

1823 

1824 # Send the request. 

1825 response = rpc( 

1826 request, 

1827 retry=retry, 

1828 timeout=timeout, 

1829 metadata=metadata, 

1830 ) 

1831 

1832 # Done; return the response. 

1833 return response 

1834 

1835 def disable_secret_version( 

1836 self, 

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

1838 *, 

1839 name: Optional[str] = None, 

1840 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1843 ) -> resources.SecretVersion: 

1844 r"""Disables a 

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

1846 

1847 Sets the 

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

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

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

1851 

1852 .. code-block:: python 

1853 

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

1855 # code template only. 

1856 # It will require modifications to work: 

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

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

1859 # client as shown in: 

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

1861 from google.cloud import secretmanager_v1beta1 

1862 

1863 def sample_disable_secret_version(): 

1864 # Create a client 

1865 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1866 

1867 # Initialize request argument(s) 

1868 request = secretmanager_v1beta1.DisableSecretVersionRequest( 

1869 name="name_value", 

1870 ) 

1871 

1872 # Make the request 

1873 response = client.disable_secret_version(request=request) 

1874 

1875 # Handle the response 

1876 print(response) 

1877 

1878 Args: 

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

1880 The request object. Request message for 

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

1882 name (str): 

1883 Required. The resource name of the 

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

1885 to disable in the format 

1886 ``projects/*/secrets/*/versions/*``. 

1887 

1888 This corresponds to the ``name`` field 

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

1890 should not be set. 

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

1892 should be retried. 

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

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

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

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

1897 be of type `bytes`. 

1898 

1899 Returns: 

1900 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

1901 A secret version resource in the 

1902 Secret Manager API. 

1903 

1904 """ 

1905 # Create or coerce a protobuf request object. 

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

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

1908 flattened_params = [name] 

1909 has_flattened_params = ( 

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

1911 ) 

1912 if request is not None and has_flattened_params: 

1913 raise ValueError( 

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

1915 "the individual field arguments should be set." 

1916 ) 

1917 

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

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

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

1921 request = service.DisableSecretVersionRequest(request) 

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

1923 # request, apply these. 

1924 if name is not None: 

1925 request.name = name 

1926 

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

1928 # and friendly error handling. 

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

1930 

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

1932 # add these here. 

1933 metadata = tuple(metadata) + ( 

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

1935 ) 

1936 

1937 # Validate the universe domain. 

1938 self._validate_universe_domain() 

1939 

1940 # Send the request. 

1941 response = rpc( 

1942 request, 

1943 retry=retry, 

1944 timeout=timeout, 

1945 metadata=metadata, 

1946 ) 

1947 

1948 # Done; return the response. 

1949 return response 

1950 

1951 def enable_secret_version( 

1952 self, 

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

1954 *, 

1955 name: Optional[str] = None, 

1956 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1959 ) -> resources.SecretVersion: 

1960 r"""Enables a 

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

1962 

1963 Sets the 

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

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

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

1967 

1968 .. code-block:: python 

1969 

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

1971 # code template only. 

1972 # It will require modifications to work: 

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

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

1975 # client as shown in: 

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

1977 from google.cloud import secretmanager_v1beta1 

1978 

1979 def sample_enable_secret_version(): 

1980 # Create a client 

1981 client = secretmanager_v1beta1.SecretManagerServiceClient() 

1982 

1983 # Initialize request argument(s) 

1984 request = secretmanager_v1beta1.EnableSecretVersionRequest( 

1985 name="name_value", 

1986 ) 

1987 

1988 # Make the request 

1989 response = client.enable_secret_version(request=request) 

1990 

1991 # Handle the response 

1992 print(response) 

1993 

1994 Args: 

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

1996 The request object. Request message for 

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

1998 name (str): 

1999 Required. The resource name of the 

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

2001 to enable in the format 

2002 ``projects/*/secrets/*/versions/*``. 

2003 

2004 This corresponds to the ``name`` field 

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

2006 should not be set. 

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

2008 should be retried. 

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

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

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

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

2013 be of type `bytes`. 

2014 

2015 Returns: 

2016 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

2017 A secret version resource in the 

2018 Secret Manager API. 

2019 

2020 """ 

2021 # Create or coerce a protobuf request object. 

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

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

2024 flattened_params = [name] 

2025 has_flattened_params = ( 

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

2027 ) 

2028 if request is not None and has_flattened_params: 

2029 raise ValueError( 

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

2031 "the individual field arguments should be set." 

2032 ) 

2033 

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

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

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

2037 request = service.EnableSecretVersionRequest(request) 

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

2039 # request, apply these. 

2040 if name is not None: 

2041 request.name = name 

2042 

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

2044 # and friendly error handling. 

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

2046 

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

2048 # add these here. 

2049 metadata = tuple(metadata) + ( 

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

2051 ) 

2052 

2053 # Validate the universe domain. 

2054 self._validate_universe_domain() 

2055 

2056 # Send the request. 

2057 response = rpc( 

2058 request, 

2059 retry=retry, 

2060 timeout=timeout, 

2061 metadata=metadata, 

2062 ) 

2063 

2064 # Done; return the response. 

2065 return response 

2066 

2067 def destroy_secret_version( 

2068 self, 

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

2070 *, 

2071 name: Optional[str] = None, 

2072 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

2075 ) -> resources.SecretVersion: 

2076 r"""Destroys a 

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

2078 

2079 Sets the 

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

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

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

2083 and irrevocably destroys the secret data. 

2084 

2085 .. code-block:: python 

2086 

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

2088 # code template only. 

2089 # It will require modifications to work: 

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

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

2092 # client as shown in: 

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

2094 from google.cloud import secretmanager_v1beta1 

2095 

2096 def sample_destroy_secret_version(): 

2097 # Create a client 

2098 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2099 

2100 # Initialize request argument(s) 

2101 request = secretmanager_v1beta1.DestroySecretVersionRequest( 

2102 name="name_value", 

2103 ) 

2104 

2105 # Make the request 

2106 response = client.destroy_secret_version(request=request) 

2107 

2108 # Handle the response 

2109 print(response) 

2110 

2111 Args: 

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

2113 The request object. Request message for 

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

2115 name (str): 

2116 Required. The resource name of the 

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

2118 to destroy in the format 

2119 ``projects/*/secrets/*/versions/*``. 

2120 

2121 This corresponds to the ``name`` field 

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

2123 should not be set. 

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

2125 should be retried. 

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

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

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

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

2130 be of type `bytes`. 

2131 

2132 Returns: 

2133 google.cloud.secretmanager_v1beta1.types.SecretVersion: 

2134 A secret version resource in the 

2135 Secret Manager API. 

2136 

2137 """ 

2138 # Create or coerce a protobuf request object. 

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

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

2141 flattened_params = [name] 

2142 has_flattened_params = ( 

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

2144 ) 

2145 if request is not None and has_flattened_params: 

2146 raise ValueError( 

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

2148 "the individual field arguments should be set." 

2149 ) 

2150 

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

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

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

2154 request = service.DestroySecretVersionRequest(request) 

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

2156 # request, apply these. 

2157 if name is not None: 

2158 request.name = name 

2159 

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

2161 # and friendly error handling. 

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

2163 

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

2165 # add these here. 

2166 metadata = tuple(metadata) + ( 

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

2168 ) 

2169 

2170 # Validate the universe domain. 

2171 self._validate_universe_domain() 

2172 

2173 # Send the request. 

2174 response = rpc( 

2175 request, 

2176 retry=retry, 

2177 timeout=timeout, 

2178 metadata=metadata, 

2179 ) 

2180 

2181 # Done; return the response. 

2182 return response 

2183 

2184 def set_iam_policy( 

2185 self, 

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

2187 *, 

2188 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

2191 ) -> policy_pb2.Policy: 

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

2193 any existing policy. 

2194 

2195 Permissions on 

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

2197 enforced according to the policy set on the associated 

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

2199 

2200 .. code-block:: python 

2201 

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

2203 # code template only. 

2204 # It will require modifications to work: 

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

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

2207 # client as shown in: 

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

2209 from google.cloud import secretmanager_v1beta1 

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

2211 

2212 def sample_set_iam_policy(): 

2213 # Create a client 

2214 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2215 

2216 # Initialize request argument(s) 

2217 request = iam_policy_pb2.SetIamPolicyRequest( 

2218 resource="resource_value", 

2219 ) 

2220 

2221 # Make the request 

2222 response = client.set_iam_policy(request=request) 

2223 

2224 # Handle the response 

2225 print(response) 

2226 

2227 Args: 

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

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

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

2231 should be retried. 

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

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

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

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

2236 be of type `bytes`. 

2237 

2238 Returns: 

2239 google.iam.v1.policy_pb2.Policy: 

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

2241 controls for Google Cloud resources. 

2242 

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

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

2245 Principals can be user accounts, service accounts, 

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

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

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

2249 

2250 For some types of Google Cloud resources, a binding 

2251 can also specify a condition, which is a logical 

2252 expression that allows access to a resource only if 

2253 the expression evaluates to true. A condition can add 

2254 constraints based on attributes of the request, the 

2255 resource, or both. To learn which resources support 

2256 conditions in their IAM policies, see the [IAM 

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

2258 

2259 **JSON example:** 

2260 

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

2262 

2263 **YAML example:** 

2264 

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

2266 

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

2268 [IAM 

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

2270 

2271 """ 

2272 # Create or coerce a protobuf request object. 

2273 if isinstance(request, dict): 

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

2275 # so it must be constructed via keyword expansion. 

2276 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

2277 elif not request: 

2278 # Null request, just make one. 

2279 request = iam_policy_pb2.SetIamPolicyRequest() 

2280 

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

2282 # and friendly error handling. 

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

2284 

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

2286 # add these here. 

2287 metadata = tuple(metadata) + ( 

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

2289 ) 

2290 

2291 # Validate the universe domain. 

2292 self._validate_universe_domain() 

2293 

2294 # Send the request. 

2295 response = rpc( 

2296 request, 

2297 retry=retry, 

2298 timeout=timeout, 

2299 metadata=metadata, 

2300 ) 

2301 

2302 # Done; return the response. 

2303 return response 

2304 

2305 def get_iam_policy( 

2306 self, 

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

2308 *, 

2309 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

2312 ) -> policy_pb2.Policy: 

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

2314 Returns empty policy if the secret exists and does not 

2315 have a policy set. 

2316 

2317 .. code-block:: python 

2318 

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

2320 # code template only. 

2321 # It will require modifications to work: 

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

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

2324 # client as shown in: 

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

2326 from google.cloud import secretmanager_v1beta1 

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

2328 

2329 def sample_get_iam_policy(): 

2330 # Create a client 

2331 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2332 

2333 # Initialize request argument(s) 

2334 request = iam_policy_pb2.GetIamPolicyRequest( 

2335 resource="resource_value", 

2336 ) 

2337 

2338 # Make the request 

2339 response = client.get_iam_policy(request=request) 

2340 

2341 # Handle the response 

2342 print(response) 

2343 

2344 Args: 

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

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

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

2348 should be retried. 

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

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

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

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

2353 be of type `bytes`. 

2354 

2355 Returns: 

2356 google.iam.v1.policy_pb2.Policy: 

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

2358 controls for Google Cloud resources. 

2359 

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

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

2362 Principals can be user accounts, service accounts, 

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

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

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

2366 

2367 For some types of Google Cloud resources, a binding 

2368 can also specify a condition, which is a logical 

2369 expression that allows access to a resource only if 

2370 the expression evaluates to true. A condition can add 

2371 constraints based on attributes of the request, the 

2372 resource, or both. To learn which resources support 

2373 conditions in their IAM policies, see the [IAM 

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

2375 

2376 **JSON example:** 

2377 

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

2379 

2380 **YAML example:** 

2381 

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

2383 

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

2385 [IAM 

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

2387 

2388 """ 

2389 # Create or coerce a protobuf request object. 

2390 if isinstance(request, dict): 

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

2392 # so it must be constructed via keyword expansion. 

2393 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

2394 elif not request: 

2395 # Null request, just make one. 

2396 request = iam_policy_pb2.GetIamPolicyRequest() 

2397 

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

2399 # and friendly error handling. 

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

2401 

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

2403 # add these here. 

2404 metadata = tuple(metadata) + ( 

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

2406 ) 

2407 

2408 # Validate the universe domain. 

2409 self._validate_universe_domain() 

2410 

2411 # Send the request. 

2412 response = rpc( 

2413 request, 

2414 retry=retry, 

2415 timeout=timeout, 

2416 metadata=metadata, 

2417 ) 

2418 

2419 # Done; return the response. 

2420 return response 

2421 

2422 def test_iam_permissions( 

2423 self, 

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

2425 *, 

2426 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

2429 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

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

2432 permissions, not a NOT_FOUND error. 

2433 

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

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

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

2437 warning. 

2438 

2439 .. code-block:: python 

2440 

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

2442 # code template only. 

2443 # It will require modifications to work: 

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

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

2446 # client as shown in: 

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

2448 from google.cloud import secretmanager_v1beta1 

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

2450 

2451 def sample_test_iam_permissions(): 

2452 # Create a client 

2453 client = secretmanager_v1beta1.SecretManagerServiceClient() 

2454 

2455 # Initialize request argument(s) 

2456 request = iam_policy_pb2.TestIamPermissionsRequest( 

2457 resource="resource_value", 

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

2459 ) 

2460 

2461 # Make the request 

2462 response = client.test_iam_permissions(request=request) 

2463 

2464 # Handle the response 

2465 print(response) 

2466 

2467 Args: 

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

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

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

2471 should be retried. 

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

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

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

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

2476 be of type `bytes`. 

2477 

2478 Returns: 

2479 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: 

2480 Response message for TestIamPermissions method. 

2481 """ 

2482 # Create or coerce a protobuf request object. 

2483 if isinstance(request, dict): 

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

2485 # so it must be constructed via keyword expansion. 

2486 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

2487 elif not request: 

2488 # Null request, just make one. 

2489 request = iam_policy_pb2.TestIamPermissionsRequest() 

2490 

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

2492 # and friendly error handling. 

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

2494 

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

2496 # add these here. 

2497 metadata = tuple(metadata) + ( 

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

2499 ) 

2500 

2501 # Validate the universe domain. 

2502 self._validate_universe_domain() 

2503 

2504 # Send the request. 

2505 response = rpc( 

2506 request, 

2507 retry=retry, 

2508 timeout=timeout, 

2509 metadata=metadata, 

2510 ) 

2511 

2512 # Done; return the response. 

2513 return response 

2514 

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

2516 return self 

2517 

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

2519 """Releases underlying transport's resources. 

2520 

2521 .. warning:: 

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

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

2524 and may cause errors in other clients! 

2525 """ 

2526 self.transport.close() 

2527 

2528 def get_location( 

2529 self, 

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

2531 *, 

2532 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

2535 ) -> locations_pb2.Location: 

2536 r"""Gets information about a location. 

2537 

2538 Args: 

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

2540 The request object. Request message for 

2541 `GetLocation` method. 

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

2543 if any, should be retried. 

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

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

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

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

2548 be of type `bytes`. 

2549 Returns: 

2550 ~.location_pb2.Location: 

2551 Location object. 

2552 """ 

2553 # Create or coerce a protobuf request object. 

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

2555 # so it must be constructed via keyword expansion. 

2556 if isinstance(request, dict): 

2557 request = locations_pb2.GetLocationRequest(**request) 

2558 

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

2560 # and friendly error handling. 

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

2562 

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

2564 # add these here. 

2565 metadata = tuple(metadata) + ( 

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

2567 ) 

2568 

2569 # Validate the universe domain. 

2570 self._validate_universe_domain() 

2571 

2572 try: 

2573 # Send the request. 

2574 response = rpc( 

2575 request, 

2576 retry=retry, 

2577 timeout=timeout, 

2578 metadata=metadata, 

2579 ) 

2580 

2581 # Done; return the response. 

2582 return response 

2583 except core_exceptions.GoogleAPICallError as e: 

2584 self._add_cred_info_for_auth_errors(e) 

2585 raise e 

2586 

2587 def list_locations( 

2588 self, 

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

2590 *, 

2591 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

2594 ) -> locations_pb2.ListLocationsResponse: 

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

2596 

2597 Args: 

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

2599 The request object. Request message for 

2600 `ListLocations` method. 

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

2602 if any, should be retried. 

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

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

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

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

2607 be of type `bytes`. 

2608 Returns: 

2609 ~.location_pb2.ListLocationsResponse: 

2610 Response message for ``ListLocations`` method. 

2611 """ 

2612 # Create or coerce a protobuf request object. 

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

2614 # so it must be constructed via keyword expansion. 

2615 if isinstance(request, dict): 

2616 request = locations_pb2.ListLocationsRequest(**request) 

2617 

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

2619 # and friendly error handling. 

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

2621 

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

2623 # add these here. 

2624 metadata = tuple(metadata) + ( 

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

2626 ) 

2627 

2628 # Validate the universe domain. 

2629 self._validate_universe_domain() 

2630 

2631 try: 

2632 # Send the request. 

2633 response = rpc( 

2634 request, 

2635 retry=retry, 

2636 timeout=timeout, 

2637 metadata=metadata, 

2638 ) 

2639 

2640 # Done; return the response. 

2641 return response 

2642 except core_exceptions.GoogleAPICallError as e: 

2643 self._add_cred_info_for_auth_errors(e) 

2644 raise e 

2645 

2646 

2647DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

2648 gapic_version=package_version.__version__ 

2649) 

2650 

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

2652 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

2653 

2654__all__ = ("SecretManagerServiceClient",)