Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/resourcemanager_v3/services/tag_holds/client.py: 42%

203 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-06 06:03 +0000

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

2# Copyright 2022 Google LLC 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

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

9# 

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

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

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

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

14# limitations under the License. 

15# 

16from collections import OrderedDict 

17import os 

18import re 

19from typing import ( 

20 Dict, 

21 Mapping, 

22 MutableMapping, 

23 MutableSequence, 

24 Optional, 

25 Sequence, 

26 Tuple, 

27 Type, 

28 Union, 

29 cast, 

30) 

31 

32from google.api_core import client_options as client_options_lib 

33from google.api_core import exceptions as core_exceptions 

34from google.api_core import gapic_v1 

35from google.api_core import retry as retries 

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

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

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

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

40from google.oauth2 import service_account # type: ignore 

41 

42from google.cloud.resourcemanager_v3 import gapic_version as package_version 

43 

44try: 

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

46except AttributeError: # pragma: NO COVER 

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

48 

49from google.api_core import operation # type: ignore 

50from google.api_core import operation_async # type: ignore 

51from google.longrunning import operations_pb2 

52from google.protobuf import empty_pb2 # type: ignore 

53 

54from google.cloud.resourcemanager_v3.services.tag_holds import pagers 

55from google.cloud.resourcemanager_v3.types import tag_holds 

56 

57from .transports.base import DEFAULT_CLIENT_INFO, TagHoldsTransport 

58from .transports.grpc import TagHoldsGrpcTransport 

59from .transports.grpc_asyncio import TagHoldsGrpcAsyncIOTransport 

60from .transports.rest import TagHoldsRestTransport 

61 

62 

63class TagHoldsClientMeta(type): 

64 """Metaclass for the TagHolds client. 

65 

66 This provides class-level methods for building and retrieving 

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

68 objects. 

69 """ 

70 

71 _transport_registry = OrderedDict() # type: Dict[str, Type[TagHoldsTransport]] 

72 _transport_registry["grpc"] = TagHoldsGrpcTransport 

73 _transport_registry["grpc_asyncio"] = TagHoldsGrpcAsyncIOTransport 

74 _transport_registry["rest"] = TagHoldsRestTransport 

75 

76 def get_transport_class( 

77 cls, 

78 label: Optional[str] = None, 

79 ) -> Type[TagHoldsTransport]: 

80 """Returns an appropriate transport class. 

81 

82 Args: 

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

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

85 

86 Returns: 

87 The transport class to use. 

88 """ 

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

90 if label: 

91 return cls._transport_registry[label] 

92 

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

94 # in the dictionary). 

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

96 

97 

98class TagHoldsClient(metaclass=TagHoldsClientMeta): 

99 """Allow users to create and manage TagHolds for TagValues. 

100 TagHolds represent the use of a Tag Value that is not captured 

101 by TagBindings but should still block TagValue deletion (such as 

102 a reference in a policy condition). This service provides 

103 isolated failure domains by cloud location so that TagHolds can 

104 be managed in the same location as their usage. 

105 """ 

106 

107 @staticmethod 

108 def _get_default_mtls_endpoint(api_endpoint): 

109 """Converts api endpoint to mTLS endpoint. 

110 

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

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

113 Args: 

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

115 Returns: 

116 str: converted mTLS api endpoint. 

117 """ 

118 if not api_endpoint: 

119 return api_endpoint 

120 

121 mtls_endpoint_re = re.compile( 

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

123 ) 

124 

125 m = mtls_endpoint_re.match(api_endpoint) 

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

127 if mtls or not googledomain: 

128 return api_endpoint 

129 

130 if sandbox: 

131 return api_endpoint.replace( 

132 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

133 ) 

134 

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

136 

137 DEFAULT_ENDPOINT = "cloudresourcemanager.googleapis.com" 

138 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

139 DEFAULT_ENDPOINT 

140 ) 

141 

142 @classmethod 

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

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

145 info. 

146 

147 Args: 

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

149 args: Additional arguments to pass to the constructor. 

150 kwargs: Additional arguments to pass to the constructor. 

151 

152 Returns: 

153 TagHoldsClient: The constructed client. 

154 """ 

155 credentials = service_account.Credentials.from_service_account_info(info) 

156 kwargs["credentials"] = credentials 

157 return cls(*args, **kwargs) 

158 

159 @classmethod 

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

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

162 file. 

163 

164 Args: 

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

166 file. 

167 args: Additional arguments to pass to the constructor. 

168 kwargs: Additional arguments to pass to the constructor. 

169 

170 Returns: 

171 TagHoldsClient: The constructed client. 

172 """ 

173 credentials = service_account.Credentials.from_service_account_file(filename) 

174 kwargs["credentials"] = credentials 

175 return cls(*args, **kwargs) 

176 

177 from_service_account_json = from_service_account_file 

178 

179 @property 

180 def transport(self) -> TagHoldsTransport: 

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

182 

183 Returns: 

184 TagHoldsTransport: The transport used by the client 

185 instance. 

186 """ 

187 return self._transport 

188 

189 @staticmethod 

190 def tag_hold_path( 

191 tag_value: str, 

192 tag_hold: str, 

193 ) -> str: 

194 """Returns a fully-qualified tag_hold string.""" 

195 return "tagValues/{tag_value}/tagHolds/{tag_hold}".format( 

196 tag_value=tag_value, 

197 tag_hold=tag_hold, 

198 ) 

199 

200 @staticmethod 

201 def parse_tag_hold_path(path: str) -> Dict[str, str]: 

202 """Parses a tag_hold path into its component segments.""" 

203 m = re.match(r"^tagValues/(?P<tag_value>.+?)/tagHolds/(?P<tag_hold>.+?)$", path) 

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

205 

206 @staticmethod 

207 def common_billing_account_path( 

208 billing_account: str, 

209 ) -> str: 

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

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

212 billing_account=billing_account, 

213 ) 

214 

215 @staticmethod 

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

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

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

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

220 

221 @staticmethod 

222 def common_folder_path( 

223 folder: str, 

224 ) -> str: 

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

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

227 folder=folder, 

228 ) 

229 

230 @staticmethod 

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

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

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

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

235 

236 @staticmethod 

237 def common_organization_path( 

238 organization: str, 

239 ) -> str: 

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

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

242 organization=organization, 

243 ) 

244 

245 @staticmethod 

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

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

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

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

250 

251 @staticmethod 

252 def common_project_path( 

253 project: str, 

254 ) -> str: 

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

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

257 project=project, 

258 ) 

259 

260 @staticmethod 

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

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

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

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

265 

266 @staticmethod 

267 def common_location_path( 

268 project: str, 

269 location: str, 

270 ) -> str: 

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

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

273 project=project, 

274 location=location, 

275 ) 

276 

277 @staticmethod 

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

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

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

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

282 

283 @classmethod 

284 def get_mtls_endpoint_and_cert_source( 

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

286 ): 

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

288 

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

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

291 client cert source is None. 

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

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

294 source is None. 

295 

296 The API endpoint is determined in the following order: 

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

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

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

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

301 use the default API endpoint. 

302 

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

304 

305 Args: 

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

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

308 in this method. 

309 

310 Returns: 

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

312 client cert source to use. 

313 

314 Raises: 

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

316 """ 

317 if client_options is None: 

318 client_options = client_options_lib.ClientOptions() 

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

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

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

322 raise ValueError( 

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

324 ) 

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

326 raise MutualTLSChannelError( 

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

328 ) 

329 

330 # Figure out the client cert source to use. 

331 client_cert_source = None 

332 if use_client_cert == "true": 

333 if client_options.client_cert_source: 

334 client_cert_source = client_options.client_cert_source 

335 elif mtls.has_default_client_cert_source(): 

336 client_cert_source = mtls.default_client_cert_source() 

337 

338 # Figure out which api endpoint to use. 

339 if client_options.api_endpoint is not None: 

340 api_endpoint = client_options.api_endpoint 

341 elif use_mtls_endpoint == "always" or ( 

342 use_mtls_endpoint == "auto" and client_cert_source 

343 ): 

344 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

345 else: 

346 api_endpoint = cls.DEFAULT_ENDPOINT 

347 

348 return api_endpoint, client_cert_source 

349 

350 def __init__( 

351 self, 

352 *, 

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

354 transport: Optional[Union[str, TagHoldsTransport]] = None, 

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

356 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

357 ) -> None: 

358 """Instantiates the tag holds client. 

359 

360 Args: 

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

362 authorization credentials to attach to requests. These 

363 credentials identify the application to the service; if none 

364 are specified, the client will attempt to ascertain the 

365 credentials from the environment. 

366 transport (Union[str, TagHoldsTransport]): The 

367 transport to use. If set to None, a transport is chosen 

368 automatically. 

369 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the 

370 client. It won't take effect if a ``transport`` instance is provided. 

371 (1) The ``api_endpoint`` property can be used to override the 

372 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

373 environment variable can also be used to override the endpoint: 

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

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

376 default mTLS endpoint if client certificate is present, this is 

377 the default value). However, the ``api_endpoint`` property takes 

378 precedence if provided. 

379 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

381 to provide client certificate for mutual TLS transport. If 

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

383 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

384 set, no client certificate will be used. 

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

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

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

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

389 your own client library. 

390 

391 Raises: 

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

393 creation failed for any reason. 

394 """ 

395 if isinstance(client_options, dict): 

396 client_options = client_options_lib.from_dict(client_options) 

397 if client_options is None: 

398 client_options = client_options_lib.ClientOptions() 

399 client_options = cast(client_options_lib.ClientOptions, client_options) 

400 

401 api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( 

402 client_options 

403 ) 

404 

405 api_key_value = getattr(client_options, "api_key", None) 

406 if api_key_value and credentials: 

407 raise ValueError( 

408 "client_options.api_key and credentials are mutually exclusive" 

409 ) 

410 

411 # Save or instantiate the transport. 

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

413 # instance provides an extensibility point for unusual situations. 

414 if isinstance(transport, TagHoldsTransport): 

415 # transport is a TagHoldsTransport instance. 

416 if credentials or client_options.credentials_file or api_key_value: 

417 raise ValueError( 

418 "When providing a transport instance, " 

419 "provide its credentials directly." 

420 ) 

421 if client_options.scopes: 

422 raise ValueError( 

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

424 "directly." 

425 ) 

426 self._transport = transport 

427 else: 

428 import google.auth._default # type: ignore 

429 

430 if api_key_value and hasattr( 

431 google.auth._default, "get_api_key_credentials" 

432 ): 

433 credentials = google.auth._default.get_api_key_credentials( 

434 api_key_value 

435 ) 

436 

437 Transport = type(self).get_transport_class(transport) 

438 self._transport = Transport( 

439 credentials=credentials, 

440 credentials_file=client_options.credentials_file, 

441 host=api_endpoint, 

442 scopes=client_options.scopes, 

443 client_cert_source_for_mtls=client_cert_source_func, 

444 quota_project_id=client_options.quota_project_id, 

445 client_info=client_info, 

446 always_use_jwt_access=True, 

447 api_audience=client_options.api_audience, 

448 ) 

449 

450 def create_tag_hold( 

451 self, 

452 request: Optional[Union[tag_holds.CreateTagHoldRequest, dict]] = None, 

453 *, 

454 parent: Optional[str] = None, 

455 tag_hold: Optional[tag_holds.TagHold] = None, 

456 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

459 ) -> operation.Operation: 

460 r"""Creates a TagHold. Returns ALREADY_EXISTS if a TagHold with the 

461 same resource and origin exists under the same TagValue. 

462 

463 .. code-block:: python 

464 

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

466 # code template only. 

467 # It will require modifications to work: 

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

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

470 # client as shown in: 

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

472 from google.cloud import resourcemanager_v3 

473 

474 def sample_create_tag_hold(): 

475 # Create a client 

476 client = resourcemanager_v3.TagHoldsClient() 

477 

478 # Initialize request argument(s) 

479 tag_hold = resourcemanager_v3.TagHold() 

480 tag_hold.holder = "holder_value" 

481 

482 request = resourcemanager_v3.CreateTagHoldRequest( 

483 parent="parent_value", 

484 tag_hold=tag_hold, 

485 ) 

486 

487 # Make the request 

488 operation = client.create_tag_hold(request=request) 

489 

490 print("Waiting for operation to complete...") 

491 

492 response = operation.result() 

493 

494 # Handle the response 

495 print(response) 

496 

497 Args: 

498 request (Union[google.cloud.resourcemanager_v3.types.CreateTagHoldRequest, dict]): 

499 The request object. The request message to create a 

500 TagHold. 

501 parent (str): 

502 Required. The resource name of the TagHold's parent 

503 TagValue. Must be of the form: 

504 ``tagValues/{tag-value-id}``. 

505 

506 This corresponds to the ``parent`` field 

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

508 should not be set. 

509 tag_hold (google.cloud.resourcemanager_v3.types.TagHold): 

510 Required. The TagHold to be created. 

511 This corresponds to the ``tag_hold`` field 

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

513 should not be set. 

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

515 should be retried. 

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

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

518 sent along with the request as metadata. 

519 

520 Returns: 

521 google.api_core.operation.Operation: 

522 An object representing a long-running operation. 

523 

524 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.TagHold` A TagHold represents the use of a TagValue that is not captured by 

525 TagBindings. If a TagValue has any TagHolds, deletion 

526 will be blocked. This resource is intended to be 

527 created in the same cloud location as the holder. 

528 

529 """ 

530 # Create or coerce a protobuf request object. 

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

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

533 has_flattened_params = any([parent, tag_hold]) 

534 if request is not None and has_flattened_params: 

535 raise ValueError( 

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

537 "the individual field arguments should be set." 

538 ) 

539 

540 # Minor optimization to avoid making a copy if the user passes 

541 # in a tag_holds.CreateTagHoldRequest. 

542 # There's no risk of modifying the input as we've already verified 

543 # there are no flattened fields. 

544 if not isinstance(request, tag_holds.CreateTagHoldRequest): 

545 request = tag_holds.CreateTagHoldRequest(request) 

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

547 # request, apply these. 

548 if parent is not None: 

549 request.parent = parent 

550 if tag_hold is not None: 

551 request.tag_hold = tag_hold 

552 

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

554 # and friendly error handling. 

555 rpc = self._transport._wrapped_methods[self._transport.create_tag_hold] 

556 

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

558 # add these here. 

559 metadata = tuple(metadata) + ( 

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

561 ) 

562 

563 # Send the request. 

564 response = rpc( 

565 request, 

566 retry=retry, 

567 timeout=timeout, 

568 metadata=metadata, 

569 ) 

570 

571 # Wrap the response in an operation future. 

572 response = operation.from_gapic( 

573 response, 

574 self._transport.operations_client, 

575 tag_holds.TagHold, 

576 metadata_type=tag_holds.CreateTagHoldMetadata, 

577 ) 

578 

579 # Done; return the response. 

580 return response 

581 

582 def delete_tag_hold( 

583 self, 

584 request: Optional[Union[tag_holds.DeleteTagHoldRequest, dict]] = None, 

585 *, 

586 name: Optional[str] = None, 

587 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

590 ) -> operation.Operation: 

591 r"""Deletes a TagHold. 

592 

593 .. code-block:: python 

594 

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

596 # code template only. 

597 # It will require modifications to work: 

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

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

600 # client as shown in: 

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

602 from google.cloud import resourcemanager_v3 

603 

604 def sample_delete_tag_hold(): 

605 # Create a client 

606 client = resourcemanager_v3.TagHoldsClient() 

607 

608 # Initialize request argument(s) 

609 request = resourcemanager_v3.DeleteTagHoldRequest( 

610 name="name_value", 

611 ) 

612 

613 # Make the request 

614 operation = client.delete_tag_hold(request=request) 

615 

616 print("Waiting for operation to complete...") 

617 

618 response = operation.result() 

619 

620 # Handle the response 

621 print(response) 

622 

623 Args: 

624 request (Union[google.cloud.resourcemanager_v3.types.DeleteTagHoldRequest, dict]): 

625 The request object. The request message to delete a 

626 TagHold. 

627 name (str): 

628 Required. The resource name of the TagHold to delete. 

629 Must be of the form: 

630 ``tagValues/{tag-value-id}/tagHolds/{tag-hold-id}``. 

631 

632 This corresponds to the ``name`` field 

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

634 should not be set. 

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

636 should be retried. 

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

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

639 sent along with the request as metadata. 

640 

641 Returns: 

642 google.api_core.operation.Operation: 

643 An object representing a long-running operation. 

644 

645 The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated 

646 empty messages in your APIs. A typical example is to 

647 use it as the request or the response type of an API 

648 method. For instance: 

649 

650 service Foo { 

651 rpc Bar(google.protobuf.Empty) returns 

652 (google.protobuf.Empty); 

653 

654 } 

655 

656 """ 

657 # Create or coerce a protobuf request object. 

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

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

660 has_flattened_params = any([name]) 

661 if request is not None and has_flattened_params: 

662 raise ValueError( 

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

664 "the individual field arguments should be set." 

665 ) 

666 

667 # Minor optimization to avoid making a copy if the user passes 

668 # in a tag_holds.DeleteTagHoldRequest. 

669 # There's no risk of modifying the input as we've already verified 

670 # there are no flattened fields. 

671 if not isinstance(request, tag_holds.DeleteTagHoldRequest): 

672 request = tag_holds.DeleteTagHoldRequest(request) 

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

674 # request, apply these. 

675 if name is not None: 

676 request.name = name 

677 

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

679 # and friendly error handling. 

680 rpc = self._transport._wrapped_methods[self._transport.delete_tag_hold] 

681 

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

683 # add these here. 

684 metadata = tuple(metadata) + ( 

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

686 ) 

687 

688 # Send the request. 

689 response = rpc( 

690 request, 

691 retry=retry, 

692 timeout=timeout, 

693 metadata=metadata, 

694 ) 

695 

696 # Wrap the response in an operation future. 

697 response = operation.from_gapic( 

698 response, 

699 self._transport.operations_client, 

700 empty_pb2.Empty, 

701 metadata_type=tag_holds.DeleteTagHoldMetadata, 

702 ) 

703 

704 # Done; return the response. 

705 return response 

706 

707 def list_tag_holds( 

708 self, 

709 request: Optional[Union[tag_holds.ListTagHoldsRequest, dict]] = None, 

710 *, 

711 parent: Optional[str] = None, 

712 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

715 ) -> pagers.ListTagHoldsPager: 

716 r"""Lists TagHolds under a TagValue. 

717 

718 .. code-block:: python 

719 

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

721 # code template only. 

722 # It will require modifications to work: 

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

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

725 # client as shown in: 

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

727 from google.cloud import resourcemanager_v3 

728 

729 def sample_list_tag_holds(): 

730 # Create a client 

731 client = resourcemanager_v3.TagHoldsClient() 

732 

733 # Initialize request argument(s) 

734 request = resourcemanager_v3.ListTagHoldsRequest( 

735 parent="parent_value", 

736 ) 

737 

738 # Make the request 

739 page_result = client.list_tag_holds(request=request) 

740 

741 # Handle the response 

742 for response in page_result: 

743 print(response) 

744 

745 Args: 

746 request (Union[google.cloud.resourcemanager_v3.types.ListTagHoldsRequest, dict]): 

747 The request object. The request message for listing the 

748 TagHolds under a TagValue. 

749 parent (str): 

750 Required. The resource name of the parent TagValue. Must 

751 be of the form: ``tagValues/{tag-value-id}``. 

752 

753 This corresponds to the ``parent`` field 

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

755 should not be set. 

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

757 should be retried. 

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

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

760 sent along with the request as metadata. 

761 

762 Returns: 

763 google.cloud.resourcemanager_v3.services.tag_holds.pagers.ListTagHoldsPager: 

764 The ListTagHolds response. 

765 Iterating over this object will yield 

766 results and resolve additional pages 

767 automatically. 

768 

769 """ 

770 # Create or coerce a protobuf request object. 

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

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

773 has_flattened_params = any([parent]) 

774 if request is not None and has_flattened_params: 

775 raise ValueError( 

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

777 "the individual field arguments should be set." 

778 ) 

779 

780 # Minor optimization to avoid making a copy if the user passes 

781 # in a tag_holds.ListTagHoldsRequest. 

782 # There's no risk of modifying the input as we've already verified 

783 # there are no flattened fields. 

784 if not isinstance(request, tag_holds.ListTagHoldsRequest): 

785 request = tag_holds.ListTagHoldsRequest(request) 

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

787 # request, apply these. 

788 if parent is not None: 

789 request.parent = parent 

790 

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

792 # and friendly error handling. 

793 rpc = self._transport._wrapped_methods[self._transport.list_tag_holds] 

794 

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

796 # add these here. 

797 metadata = tuple(metadata) + ( 

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

799 ) 

800 

801 # Send the request. 

802 response = rpc( 

803 request, 

804 retry=retry, 

805 timeout=timeout, 

806 metadata=metadata, 

807 ) 

808 

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

810 # an `__iter__` convenience method. 

811 response = pagers.ListTagHoldsPager( 

812 method=rpc, 

813 request=request, 

814 response=response, 

815 metadata=metadata, 

816 ) 

817 

818 # Done; return the response. 

819 return response 

820 

821 def __enter__(self) -> "TagHoldsClient": 

822 return self 

823 

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

825 """Releases underlying transport's resources. 

826 

827 .. warning:: 

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

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

830 and may cause errors in other clients! 

831 """ 

832 self.transport.close() 

833 

834 def get_operation( 

835 self, 

836 request: Optional[operations_pb2.GetOperationRequest] = None, 

837 *, 

838 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

841 ) -> operations_pb2.Operation: 

842 r"""Gets the latest state of a long-running operation. 

843 

844 Args: 

845 request (:class:`~.operations_pb2.GetOperationRequest`): 

846 The request object. Request message for 

847 `GetOperation` method. 

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

849 if any, should be retried. 

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

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

852 sent along with the request as metadata. 

853 Returns: 

854 ~.operations_pb2.Operation: 

855 An ``Operation`` object. 

856 """ 

857 # Create or coerce a protobuf request object. 

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

859 # so it must be constructed via keyword expansion. 

860 if isinstance(request, dict): 

861 request = operations_pb2.GetOperationRequest(**request) 

862 

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

864 # and friendly error handling. 

865 rpc = gapic_v1.method.wrap_method( 

866 self._transport.get_operation, 

867 default_timeout=None, 

868 client_info=DEFAULT_CLIENT_INFO, 

869 ) 

870 

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

872 # add these here. 

873 metadata = tuple(metadata) + ( 

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

875 ) 

876 

877 # Send the request. 

878 response = rpc( 

879 request, 

880 retry=retry, 

881 timeout=timeout, 

882 metadata=metadata, 

883 ) 

884 

885 # Done; return the response. 

886 return response 

887 

888 

889DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

890 gapic_version=package_version.__version__ 

891) 

892 

893 

894__all__ = ("TagHoldsClient",)