Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/resourcemanager_v3/services/tag_keys/async_client.py: 38%

175 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 functools 

18import re 

19from typing import ( 

20 Dict, 

21 Mapping, 

22 MutableMapping, 

23 MutableSequence, 

24 Optional, 

25 Sequence, 

26 Tuple, 

27 Type, 

28 Union, 

29) 

30 

31from google.api_core import exceptions as core_exceptions 

32from google.api_core import gapic_v1 

33from google.api_core import retry as retries 

34from google.api_core.client_options import ClientOptions 

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

36from google.oauth2 import service_account # type: ignore 

37 

38from google.cloud.resourcemanager_v3 import gapic_version as package_version 

39 

40try: 

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

42except AttributeError: # pragma: NO COVER 

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

44 

45from google.api_core import operation # type: ignore 

46from google.api_core import operation_async # type: ignore 

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

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

49from google.longrunning import operations_pb2 

50from google.protobuf import field_mask_pb2 # type: ignore 

51from google.protobuf import timestamp_pb2 # type: ignore 

52 

53from google.cloud.resourcemanager_v3.services.tag_keys import pagers 

54from google.cloud.resourcemanager_v3.types import tag_keys 

55 

56from .client import TagKeysClient 

57from .transports.base import DEFAULT_CLIENT_INFO, TagKeysTransport 

58from .transports.grpc_asyncio import TagKeysGrpcAsyncIOTransport 

59 

60 

61class TagKeysAsyncClient: 

62 """Allow users to create and manage tag keys.""" 

63 

64 _client: TagKeysClient 

65 

66 DEFAULT_ENDPOINT = TagKeysClient.DEFAULT_ENDPOINT 

67 DEFAULT_MTLS_ENDPOINT = TagKeysClient.DEFAULT_MTLS_ENDPOINT 

68 

69 tag_key_path = staticmethod(TagKeysClient.tag_key_path) 

70 parse_tag_key_path = staticmethod(TagKeysClient.parse_tag_key_path) 

71 common_billing_account_path = staticmethod( 

72 TagKeysClient.common_billing_account_path 

73 ) 

74 parse_common_billing_account_path = staticmethod( 

75 TagKeysClient.parse_common_billing_account_path 

76 ) 

77 common_folder_path = staticmethod(TagKeysClient.common_folder_path) 

78 parse_common_folder_path = staticmethod(TagKeysClient.parse_common_folder_path) 

79 common_organization_path = staticmethod(TagKeysClient.common_organization_path) 

80 parse_common_organization_path = staticmethod( 

81 TagKeysClient.parse_common_organization_path 

82 ) 

83 common_project_path = staticmethod(TagKeysClient.common_project_path) 

84 parse_common_project_path = staticmethod(TagKeysClient.parse_common_project_path) 

85 common_location_path = staticmethod(TagKeysClient.common_location_path) 

86 parse_common_location_path = staticmethod(TagKeysClient.parse_common_location_path) 

87 

88 @classmethod 

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

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

91 info. 

92 

93 Args: 

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

95 args: Additional arguments to pass to the constructor. 

96 kwargs: Additional arguments to pass to the constructor. 

97 

98 Returns: 

99 TagKeysAsyncClient: The constructed client. 

100 """ 

101 return TagKeysClient.from_service_account_info.__func__(TagKeysAsyncClient, info, *args, **kwargs) # type: ignore 

102 

103 @classmethod 

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

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

106 file. 

107 

108 Args: 

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

110 file. 

111 args: Additional arguments to pass to the constructor. 

112 kwargs: Additional arguments to pass to the constructor. 

113 

114 Returns: 

115 TagKeysAsyncClient: The constructed client. 

116 """ 

117 return TagKeysClient.from_service_account_file.__func__(TagKeysAsyncClient, filename, *args, **kwargs) # type: ignore 

118 

119 from_service_account_json = from_service_account_file 

120 

121 @classmethod 

122 def get_mtls_endpoint_and_cert_source( 

123 cls, client_options: Optional[ClientOptions] = None 

124 ): 

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

126 

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

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

129 client cert source is None. 

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

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

132 source is None. 

133 

134 The API endpoint is determined in the following order: 

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

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

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

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

139 use the default API endpoint. 

140 

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

142 

143 Args: 

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

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

146 in this method. 

147 

148 Returns: 

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

150 client cert source to use. 

151 

152 Raises: 

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

154 """ 

155 return TagKeysClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

156 

157 @property 

158 def transport(self) -> TagKeysTransport: 

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

160 

161 Returns: 

162 TagKeysTransport: The transport used by the client instance. 

163 """ 

164 return self._client.transport 

165 

166 get_transport_class = functools.partial( 

167 type(TagKeysClient).get_transport_class, type(TagKeysClient) 

168 ) 

169 

170 def __init__( 

171 self, 

172 *, 

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

174 transport: Union[str, TagKeysTransport] = "grpc_asyncio", 

175 client_options: Optional[ClientOptions] = None, 

176 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

177 ) -> None: 

178 """Instantiates the tag keys client. 

179 

180 Args: 

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

182 authorization credentials to attach to requests. These 

183 credentials identify the application to the service; if none 

184 are specified, the client will attempt to ascertain the 

185 credentials from the environment. 

186 transport (Union[str, ~.TagKeysTransport]): The 

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

188 automatically. 

189 client_options (ClientOptions): Custom options for the client. It 

190 won't take effect if a ``transport`` instance is provided. 

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

192 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

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

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

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

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

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

198 precedence if provided. 

199 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

201 to provide client certificate for mutual TLS transport. If 

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

203 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

204 set, no client certificate will be used. 

205 

206 Raises: 

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

208 creation failed for any reason. 

209 """ 

210 self._client = TagKeysClient( 

211 credentials=credentials, 

212 transport=transport, 

213 client_options=client_options, 

214 client_info=client_info, 

215 ) 

216 

217 async def list_tag_keys( 

218 self, 

219 request: Optional[Union[tag_keys.ListTagKeysRequest, dict]] = None, 

220 *, 

221 parent: Optional[str] = None, 

222 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

225 ) -> pagers.ListTagKeysAsyncPager: 

226 r"""Lists all TagKeys for a parent resource. 

227 

228 .. code-block:: python 

229 

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

231 # code template only. 

232 # It will require modifications to work: 

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

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

235 # client as shown in: 

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

237 from google.cloud import resourcemanager_v3 

238 

239 async def sample_list_tag_keys(): 

240 # Create a client 

241 client = resourcemanager_v3.TagKeysAsyncClient() 

242 

243 # Initialize request argument(s) 

244 request = resourcemanager_v3.ListTagKeysRequest( 

245 parent="parent_value", 

246 ) 

247 

248 # Make the request 

249 page_result = client.list_tag_keys(request=request) 

250 

251 # Handle the response 

252 async for response in page_result: 

253 print(response) 

254 

255 Args: 

256 request (Optional[Union[google.cloud.resourcemanager_v3.types.ListTagKeysRequest, dict]]): 

257 The request object. The request message for listing all 

258 TagKeys under a parent resource. 

259 parent (:class:`str`): 

260 Required. The resource name of the TagKey's parent. Must 

261 be of the form ``organizations/{org_id}`` or 

262 ``projects/{project_id}`` or 

263 ``projects/{project_number}`` 

264 

265 This corresponds to the ``parent`` field 

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

267 should not be set. 

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

269 should be retried. 

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

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

272 sent along with the request as metadata. 

273 

274 Returns: 

275 google.cloud.resourcemanager_v3.services.tag_keys.pagers.ListTagKeysAsyncPager: 

276 The ListTagKeys response message. 

277 Iterating over this object will yield 

278 results and resolve additional pages 

279 automatically. 

280 

281 """ 

282 # Create or coerce a protobuf request object. 

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

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

285 has_flattened_params = any([parent]) 

286 if request is not None and has_flattened_params: 

287 raise ValueError( 

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

289 "the individual field arguments should be set." 

290 ) 

291 

292 request = tag_keys.ListTagKeysRequest(request) 

293 

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

295 # request, apply these. 

296 if parent is not None: 

297 request.parent = parent 

298 

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

300 # and friendly error handling. 

301 rpc = gapic_v1.method_async.wrap_method( 

302 self._client._transport.list_tag_keys, 

303 default_retry=retries.Retry( 

304 initial=0.1, 

305 maximum=60.0, 

306 multiplier=1.3, 

307 predicate=retries.if_exception_type( 

308 core_exceptions.ServiceUnavailable, 

309 ), 

310 deadline=60.0, 

311 ), 

312 default_timeout=60.0, 

313 client_info=DEFAULT_CLIENT_INFO, 

314 ) 

315 

316 # Send the request. 

317 response = await rpc( 

318 request, 

319 retry=retry, 

320 timeout=timeout, 

321 metadata=metadata, 

322 ) 

323 

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

325 # an `__aiter__` convenience method. 

326 response = pagers.ListTagKeysAsyncPager( 

327 method=rpc, 

328 request=request, 

329 response=response, 

330 metadata=metadata, 

331 ) 

332 

333 # Done; return the response. 

334 return response 

335 

336 async def get_tag_key( 

337 self, 

338 request: Optional[Union[tag_keys.GetTagKeyRequest, dict]] = None, 

339 *, 

340 name: Optional[str] = None, 

341 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

344 ) -> tag_keys.TagKey: 

345 r"""Retrieves a TagKey. This method will return 

346 ``PERMISSION_DENIED`` if the key does not exist or the user does 

347 not have permission to view it. 

348 

349 .. code-block:: python 

350 

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

352 # code template only. 

353 # It will require modifications to work: 

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

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

356 # client as shown in: 

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

358 from google.cloud import resourcemanager_v3 

359 

360 async def sample_get_tag_key(): 

361 # Create a client 

362 client = resourcemanager_v3.TagKeysAsyncClient() 

363 

364 # Initialize request argument(s) 

365 request = resourcemanager_v3.GetTagKeyRequest( 

366 name="name_value", 

367 ) 

368 

369 # Make the request 

370 response = await client.get_tag_key(request=request) 

371 

372 # Handle the response 

373 print(response) 

374 

375 Args: 

376 request (Optional[Union[google.cloud.resourcemanager_v3.types.GetTagKeyRequest, dict]]): 

377 The request object. The request message for getting a 

378 TagKey. 

379 name (:class:`str`): 

380 Required. A resource name in the format 

381 ``tagKeys/{id}``, such as ``tagKeys/123``. 

382 

383 This corresponds to the ``name`` field 

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

385 should not be set. 

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

387 should be retried. 

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

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

390 sent along with the request as metadata. 

391 

392 Returns: 

393 google.cloud.resourcemanager_v3.types.TagKey: 

394 A TagKey, used to group a set of 

395 TagValues. 

396 

397 """ 

398 # Create or coerce a protobuf request object. 

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

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

401 has_flattened_params = any([name]) 

402 if request is not None and has_flattened_params: 

403 raise ValueError( 

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

405 "the individual field arguments should be set." 

406 ) 

407 

408 request = tag_keys.GetTagKeyRequest(request) 

409 

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

411 # request, apply these. 

412 if name is not None: 

413 request.name = name 

414 

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

416 # and friendly error handling. 

417 rpc = gapic_v1.method_async.wrap_method( 

418 self._client._transport.get_tag_key, 

419 default_retry=retries.Retry( 

420 initial=0.1, 

421 maximum=60.0, 

422 multiplier=1.3, 

423 predicate=retries.if_exception_type( 

424 core_exceptions.ServiceUnavailable, 

425 ), 

426 deadline=60.0, 

427 ), 

428 default_timeout=60.0, 

429 client_info=DEFAULT_CLIENT_INFO, 

430 ) 

431 

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

433 # add these here. 

434 metadata = tuple(metadata) + ( 

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

436 ) 

437 

438 # Send the request. 

439 response = await rpc( 

440 request, 

441 retry=retry, 

442 timeout=timeout, 

443 metadata=metadata, 

444 ) 

445 

446 # Done; return the response. 

447 return response 

448 

449 async def get_namespaced_tag_key( 

450 self, 

451 request: Optional[Union[tag_keys.GetNamespacedTagKeyRequest, dict]] = None, 

452 *, 

453 name: Optional[str] = None, 

454 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

457 ) -> tag_keys.TagKey: 

458 r"""Retrieves a TagKey by its namespaced name. This method will 

459 return ``PERMISSION_DENIED`` if the key does not exist or the 

460 user does not have permission to view it. 

461 

462 .. code-block:: python 

463 

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

465 # code template only. 

466 # It will require modifications to work: 

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

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

469 # client as shown in: 

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

471 from google.cloud import resourcemanager_v3 

472 

473 async def sample_get_namespaced_tag_key(): 

474 # Create a client 

475 client = resourcemanager_v3.TagKeysAsyncClient() 

476 

477 # Initialize request argument(s) 

478 request = resourcemanager_v3.GetNamespacedTagKeyRequest( 

479 name="name_value", 

480 ) 

481 

482 # Make the request 

483 response = await client.get_namespaced_tag_key(request=request) 

484 

485 # Handle the response 

486 print(response) 

487 

488 Args: 

489 request (Optional[Union[google.cloud.resourcemanager_v3.types.GetNamespacedTagKeyRequest, dict]]): 

490 The request object. The request message for getting a 

491 TagKey by its namespaced name. 

492 name (:class:`str`): 

493 Required. A namespaced tag key name in the format 

494 ``{parentId}/{tagKeyShort}``, such as ``42/foo`` for a 

495 key with short name "foo" under the organization with ID 

496 42 or ``r2-d2/bar`` for a key with short name "bar" 

497 under the project ``r2-d2``. 

498 

499 This corresponds to the ``name`` field 

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

501 should not be set. 

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

503 should be retried. 

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

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

506 sent along with the request as metadata. 

507 

508 Returns: 

509 google.cloud.resourcemanager_v3.types.TagKey: 

510 A TagKey, used to group a set of 

511 TagValues. 

512 

513 """ 

514 # Create or coerce a protobuf request object. 

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

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

517 has_flattened_params = any([name]) 

518 if request is not None and has_flattened_params: 

519 raise ValueError( 

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

521 "the individual field arguments should be set." 

522 ) 

523 

524 request = tag_keys.GetNamespacedTagKeyRequest(request) 

525 

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

527 # request, apply these. 

528 if name is not None: 

529 request.name = name 

530 

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

532 # and friendly error handling. 

533 rpc = gapic_v1.method_async.wrap_method( 

534 self._client._transport.get_namespaced_tag_key, 

535 default_timeout=None, 

536 client_info=DEFAULT_CLIENT_INFO, 

537 ) 

538 

539 # Send the request. 

540 response = await rpc( 

541 request, 

542 retry=retry, 

543 timeout=timeout, 

544 metadata=metadata, 

545 ) 

546 

547 # Done; return the response. 

548 return response 

549 

550 async def create_tag_key( 

551 self, 

552 request: Optional[Union[tag_keys.CreateTagKeyRequest, dict]] = None, 

553 *, 

554 tag_key: Optional[tag_keys.TagKey] = None, 

555 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

558 ) -> operation_async.AsyncOperation: 

559 r"""Creates a new TagKey. If another request with the 

560 same parameters is sent while the original request is in 

561 process, the second request will receive an error. A 

562 maximum of 1000 TagKeys can exist under a parent at any 

563 given time. 

564 

565 .. code-block:: python 

566 

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

568 # code template only. 

569 # It will require modifications to work: 

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

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

572 # client as shown in: 

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

574 from google.cloud import resourcemanager_v3 

575 

576 async def sample_create_tag_key(): 

577 # Create a client 

578 client = resourcemanager_v3.TagKeysAsyncClient() 

579 

580 # Initialize request argument(s) 

581 tag_key = resourcemanager_v3.TagKey() 

582 tag_key.short_name = "short_name_value" 

583 

584 request = resourcemanager_v3.CreateTagKeyRequest( 

585 tag_key=tag_key, 

586 ) 

587 

588 # Make the request 

589 operation = client.create_tag_key(request=request) 

590 

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

592 

593 response = (await operation).result() 

594 

595 # Handle the response 

596 print(response) 

597 

598 Args: 

599 request (Optional[Union[google.cloud.resourcemanager_v3.types.CreateTagKeyRequest, dict]]): 

600 The request object. The request message for creating a 

601 TagKey. 

602 tag_key (:class:`google.cloud.resourcemanager_v3.types.TagKey`): 

603 Required. The TagKey to be created. Only fields 

604 ``short_name``, ``description``, and ``parent`` are 

605 considered during the creation request. 

606 

607 This corresponds to the ``tag_key`` field 

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

609 should not be set. 

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

611 should be retried. 

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

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

614 sent along with the request as metadata. 

615 

616 Returns: 

617 google.api_core.operation_async.AsyncOperation: 

618 An object representing a long-running operation. 

619 

620 The result type for the operation will be 

621 :class:`google.cloud.resourcemanager_v3.types.TagKey` A 

622 TagKey, used to group a set of TagValues. 

623 

624 """ 

625 # Create or coerce a protobuf request object. 

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

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

628 has_flattened_params = any([tag_key]) 

629 if request is not None and has_flattened_params: 

630 raise ValueError( 

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

632 "the individual field arguments should be set." 

633 ) 

634 

635 request = tag_keys.CreateTagKeyRequest(request) 

636 

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

638 # request, apply these. 

639 if tag_key is not None: 

640 request.tag_key = tag_key 

641 

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

643 # and friendly error handling. 

644 rpc = gapic_v1.method_async.wrap_method( 

645 self._client._transport.create_tag_key, 

646 default_timeout=60.0, 

647 client_info=DEFAULT_CLIENT_INFO, 

648 ) 

649 

650 # Send the request. 

651 response = await rpc( 

652 request, 

653 retry=retry, 

654 timeout=timeout, 

655 metadata=metadata, 

656 ) 

657 

658 # Wrap the response in an operation future. 

659 response = operation_async.from_gapic( 

660 response, 

661 self._client._transport.operations_client, 

662 tag_keys.TagKey, 

663 metadata_type=tag_keys.CreateTagKeyMetadata, 

664 ) 

665 

666 # Done; return the response. 

667 return response 

668 

669 async def update_tag_key( 

670 self, 

671 request: Optional[Union[tag_keys.UpdateTagKeyRequest, dict]] = None, 

672 *, 

673 tag_key: Optional[tag_keys.TagKey] = None, 

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

675 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

678 ) -> operation_async.AsyncOperation: 

679 r"""Updates the attributes of the TagKey resource. 

680 

681 .. code-block:: python 

682 

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

684 # code template only. 

685 # It will require modifications to work: 

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

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

688 # client as shown in: 

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

690 from google.cloud import resourcemanager_v3 

691 

692 async def sample_update_tag_key(): 

693 # Create a client 

694 client = resourcemanager_v3.TagKeysAsyncClient() 

695 

696 # Initialize request argument(s) 

697 tag_key = resourcemanager_v3.TagKey() 

698 tag_key.short_name = "short_name_value" 

699 

700 request = resourcemanager_v3.UpdateTagKeyRequest( 

701 tag_key=tag_key, 

702 ) 

703 

704 # Make the request 

705 operation = client.update_tag_key(request=request) 

706 

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

708 

709 response = (await operation).result() 

710 

711 # Handle the response 

712 print(response) 

713 

714 Args: 

715 request (Optional[Union[google.cloud.resourcemanager_v3.types.UpdateTagKeyRequest, dict]]): 

716 The request object. The request message for updating a 

717 TagKey. 

718 tag_key (:class:`google.cloud.resourcemanager_v3.types.TagKey`): 

719 Required. The new definition of the TagKey. Only the 

720 ``description`` and ``etag`` fields can be updated by 

721 this request. If the ``etag`` field is not empty, it 

722 must match the ``etag`` field of the existing tag key. 

723 Otherwise, ``ABORTED`` will be returned. 

724 

725 This corresponds to the ``tag_key`` field 

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

727 should not be set. 

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

729 Fields to be updated. The mask may only contain 

730 ``description`` or ``etag``. If omitted entirely, both 

731 ``description`` and ``etag`` are assumed to be 

732 significant. 

733 

734 This corresponds to the ``update_mask`` field 

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

736 should not be set. 

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

738 should be retried. 

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

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

741 sent along with the request as metadata. 

742 

743 Returns: 

744 google.api_core.operation_async.AsyncOperation: 

745 An object representing a long-running operation. 

746 

747 The result type for the operation will be 

748 :class:`google.cloud.resourcemanager_v3.types.TagKey` A 

749 TagKey, used to group a set of TagValues. 

750 

751 """ 

752 # Create or coerce a protobuf request object. 

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

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

755 has_flattened_params = any([tag_key, update_mask]) 

756 if request is not None and has_flattened_params: 

757 raise ValueError( 

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

759 "the individual field arguments should be set." 

760 ) 

761 

762 request = tag_keys.UpdateTagKeyRequest(request) 

763 

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

765 # request, apply these. 

766 if tag_key is not None: 

767 request.tag_key = tag_key 

768 if update_mask is not None: 

769 request.update_mask = update_mask 

770 

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

772 # and friendly error handling. 

773 rpc = gapic_v1.method_async.wrap_method( 

774 self._client._transport.update_tag_key, 

775 default_timeout=60.0, 

776 client_info=DEFAULT_CLIENT_INFO, 

777 ) 

778 

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

780 # add these here. 

781 metadata = tuple(metadata) + ( 

782 gapic_v1.routing_header.to_grpc_metadata( 

783 (("tag_key.name", request.tag_key.name),) 

784 ), 

785 ) 

786 

787 # Send the request. 

788 response = await rpc( 

789 request, 

790 retry=retry, 

791 timeout=timeout, 

792 metadata=metadata, 

793 ) 

794 

795 # Wrap the response in an operation future. 

796 response = operation_async.from_gapic( 

797 response, 

798 self._client._transport.operations_client, 

799 tag_keys.TagKey, 

800 metadata_type=tag_keys.UpdateTagKeyMetadata, 

801 ) 

802 

803 # Done; return the response. 

804 return response 

805 

806 async def delete_tag_key( 

807 self, 

808 request: Optional[Union[tag_keys.DeleteTagKeyRequest, dict]] = None, 

809 *, 

810 name: Optional[str] = None, 

811 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

814 ) -> operation_async.AsyncOperation: 

815 r"""Deletes a TagKey. The TagKey cannot be deleted if it 

816 has any child TagValues. 

817 

818 .. code-block:: python 

819 

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

821 # code template only. 

822 # It will require modifications to work: 

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

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

825 # client as shown in: 

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

827 from google.cloud import resourcemanager_v3 

828 

829 async def sample_delete_tag_key(): 

830 # Create a client 

831 client = resourcemanager_v3.TagKeysAsyncClient() 

832 

833 # Initialize request argument(s) 

834 request = resourcemanager_v3.DeleteTagKeyRequest( 

835 name="name_value", 

836 ) 

837 

838 # Make the request 

839 operation = client.delete_tag_key(request=request) 

840 

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

842 

843 response = (await operation).result() 

844 

845 # Handle the response 

846 print(response) 

847 

848 Args: 

849 request (Optional[Union[google.cloud.resourcemanager_v3.types.DeleteTagKeyRequest, dict]]): 

850 The request object. The request message for deleting a 

851 TagKey. 

852 name (:class:`str`): 

853 Required. The resource name of a TagKey to be deleted in 

854 the format ``tagKeys/123``. The TagKey cannot be a 

855 parent of any existing TagValues or it will not be 

856 deleted successfully. 

857 

858 This corresponds to the ``name`` field 

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

860 should not be set. 

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

862 should be retried. 

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

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

865 sent along with the request as metadata. 

866 

867 Returns: 

868 google.api_core.operation_async.AsyncOperation: 

869 An object representing a long-running operation. 

870 

871 The result type for the operation will be 

872 :class:`google.cloud.resourcemanager_v3.types.TagKey` A 

873 TagKey, used to group a set of TagValues. 

874 

875 """ 

876 # Create or coerce a protobuf request object. 

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

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

879 has_flattened_params = any([name]) 

880 if request is not None and has_flattened_params: 

881 raise ValueError( 

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

883 "the individual field arguments should be set." 

884 ) 

885 

886 request = tag_keys.DeleteTagKeyRequest(request) 

887 

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

889 # request, apply these. 

890 if name is not None: 

891 request.name = name 

892 

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

894 # and friendly error handling. 

895 rpc = gapic_v1.method_async.wrap_method( 

896 self._client._transport.delete_tag_key, 

897 default_timeout=60.0, 

898 client_info=DEFAULT_CLIENT_INFO, 

899 ) 

900 

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

902 # add these here. 

903 metadata = tuple(metadata) + ( 

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

905 ) 

906 

907 # Send the request. 

908 response = await rpc( 

909 request, 

910 retry=retry, 

911 timeout=timeout, 

912 metadata=metadata, 

913 ) 

914 

915 # Wrap the response in an operation future. 

916 response = operation_async.from_gapic( 

917 response, 

918 self._client._transport.operations_client, 

919 tag_keys.TagKey, 

920 metadata_type=tag_keys.DeleteTagKeyMetadata, 

921 ) 

922 

923 # Done; return the response. 

924 return response 

925 

926 async def get_iam_policy( 

927 self, 

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

929 *, 

930 resource: Optional[str] = None, 

931 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

934 ) -> policy_pb2.Policy: 

935 r"""Gets the access control policy for a TagKey. The returned policy 

936 may be empty if no such policy or resource exists. The 

937 ``resource`` field should be the TagKey's resource name. For 

938 example, "tagKeys/1234". The caller must have 

939 ``cloudresourcemanager.googleapis.com/tagKeys.getIamPolicy`` 

940 permission on the specified TagKey. 

941 

942 .. code-block:: python 

943 

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

945 # code template only. 

946 # It will require modifications to work: 

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

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

949 # client as shown in: 

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

951 from google.cloud import resourcemanager_v3 

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

953 

954 async def sample_get_iam_policy(): 

955 # Create a client 

956 client = resourcemanager_v3.TagKeysAsyncClient() 

957 

958 # Initialize request argument(s) 

959 request = iam_policy_pb2.GetIamPolicyRequest( 

960 resource="resource_value", 

961 ) 

962 

963 # Make the request 

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

965 

966 # Handle the response 

967 print(response) 

968 

969 Args: 

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

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

972 resource (:class:`str`): 

973 REQUIRED: The resource for which the 

974 policy is being requested. See the 

975 operation documentation for the 

976 appropriate value for this field. 

977 

978 This corresponds to the ``resource`` field 

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

980 should not be set. 

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

982 should be retried. 

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

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

985 sent along with the request as metadata. 

986 

987 Returns: 

988 google.iam.v1.policy_pb2.Policy: 

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

990 controls for Google Cloud resources. 

991 

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

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

994 Principals can be user accounts, service accounts, 

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

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

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

998 

999 For some types of Google Cloud resources, a binding 

1000 can also specify a condition, which is a logical 

1001 expression that allows access to a resource only if 

1002 the expression evaluates to true. A condition can add 

1003 constraints based on attributes of the request, the 

1004 resource, or both. To learn which resources support 

1005 conditions in their IAM policies, see the [IAM 

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

1007 

1008 **JSON example:** 

1009 

1010 { 

1011 "bindings": [ 

1012 { 

1013 "role": 

1014 "roles/resourcemanager.organizationAdmin", 

1015 "members": [ "user:mike@example.com", 

1016 "group:admins@example.com", 

1017 "domain:google.com", 

1018 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

1019 ] 

1020 

1021 }, { "role": 

1022 "roles/resourcemanager.organizationViewer", 

1023 "members": [ "user:eve@example.com" ], 

1024 "condition": { "title": "expirable access", 

1025 "description": "Does not grant access after 

1026 Sep 2020", "expression": "request.time < 

1027 timestamp('2020-10-01T00:00:00.000Z')", } } 

1028 

1029 ], "etag": "BwWWja0YfJA=", "version": 3 

1030 

1031 } 

1032 

1033 **YAML example:** 

1034 

1035 bindings: - members: - user:\ mike@example.com - 

1036 group:\ admins@example.com - domain:google.com - 

1037 serviceAccount:\ my-project-id@appspot.gserviceaccount.com 

1038 role: roles/resourcemanager.organizationAdmin - 

1039 members: - user:\ eve@example.com role: 

1040 roles/resourcemanager.organizationViewer 

1041 condition: title: expirable access description: 

1042 Does not grant access after Sep 2020 expression: 

1043 request.time < 

1044 timestamp('2020-10-01T00:00:00.000Z') etag: 

1045 BwWWja0YfJA= version: 3 

1046 

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

1048 [IAM 

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

1050 

1051 """ 

1052 # Create or coerce a protobuf request object. 

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

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

1055 has_flattened_params = any([resource]) 

1056 if request is not None and has_flattened_params: 

1057 raise ValueError( 

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

1059 "the individual field arguments should be set." 

1060 ) 

1061 

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

1063 # so it must be constructed via keyword expansion. 

1064 if isinstance(request, dict): 

1065 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1066 elif not request: 

1067 request = iam_policy_pb2.GetIamPolicyRequest( 

1068 resource=resource, 

1069 ) 

1070 

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

1072 # and friendly error handling. 

1073 rpc = gapic_v1.method_async.wrap_method( 

1074 self._client._transport.get_iam_policy, 

1075 default_retry=retries.Retry( 

1076 initial=0.1, 

1077 maximum=60.0, 

1078 multiplier=1.3, 

1079 predicate=retries.if_exception_type( 

1080 core_exceptions.ServiceUnavailable, 

1081 ), 

1082 deadline=60.0, 

1083 ), 

1084 default_timeout=60.0, 

1085 client_info=DEFAULT_CLIENT_INFO, 

1086 ) 

1087 

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

1089 # add these here. 

1090 metadata = tuple(metadata) + ( 

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

1092 ) 

1093 

1094 # Send the request. 

1095 response = await rpc( 

1096 request, 

1097 retry=retry, 

1098 timeout=timeout, 

1099 metadata=metadata, 

1100 ) 

1101 

1102 # Done; return the response. 

1103 return response 

1104 

1105 async def set_iam_policy( 

1106 self, 

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

1108 *, 

1109 resource: Optional[str] = None, 

1110 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1113 ) -> policy_pb2.Policy: 

1114 r"""Sets the access control policy on a TagKey, replacing any 

1115 existing policy. The ``resource`` field should be the TagKey's 

1116 resource name. For example, "tagKeys/1234". The caller must have 

1117 ``resourcemanager.tagKeys.setIamPolicy`` permission on the 

1118 identified tagValue. 

1119 

1120 .. code-block:: python 

1121 

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

1123 # code template only. 

1124 # It will require modifications to work: 

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

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

1127 # client as shown in: 

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

1129 from google.cloud import resourcemanager_v3 

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

1131 

1132 async def sample_set_iam_policy(): 

1133 # Create a client 

1134 client = resourcemanager_v3.TagKeysAsyncClient() 

1135 

1136 # Initialize request argument(s) 

1137 request = iam_policy_pb2.SetIamPolicyRequest( 

1138 resource="resource_value", 

1139 ) 

1140 

1141 # Make the request 

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

1143 

1144 # Handle the response 

1145 print(response) 

1146 

1147 Args: 

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

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

1150 resource (:class:`str`): 

1151 REQUIRED: The resource for which the 

1152 policy is being specified. See the 

1153 operation documentation for the 

1154 appropriate value for this field. 

1155 

1156 This corresponds to the ``resource`` field 

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

1158 should not be set. 

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

1160 should be retried. 

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

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

1163 sent along with the request as metadata. 

1164 

1165 Returns: 

1166 google.iam.v1.policy_pb2.Policy: 

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

1168 controls for Google Cloud resources. 

1169 

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

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

1172 Principals can be user accounts, service accounts, 

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

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

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

1176 

1177 For some types of Google Cloud resources, a binding 

1178 can also specify a condition, which is a logical 

1179 expression that allows access to a resource only if 

1180 the expression evaluates to true. A condition can add 

1181 constraints based on attributes of the request, the 

1182 resource, or both. To learn which resources support 

1183 conditions in their IAM policies, see the [IAM 

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

1185 

1186 **JSON example:** 

1187 

1188 { 

1189 "bindings": [ 

1190 { 

1191 "role": 

1192 "roles/resourcemanager.organizationAdmin", 

1193 "members": [ "user:mike@example.com", 

1194 "group:admins@example.com", 

1195 "domain:google.com", 

1196 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

1197 ] 

1198 

1199 }, { "role": 

1200 "roles/resourcemanager.organizationViewer", 

1201 "members": [ "user:eve@example.com" ], 

1202 "condition": { "title": "expirable access", 

1203 "description": "Does not grant access after 

1204 Sep 2020", "expression": "request.time < 

1205 timestamp('2020-10-01T00:00:00.000Z')", } } 

1206 

1207 ], "etag": "BwWWja0YfJA=", "version": 3 

1208 

1209 } 

1210 

1211 **YAML example:** 

1212 

1213 bindings: - members: - user:\ mike@example.com - 

1214 group:\ admins@example.com - domain:google.com - 

1215 serviceAccount:\ my-project-id@appspot.gserviceaccount.com 

1216 role: roles/resourcemanager.organizationAdmin - 

1217 members: - user:\ eve@example.com role: 

1218 roles/resourcemanager.organizationViewer 

1219 condition: title: expirable access description: 

1220 Does not grant access after Sep 2020 expression: 

1221 request.time < 

1222 timestamp('2020-10-01T00:00:00.000Z') etag: 

1223 BwWWja0YfJA= version: 3 

1224 

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

1226 [IAM 

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

1228 

1229 """ 

1230 # Create or coerce a protobuf request object. 

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

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

1233 has_flattened_params = any([resource]) 

1234 if request is not None and has_flattened_params: 

1235 raise ValueError( 

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

1237 "the individual field arguments should be set." 

1238 ) 

1239 

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

1241 # so it must be constructed via keyword expansion. 

1242 if isinstance(request, dict): 

1243 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1244 elif not request: 

1245 request = iam_policy_pb2.SetIamPolicyRequest( 

1246 resource=resource, 

1247 ) 

1248 

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

1250 # and friendly error handling. 

1251 rpc = gapic_v1.method_async.wrap_method( 

1252 self._client._transport.set_iam_policy, 

1253 default_timeout=60.0, 

1254 client_info=DEFAULT_CLIENT_INFO, 

1255 ) 

1256 

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

1258 # add these here. 

1259 metadata = tuple(metadata) + ( 

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

1261 ) 

1262 

1263 # Send the request. 

1264 response = await rpc( 

1265 request, 

1266 retry=retry, 

1267 timeout=timeout, 

1268 metadata=metadata, 

1269 ) 

1270 

1271 # Done; return the response. 

1272 return response 

1273 

1274 async def test_iam_permissions( 

1275 self, 

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

1277 *, 

1278 resource: Optional[str] = None, 

1279 permissions: Optional[MutableSequence[str]] = None, 

1280 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1283 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1284 r"""Returns permissions that a caller has on the specified TagKey. 

1285 The ``resource`` field should be the TagKey's resource name. For 

1286 example, "tagKeys/1234". 

1287 

1288 There are no permissions required for making this API call. 

1289 

1290 .. code-block:: python 

1291 

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

1293 # code template only. 

1294 # It will require modifications to work: 

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

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

1297 # client as shown in: 

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

1299 from google.cloud import resourcemanager_v3 

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

1301 

1302 async def sample_test_iam_permissions(): 

1303 # Create a client 

1304 client = resourcemanager_v3.TagKeysAsyncClient() 

1305 

1306 # Initialize request argument(s) 

1307 request = iam_policy_pb2.TestIamPermissionsRequest( 

1308 resource="resource_value", 

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

1310 ) 

1311 

1312 # Make the request 

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

1314 

1315 # Handle the response 

1316 print(response) 

1317 

1318 Args: 

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

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

1321 resource (:class:`str`): 

1322 REQUIRED: The resource for which the 

1323 policy detail is being requested. See 

1324 the operation documentation for the 

1325 appropriate value for this field. 

1326 

1327 This corresponds to the ``resource`` field 

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

1329 should not be set. 

1330 permissions (:class:`MutableSequence[str]`): 

1331 The set of permissions to check for the ``resource``. 

1332 Permissions with wildcards (such as '*' or 'storage.*') 

1333 are not allowed. For more information see `IAM 

1334 Overview <https://cloud.google.com/iam/docs/overview#permissions>`__. 

1335 

1336 This corresponds to the ``permissions`` field 

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

1338 should not be set. 

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

1340 should be retried. 

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

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

1343 sent along with the request as metadata. 

1344 

1345 Returns: 

1346 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: 

1347 Response message for TestIamPermissions method. 

1348 """ 

1349 # Create or coerce a protobuf request object. 

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

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

1352 has_flattened_params = any([resource, permissions]) 

1353 if request is not None and has_flattened_params: 

1354 raise ValueError( 

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

1356 "the individual field arguments should be set." 

1357 ) 

1358 

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

1360 # so it must be constructed via keyword expansion. 

1361 if isinstance(request, dict): 

1362 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1363 elif not request: 

1364 request = iam_policy_pb2.TestIamPermissionsRequest( 

1365 resource=resource, 

1366 permissions=permissions, 

1367 ) 

1368 

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

1370 # and friendly error handling. 

1371 rpc = gapic_v1.method_async.wrap_method( 

1372 self._client._transport.test_iam_permissions, 

1373 default_timeout=None, 

1374 client_info=DEFAULT_CLIENT_INFO, 

1375 ) 

1376 

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

1378 # add these here. 

1379 metadata = tuple(metadata) + ( 

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

1381 ) 

1382 

1383 # Send the request. 

1384 response = await rpc( 

1385 request, 

1386 retry=retry, 

1387 timeout=timeout, 

1388 metadata=metadata, 

1389 ) 

1390 

1391 # Done; return the response. 

1392 return response 

1393 

1394 async def get_operation( 

1395 self, 

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

1397 *, 

1398 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1401 ) -> operations_pb2.Operation: 

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

1403 

1404 Args: 

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

1406 The request object. Request message for 

1407 `GetOperation` method. 

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

1409 if any, should be retried. 

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

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

1412 sent along with the request as metadata. 

1413 Returns: 

1414 ~.operations_pb2.Operation: 

1415 An ``Operation`` object. 

1416 """ 

1417 # Create or coerce a protobuf request object. 

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

1419 # so it must be constructed via keyword expansion. 

1420 if isinstance(request, dict): 

1421 request = operations_pb2.GetOperationRequest(**request) 

1422 

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

1424 # and friendly error handling. 

1425 rpc = gapic_v1.method.wrap_method( 

1426 self._client._transport.get_operation, 

1427 default_timeout=None, 

1428 client_info=DEFAULT_CLIENT_INFO, 

1429 ) 

1430 

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

1432 # add these here. 

1433 metadata = tuple(metadata) + ( 

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

1435 ) 

1436 

1437 # Send the request. 

1438 response = await rpc( 

1439 request, 

1440 retry=retry, 

1441 timeout=timeout, 

1442 metadata=metadata, 

1443 ) 

1444 

1445 # Done; return the response. 

1446 return response 

1447 

1448 async def __aenter__(self): 

1449 return self 

1450 

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

1452 await self.transport.close() 

1453 

1454 

1455DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1456 gapic_version=package_version.__version__ 

1457) 

1458 

1459 

1460__all__ = ("TagKeysAsyncClient",)