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

202 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.projects import pagers 

54from google.cloud.resourcemanager_v3.types import projects 

55 

56from .client import ProjectsClient 

57from .transports.base import DEFAULT_CLIENT_INFO, ProjectsTransport 

58from .transports.grpc_asyncio import ProjectsGrpcAsyncIOTransport 

59 

60 

61class ProjectsAsyncClient: 

62 """Manages Google Cloud Projects.""" 

63 

64 _client: ProjectsClient 

65 

66 DEFAULT_ENDPOINT = ProjectsClient.DEFAULT_ENDPOINT 

67 DEFAULT_MTLS_ENDPOINT = ProjectsClient.DEFAULT_MTLS_ENDPOINT 

68 

69 project_path = staticmethod(ProjectsClient.project_path) 

70 parse_project_path = staticmethod(ProjectsClient.parse_project_path) 

71 common_billing_account_path = staticmethod( 

72 ProjectsClient.common_billing_account_path 

73 ) 

74 parse_common_billing_account_path = staticmethod( 

75 ProjectsClient.parse_common_billing_account_path 

76 ) 

77 common_folder_path = staticmethod(ProjectsClient.common_folder_path) 

78 parse_common_folder_path = staticmethod(ProjectsClient.parse_common_folder_path) 

79 common_organization_path = staticmethod(ProjectsClient.common_organization_path) 

80 parse_common_organization_path = staticmethod( 

81 ProjectsClient.parse_common_organization_path 

82 ) 

83 common_project_path = staticmethod(ProjectsClient.common_project_path) 

84 parse_common_project_path = staticmethod(ProjectsClient.parse_common_project_path) 

85 common_location_path = staticmethod(ProjectsClient.common_location_path) 

86 parse_common_location_path = staticmethod(ProjectsClient.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 ProjectsAsyncClient: The constructed client. 

100 """ 

101 return ProjectsClient.from_service_account_info.__func__(ProjectsAsyncClient, 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 ProjectsAsyncClient: The constructed client. 

116 """ 

117 return ProjectsClient.from_service_account_file.__func__(ProjectsAsyncClient, 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 ProjectsClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

156 

157 @property 

158 def transport(self) -> ProjectsTransport: 

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

160 

161 Returns: 

162 ProjectsTransport: The transport used by the client instance. 

163 """ 

164 return self._client.transport 

165 

166 get_transport_class = functools.partial( 

167 type(ProjectsClient).get_transport_class, type(ProjectsClient) 

168 ) 

169 

170 def __init__( 

171 self, 

172 *, 

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

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

175 client_options: Optional[ClientOptions] = None, 

176 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

177 ) -> None: 

178 """Instantiates the projects 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, ~.ProjectsTransport]): 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 = ProjectsClient( 

211 credentials=credentials, 

212 transport=transport, 

213 client_options=client_options, 

214 client_info=client_info, 

215 ) 

216 

217 async def get_project( 

218 self, 

219 request: Optional[Union[projects.GetProjectRequest, dict]] = None, 

220 *, 

221 name: 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 ) -> projects.Project: 

226 r"""Retrieves the project identified by the specified ``name`` (for 

227 example, ``projects/415104041262``). 

228 

229 The caller must have ``resourcemanager.projects.get`` permission 

230 for this project. 

231 

232 .. code-block:: python 

233 

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

235 # code template only. 

236 # It will require modifications to work: 

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

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

239 # client as shown in: 

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

241 from google.cloud import resourcemanager_v3 

242 

243 async def sample_get_project(): 

244 # Create a client 

245 client = resourcemanager_v3.ProjectsAsyncClient() 

246 

247 # Initialize request argument(s) 

248 request = resourcemanager_v3.GetProjectRequest( 

249 name="name_value", 

250 ) 

251 

252 # Make the request 

253 response = await client.get_project(request=request) 

254 

255 # Handle the response 

256 print(response) 

257 

258 Args: 

259 request (Optional[Union[google.cloud.resourcemanager_v3.types.GetProjectRequest, dict]]): 

260 The request object. The request sent to the 

261 [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] 

262 method. 

263 name (:class:`str`): 

264 Required. The name of the project (for example, 

265 ``projects/415104041262``). 

266 

267 This corresponds to the ``name`` field 

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

269 should not be set. 

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

271 should be retried. 

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

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

274 sent along with the request as metadata. 

275 

276 Returns: 

277 google.cloud.resourcemanager_v3.types.Project: 

278 A project is a high-level Google 

279 Cloud entity. It is a container for 

280 ACLs, APIs, App Engine Apps, VMs, and 

281 other Google Cloud Platform resources. 

282 

283 """ 

284 # Create or coerce a protobuf request object. 

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

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

287 has_flattened_params = any([name]) 

288 if request is not None and has_flattened_params: 

289 raise ValueError( 

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

291 "the individual field arguments should be set." 

292 ) 

293 

294 request = projects.GetProjectRequest(request) 

295 

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

297 # request, apply these. 

298 if name is not None: 

299 request.name = name 

300 

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

302 # and friendly error handling. 

303 rpc = gapic_v1.method_async.wrap_method( 

304 self._client._transport.get_project, 

305 default_retry=retries.Retry( 

306 initial=0.1, 

307 maximum=60.0, 

308 multiplier=1.3, 

309 predicate=retries.if_exception_type( 

310 core_exceptions.ServiceUnavailable, 

311 ), 

312 deadline=60.0, 

313 ), 

314 default_timeout=60.0, 

315 client_info=DEFAULT_CLIENT_INFO, 

316 ) 

317 

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

319 # add these here. 

320 metadata = tuple(metadata) + ( 

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

322 ) 

323 

324 # Send the request. 

325 response = await rpc( 

326 request, 

327 retry=retry, 

328 timeout=timeout, 

329 metadata=metadata, 

330 ) 

331 

332 # Done; return the response. 

333 return response 

334 

335 async def list_projects( 

336 self, 

337 request: Optional[Union[projects.ListProjectsRequest, dict]] = None, 

338 *, 

339 parent: Optional[str] = None, 

340 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

343 ) -> pagers.ListProjectsAsyncPager: 

344 r"""Lists projects that are direct children of the specified folder 

345 or organization resource. ``list()`` provides a strongly 

346 consistent view of the projects underneath the specified parent 

347 resource. ``list()`` returns projects sorted based upon the 

348 (ascending) lexical ordering of their ``display_name``. The 

349 caller must have ``resourcemanager.projects.list`` permission on 

350 the identified parent. 

351 

352 .. code-block:: python 

353 

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

355 # code template only. 

356 # It will require modifications to work: 

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

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

359 # client as shown in: 

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

361 from google.cloud import resourcemanager_v3 

362 

363 async def sample_list_projects(): 

364 # Create a client 

365 client = resourcemanager_v3.ProjectsAsyncClient() 

366 

367 # Initialize request argument(s) 

368 request = resourcemanager_v3.ListProjectsRequest( 

369 parent="parent_value", 

370 ) 

371 

372 # Make the request 

373 page_result = client.list_projects(request=request) 

374 

375 # Handle the response 

376 async for response in page_result: 

377 print(response) 

378 

379 Args: 

380 request (Optional[Union[google.cloud.resourcemanager_v3.types.ListProjectsRequest, dict]]): 

381 The request object. The request sent to the 

382 [ListProjects][google.cloud.resourcemanager.v3.Projects.ListProjects] 

383 method. 

384 parent (:class:`str`): 

385 Required. The name of the parent resource whose projects 

386 are being listed. Only children of this parent resource 

387 are listed; descendants are not listed. 

388 

389 If the parent is a folder, use the value 

390 ``folders/{folder_id}``. If the parent is an 

391 organization, use the value ``organizations/{org_id}``. 

392 

393 This corresponds to the ``parent`` field 

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

395 should not be set. 

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

397 should be retried. 

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

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

400 sent along with the request as metadata. 

401 

402 Returns: 

403 google.cloud.resourcemanager_v3.services.projects.pagers.ListProjectsAsyncPager: 

404 A page of the response received from the 

405 [ListProjects][google.cloud.resourcemanager.v3.Projects.ListProjects] 

406 method. 

407 

408 A paginated response where more pages are available 

409 has next_page_token set. This token can be used in a 

410 subsequent request to retrieve the next request page. 

411 

412 NOTE: A response may contain fewer elements than the 

413 request page_size and still have a next_page_token. 

414 

415 Iterating over this object will yield results and 

416 resolve additional pages automatically. 

417 

418 """ 

419 # Create or coerce a protobuf request object. 

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

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

422 has_flattened_params = any([parent]) 

423 if request is not None and has_flattened_params: 

424 raise ValueError( 

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

426 "the individual field arguments should be set." 

427 ) 

428 

429 request = projects.ListProjectsRequest(request) 

430 

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

432 # request, apply these. 

433 if parent is not None: 

434 request.parent = parent 

435 

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

437 # and friendly error handling. 

438 rpc = gapic_v1.method_async.wrap_method( 

439 self._client._transport.list_projects, 

440 default_retry=retries.Retry( 

441 initial=0.1, 

442 maximum=60.0, 

443 multiplier=1.3, 

444 predicate=retries.if_exception_type( 

445 core_exceptions.ServiceUnavailable, 

446 ), 

447 deadline=60.0, 

448 ), 

449 default_timeout=60.0, 

450 client_info=DEFAULT_CLIENT_INFO, 

451 ) 

452 

453 # Send the request. 

454 response = await rpc( 

455 request, 

456 retry=retry, 

457 timeout=timeout, 

458 metadata=metadata, 

459 ) 

460 

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

462 # an `__aiter__` convenience method. 

463 response = pagers.ListProjectsAsyncPager( 

464 method=rpc, 

465 request=request, 

466 response=response, 

467 metadata=metadata, 

468 ) 

469 

470 # Done; return the response. 

471 return response 

472 

473 async def search_projects( 

474 self, 

475 request: Optional[Union[projects.SearchProjectsRequest, dict]] = None, 

476 *, 

477 query: Optional[str] = None, 

478 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

481 ) -> pagers.SearchProjectsAsyncPager: 

482 r"""Search for projects that the caller has both 

483 ``resourcemanager.projects.get`` permission on, and also satisfy 

484 the specified query. 

485 

486 This method returns projects in an unspecified order. 

487 

488 This method is eventually consistent with project mutations; 

489 this means that a newly created project may not appear in the 

490 results or recent updates to an existing project may not be 

491 reflected in the results. To retrieve the latest state of a 

492 project, use the 

493 [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] 

494 method. 

495 

496 .. code-block:: python 

497 

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

499 # code template only. 

500 # It will require modifications to work: 

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

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

503 # client as shown in: 

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

505 from google.cloud import resourcemanager_v3 

506 

507 async def sample_search_projects(): 

508 # Create a client 

509 client = resourcemanager_v3.ProjectsAsyncClient() 

510 

511 # Initialize request argument(s) 

512 request = resourcemanager_v3.SearchProjectsRequest( 

513 ) 

514 

515 # Make the request 

516 page_result = client.search_projects(request=request) 

517 

518 # Handle the response 

519 async for response in page_result: 

520 print(response) 

521 

522 Args: 

523 request (Optional[Union[google.cloud.resourcemanager_v3.types.SearchProjectsRequest, dict]]): 

524 The request object. The request sent to the 

525 [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] 

526 method. 

527 query (:class:`str`): 

528 Optional. A query string for searching for projects that 

529 the caller has ``resourcemanager.projects.get`` 

530 permission to. If multiple fields are included in the 

531 query, then it will return results that match any of the 

532 fields. Some eligible fields are: 

533 

534 - **``displayName``, ``name``**: Filters by 

535 displayName. 

536 - **``parent``**: Project's parent (for example: 

537 ``folders/123``, ``organizations/*``). Prefer 

538 ``parent`` field over ``parent.type`` and 

539 ``parent.id``. 

540 - **``parent.type``**: Parent's type: ``folder`` or 

541 ``organization``. 

542 - **``parent.id``**: Parent's id number (for example: 

543 ``123``). 

544 - **``id``, ``projectId``**: Filters by projectId. 

545 - **``state``, ``lifecycleState``**: Filters by state. 

546 - **``labels``**: Filters by label name or value. 

547 - **``labels.<key>`` (where ``<key>`` is the name of a 

548 label)**: Filters by label name. 

549 

550 Search expressions are case insensitive. 

551 

552 Some examples queries: 

553 

554 - **``name:how*``**: The project's name starts with 

555 "how". 

556 - **``name:Howl``**: The project's name is ``Howl`` or 

557 ``howl``. 

558 - **``name:HOWL``**: Equivalent to above. 

559 - **``NAME:howl``**: Equivalent to above. 

560 - **``labels.color:*``**: The project has the label 

561 ``color``. 

562 - **``labels.color:red``**: The project's label 

563 ``color`` has the value ``red``. 

564 - **``labels.color:red labels.size:big``**: The 

565 project's label ``color`` has the value ``red`` or 

566 its label ``size`` has the value ``big``. 

567 

568 If no query is specified, the call will return projects 

569 for which the user has the 

570 ``resourcemanager.projects.get`` permission. 

571 

572 This corresponds to the ``query`` field 

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

574 should not be set. 

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

576 should be retried. 

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

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

579 sent along with the request as metadata. 

580 

581 Returns: 

582 google.cloud.resourcemanager_v3.services.projects.pagers.SearchProjectsAsyncPager: 

583 A page of the response received from the 

584 [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] 

585 method. 

586 

587 A paginated response where more pages are available 

588 has next_page_token set. This token can be used in a 

589 subsequent request to retrieve the next request page. 

590 

591 Iterating over this object will yield results and 

592 resolve additional pages automatically. 

593 

594 """ 

595 # Create or coerce a protobuf request object. 

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

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

598 has_flattened_params = any([query]) 

599 if request is not None and has_flattened_params: 

600 raise ValueError( 

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

602 "the individual field arguments should be set." 

603 ) 

604 

605 request = projects.SearchProjectsRequest(request) 

606 

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

608 # request, apply these. 

609 if query is not None: 

610 request.query = query 

611 

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

613 # and friendly error handling. 

614 rpc = gapic_v1.method_async.wrap_method( 

615 self._client._transport.search_projects, 

616 default_timeout=60.0, 

617 client_info=DEFAULT_CLIENT_INFO, 

618 ) 

619 

620 # Send the request. 

621 response = await rpc( 

622 request, 

623 retry=retry, 

624 timeout=timeout, 

625 metadata=metadata, 

626 ) 

627 

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

629 # an `__aiter__` convenience method. 

630 response = pagers.SearchProjectsAsyncPager( 

631 method=rpc, 

632 request=request, 

633 response=response, 

634 metadata=metadata, 

635 ) 

636 

637 # Done; return the response. 

638 return response 

639 

640 async def create_project( 

641 self, 

642 request: Optional[Union[projects.CreateProjectRequest, dict]] = None, 

643 *, 

644 project: Optional[projects.Project] = None, 

645 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

648 ) -> operation_async.AsyncOperation: 

649 r"""Request that a new project be created. The result is an 

650 ``Operation`` which can be used to track the creation process. 

651 This process usually takes a few seconds, but can sometimes take 

652 much longer. The tracking ``Operation`` is automatically deleted 

653 after a few hours, so there is no need to call 

654 ``DeleteOperation``. 

655 

656 .. code-block:: python 

657 

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

659 # code template only. 

660 # It will require modifications to work: 

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

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

663 # client as shown in: 

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

665 from google.cloud import resourcemanager_v3 

666 

667 async def sample_create_project(): 

668 # Create a client 

669 client = resourcemanager_v3.ProjectsAsyncClient() 

670 

671 # Initialize request argument(s) 

672 request = resourcemanager_v3.CreateProjectRequest( 

673 ) 

674 

675 # Make the request 

676 operation = client.create_project(request=request) 

677 

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

679 

680 response = (await operation).result() 

681 

682 # Handle the response 

683 print(response) 

684 

685 Args: 

686 request (Optional[Union[google.cloud.resourcemanager_v3.types.CreateProjectRequest, dict]]): 

687 The request object. The request sent to the 

688 [CreateProject][google.cloud.resourcemanager.v3.Projects.CreateProject] 

689 method. 

690 project (:class:`google.cloud.resourcemanager_v3.types.Project`): 

691 Required. The Project to create. 

692 

693 Project ID is required. If the requested ID is 

694 unavailable, the request fails. 

695 

696 If the ``parent`` field is set, the 

697 ``resourcemanager.projects.create`` permission is 

698 checked on the parent resource. If no parent is set and 

699 the authorization credentials belong to an Organization, 

700 the parent will be set to that Organization. 

701 

702 This corresponds to the ``project`` field 

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

704 should not be set. 

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

706 should be retried. 

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

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

709 sent along with the request as metadata. 

710 

711 Returns: 

712 google.api_core.operation_async.AsyncOperation: 

713 An object representing a long-running operation. 

714 

715 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Project` A project is a high-level Google Cloud entity. It is a 

716 container for ACLs, APIs, App Engine Apps, VMs, and 

717 other Google Cloud Platform resources. 

718 

719 """ 

720 # Create or coerce a protobuf request object. 

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

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

723 has_flattened_params = any([project]) 

724 if request is not None and has_flattened_params: 

725 raise ValueError( 

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

727 "the individual field arguments should be set." 

728 ) 

729 

730 request = projects.CreateProjectRequest(request) 

731 

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

733 # request, apply these. 

734 if project is not None: 

735 request.project = project 

736 

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

738 # and friendly error handling. 

739 rpc = gapic_v1.method_async.wrap_method( 

740 self._client._transport.create_project, 

741 default_timeout=60.0, 

742 client_info=DEFAULT_CLIENT_INFO, 

743 ) 

744 

745 # Send the request. 

746 response = await rpc( 

747 request, 

748 retry=retry, 

749 timeout=timeout, 

750 metadata=metadata, 

751 ) 

752 

753 # Wrap the response in an operation future. 

754 response = operation_async.from_gapic( 

755 response, 

756 self._client._transport.operations_client, 

757 projects.Project, 

758 metadata_type=projects.CreateProjectMetadata, 

759 ) 

760 

761 # Done; return the response. 

762 return response 

763 

764 async def update_project( 

765 self, 

766 request: Optional[Union[projects.UpdateProjectRequest, dict]] = None, 

767 *, 

768 project: Optional[projects.Project] = None, 

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

770 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

773 ) -> operation_async.AsyncOperation: 

774 r"""Updates the ``display_name`` and labels of the project 

775 identified by the specified ``name`` (for example, 

776 ``projects/415104041262``). Deleting all labels requires an 

777 update mask for labels field. 

778 

779 The caller must have ``resourcemanager.projects.update`` 

780 permission for this project. 

781 

782 .. code-block:: python 

783 

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

785 # code template only. 

786 # It will require modifications to work: 

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

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

789 # client as shown in: 

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

791 from google.cloud import resourcemanager_v3 

792 

793 async def sample_update_project(): 

794 # Create a client 

795 client = resourcemanager_v3.ProjectsAsyncClient() 

796 

797 # Initialize request argument(s) 

798 request = resourcemanager_v3.UpdateProjectRequest( 

799 ) 

800 

801 # Make the request 

802 operation = client.update_project(request=request) 

803 

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

805 

806 response = (await operation).result() 

807 

808 # Handle the response 

809 print(response) 

810 

811 Args: 

812 request (Optional[Union[google.cloud.resourcemanager_v3.types.UpdateProjectRequest, dict]]): 

813 The request object. The request sent to the 

814 [UpdateProject][google.cloud.resourcemanager.v3.Projects.UpdateProject] 

815 method. 

816 

817 Only the ``display_name`` and ``labels`` fields can be 

818 change. Use the 

819 [MoveProject][google.cloud.resourcemanager.v3.Projects.MoveProject] 

820 method to change the ``parent`` field. 

821 project (:class:`google.cloud.resourcemanager_v3.types.Project`): 

822 Required. The new definition of the 

823 project. 

824 

825 This corresponds to the ``project`` field 

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

827 should not be set. 

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

829 Optional. An update mask to 

830 selectively update fields. 

831 

832 This corresponds to the ``update_mask`` field 

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

834 should not be set. 

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

836 should be retried. 

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

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

839 sent along with the request as metadata. 

840 

841 Returns: 

842 google.api_core.operation_async.AsyncOperation: 

843 An object representing a long-running operation. 

844 

845 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Project` A project is a high-level Google Cloud entity. It is a 

846 container for ACLs, APIs, App Engine Apps, VMs, and 

847 other Google Cloud Platform resources. 

848 

849 """ 

850 # Create or coerce a protobuf request object. 

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

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

853 has_flattened_params = any([project, update_mask]) 

854 if request is not None and has_flattened_params: 

855 raise ValueError( 

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

857 "the individual field arguments should be set." 

858 ) 

859 

860 request = projects.UpdateProjectRequest(request) 

861 

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

863 # request, apply these. 

864 if project is not None: 

865 request.project = project 

866 if update_mask is not None: 

867 request.update_mask = update_mask 

868 

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

870 # and friendly error handling. 

871 rpc = gapic_v1.method_async.wrap_method( 

872 self._client._transport.update_project, 

873 default_timeout=60.0, 

874 client_info=DEFAULT_CLIENT_INFO, 

875 ) 

876 

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

878 # add these here. 

879 metadata = tuple(metadata) + ( 

880 gapic_v1.routing_header.to_grpc_metadata( 

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

882 ), 

883 ) 

884 

885 # Send the request. 

886 response = await rpc( 

887 request, 

888 retry=retry, 

889 timeout=timeout, 

890 metadata=metadata, 

891 ) 

892 

893 # Wrap the response in an operation future. 

894 response = operation_async.from_gapic( 

895 response, 

896 self._client._transport.operations_client, 

897 projects.Project, 

898 metadata_type=projects.UpdateProjectMetadata, 

899 ) 

900 

901 # Done; return the response. 

902 return response 

903 

904 async def move_project( 

905 self, 

906 request: Optional[Union[projects.MoveProjectRequest, dict]] = None, 

907 *, 

908 name: Optional[str] = None, 

909 destination_parent: Optional[str] = None, 

910 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

913 ) -> operation_async.AsyncOperation: 

914 r"""Move a project to another place in your resource hierarchy, 

915 under a new resource parent. 

916 

917 Returns an operation which can be used to track the process of 

918 the project move workflow. Upon success, the 

919 ``Operation.response`` field will be populated with the moved 

920 project. 

921 

922 The caller must have ``resourcemanager.projects.move`` 

923 permission on the project, on the project's current and proposed 

924 new parent. 

925 

926 If project has no current parent, or it currently does not have 

927 an associated organization resource, you will also need the 

928 ``resourcemanager.projects.setIamPolicy`` permission in the 

929 project. 

930 

931 .. code-block:: python 

932 

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

934 # code template only. 

935 # It will require modifications to work: 

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

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

938 # client as shown in: 

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

940 from google.cloud import resourcemanager_v3 

941 

942 async def sample_move_project(): 

943 # Create a client 

944 client = resourcemanager_v3.ProjectsAsyncClient() 

945 

946 # Initialize request argument(s) 

947 request = resourcemanager_v3.MoveProjectRequest( 

948 name="name_value", 

949 destination_parent="destination_parent_value", 

950 ) 

951 

952 # Make the request 

953 operation = client.move_project(request=request) 

954 

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

956 

957 response = (await operation).result() 

958 

959 # Handle the response 

960 print(response) 

961 

962 Args: 

963 request (Optional[Union[google.cloud.resourcemanager_v3.types.MoveProjectRequest, dict]]): 

964 The request object. The request sent to 

965 [MoveProject][google.cloud.resourcemanager.v3.Projects.MoveProject] 

966 method. 

967 name (:class:`str`): 

968 Required. The name of the project to 

969 move. 

970 

971 This corresponds to the ``name`` field 

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

973 should not be set. 

974 destination_parent (:class:`str`): 

975 Required. The new parent to move the 

976 Project under. 

977 

978 This corresponds to the ``destination_parent`` 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.api_core.operation_async.AsyncOperation: 

989 An object representing a long-running operation. 

990 

991 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Project` A project is a high-level Google Cloud entity. It is a 

992 container for ACLs, APIs, App Engine Apps, VMs, and 

993 other Google Cloud Platform resources. 

994 

995 """ 

996 # Create or coerce a protobuf request object. 

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

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

999 has_flattened_params = any([name, destination_parent]) 

1000 if request is not None and has_flattened_params: 

1001 raise ValueError( 

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

1003 "the individual field arguments should be set." 

1004 ) 

1005 

1006 request = projects.MoveProjectRequest(request) 

1007 

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

1009 # request, apply these. 

1010 if name is not None: 

1011 request.name = name 

1012 if destination_parent is not None: 

1013 request.destination_parent = destination_parent 

1014 

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

1016 # and friendly error handling. 

1017 rpc = gapic_v1.method_async.wrap_method( 

1018 self._client._transport.move_project, 

1019 default_timeout=60.0, 

1020 client_info=DEFAULT_CLIENT_INFO, 

1021 ) 

1022 

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

1024 # add these here. 

1025 metadata = tuple(metadata) + ( 

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

1027 ) 

1028 

1029 # Send the request. 

1030 response = await rpc( 

1031 request, 

1032 retry=retry, 

1033 timeout=timeout, 

1034 metadata=metadata, 

1035 ) 

1036 

1037 # Wrap the response in an operation future. 

1038 response = operation_async.from_gapic( 

1039 response, 

1040 self._client._transport.operations_client, 

1041 projects.Project, 

1042 metadata_type=projects.MoveProjectMetadata, 

1043 ) 

1044 

1045 # Done; return the response. 

1046 return response 

1047 

1048 async def delete_project( 

1049 self, 

1050 request: Optional[Union[projects.DeleteProjectRequest, dict]] = None, 

1051 *, 

1052 name: Optional[str] = None, 

1053 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1056 ) -> operation_async.AsyncOperation: 

1057 r"""Marks the project identified by the specified ``name`` (for 

1058 example, ``projects/415104041262``) for deletion. 

1059 

1060 This method will only affect the project if it has a lifecycle 

1061 state of 

1062 [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE]. 

1063 

1064 This method changes the Project's lifecycle state from 

1065 [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] 

1066 to 

1067 [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. 

1068 The deletion starts at an unspecified time, at which point the 

1069 Project is no longer accessible. 

1070 

1071 Until the deletion completes, you can check the lifecycle state 

1072 checked by retrieving the project with [GetProject] 

1073 [google.cloud.resourcemanager.v3.Projects.GetProject], and the 

1074 project remains visible to [ListProjects] 

1075 [google.cloud.resourcemanager.v3.Projects.ListProjects]. 

1076 However, you cannot update the project. 

1077 

1078 After the deletion completes, the project is not retrievable by 

1079 the [GetProject] 

1080 [google.cloud.resourcemanager.v3.Projects.GetProject], 

1081 [ListProjects] 

1082 [google.cloud.resourcemanager.v3.Projects.ListProjects], and 

1083 [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] 

1084 methods. 

1085 

1086 This method behaves idempotently, such that deleting a 

1087 ``DELETE_REQUESTED`` project will not cause an error, but also 

1088 won't do anything. 

1089 

1090 The caller must have ``resourcemanager.projects.delete`` 

1091 permissions for this project. 

1092 

1093 .. code-block:: python 

1094 

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

1096 # code template only. 

1097 # It will require modifications to work: 

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

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

1100 # client as shown in: 

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

1102 from google.cloud import resourcemanager_v3 

1103 

1104 async def sample_delete_project(): 

1105 # Create a client 

1106 client = resourcemanager_v3.ProjectsAsyncClient() 

1107 

1108 # Initialize request argument(s) 

1109 request = resourcemanager_v3.DeleteProjectRequest( 

1110 name="name_value", 

1111 ) 

1112 

1113 # Make the request 

1114 operation = client.delete_project(request=request) 

1115 

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

1117 

1118 response = (await operation).result() 

1119 

1120 # Handle the response 

1121 print(response) 

1122 

1123 Args: 

1124 request (Optional[Union[google.cloud.resourcemanager_v3.types.DeleteProjectRequest, dict]]): 

1125 The request object. [DeleteProject][google.cloud.resourcemanager.v3.Projects.DeleteProject] 

1126 method. 

1127 name (:class:`str`): 

1128 Required. The name of the Project (for example, 

1129 ``projects/415104041262``). 

1130 

1131 This corresponds to the ``name`` field 

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

1133 should not be set. 

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

1135 should be retried. 

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

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

1138 sent along with the request as metadata. 

1139 

1140 Returns: 

1141 google.api_core.operation_async.AsyncOperation: 

1142 An object representing a long-running operation. 

1143 

1144 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Project` A project is a high-level Google Cloud entity. It is a 

1145 container for ACLs, APIs, App Engine Apps, VMs, and 

1146 other Google Cloud Platform resources. 

1147 

1148 """ 

1149 # Create or coerce a protobuf request object. 

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

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

1152 has_flattened_params = any([name]) 

1153 if request is not None and has_flattened_params: 

1154 raise ValueError( 

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

1156 "the individual field arguments should be set." 

1157 ) 

1158 

1159 request = projects.DeleteProjectRequest(request) 

1160 

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

1162 # request, apply these. 

1163 if name is not None: 

1164 request.name = name 

1165 

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

1167 # and friendly error handling. 

1168 rpc = gapic_v1.method_async.wrap_method( 

1169 self._client._transport.delete_project, 

1170 default_timeout=60.0, 

1171 client_info=DEFAULT_CLIENT_INFO, 

1172 ) 

1173 

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

1175 # add these here. 

1176 metadata = tuple(metadata) + ( 

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

1178 ) 

1179 

1180 # Send the request. 

1181 response = await rpc( 

1182 request, 

1183 retry=retry, 

1184 timeout=timeout, 

1185 metadata=metadata, 

1186 ) 

1187 

1188 # Wrap the response in an operation future. 

1189 response = operation_async.from_gapic( 

1190 response, 

1191 self._client._transport.operations_client, 

1192 projects.Project, 

1193 metadata_type=projects.DeleteProjectMetadata, 

1194 ) 

1195 

1196 # Done; return the response. 

1197 return response 

1198 

1199 async def undelete_project( 

1200 self, 

1201 request: Optional[Union[projects.UndeleteProjectRequest, dict]] = None, 

1202 *, 

1203 name: Optional[str] = None, 

1204 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1207 ) -> operation_async.AsyncOperation: 

1208 r"""Restores the project identified by the specified ``name`` (for 

1209 example, ``projects/415104041262``). You can only use this 

1210 method for a project that has a lifecycle state of 

1211 [DELETE_REQUESTED] [Projects.State.DELETE_REQUESTED]. After 

1212 deletion starts, the project cannot be restored. 

1213 

1214 The caller must have ``resourcemanager.projects.undelete`` 

1215 permission for this project. 

1216 

1217 .. code-block:: python 

1218 

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

1220 # code template only. 

1221 # It will require modifications to work: 

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

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

1224 # client as shown in: 

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

1226 from google.cloud import resourcemanager_v3 

1227 

1228 async def sample_undelete_project(): 

1229 # Create a client 

1230 client = resourcemanager_v3.ProjectsAsyncClient() 

1231 

1232 # Initialize request argument(s) 

1233 request = resourcemanager_v3.UndeleteProjectRequest( 

1234 name="name_value", 

1235 ) 

1236 

1237 # Make the request 

1238 operation = client.undelete_project(request=request) 

1239 

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

1241 

1242 response = (await operation).result() 

1243 

1244 # Handle the response 

1245 print(response) 

1246 

1247 Args: 

1248 request (Optional[Union[google.cloud.resourcemanager_v3.types.UndeleteProjectRequest, dict]]): 

1249 The request object. The request sent to the [UndeleteProject] 

1250 [google.cloud.resourcemanager.v3.Projects.UndeleteProject] 

1251 method. 

1252 name (:class:`str`): 

1253 Required. The name of the project (for example, 

1254 ``projects/415104041262``). 

1255 

1256 Required. 

1257 

1258 This corresponds to the ``name`` field 

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

1260 should not be set. 

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

1262 should be retried. 

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

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

1265 sent along with the request as metadata. 

1266 

1267 Returns: 

1268 google.api_core.operation_async.AsyncOperation: 

1269 An object representing a long-running operation. 

1270 

1271 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.Project` A project is a high-level Google Cloud entity. It is a 

1272 container for ACLs, APIs, App Engine Apps, VMs, and 

1273 other Google Cloud Platform resources. 

1274 

1275 """ 

1276 # Create or coerce a protobuf request object. 

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

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

1279 has_flattened_params = any([name]) 

1280 if request is not None and has_flattened_params: 

1281 raise ValueError( 

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

1283 "the individual field arguments should be set." 

1284 ) 

1285 

1286 request = projects.UndeleteProjectRequest(request) 

1287 

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

1289 # request, apply these. 

1290 if name is not None: 

1291 request.name = name 

1292 

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

1294 # and friendly error handling. 

1295 rpc = gapic_v1.method_async.wrap_method( 

1296 self._client._transport.undelete_project, 

1297 default_timeout=60.0, 

1298 client_info=DEFAULT_CLIENT_INFO, 

1299 ) 

1300 

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

1302 # add these here. 

1303 metadata = tuple(metadata) + ( 

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

1305 ) 

1306 

1307 # Send the request. 

1308 response = await rpc( 

1309 request, 

1310 retry=retry, 

1311 timeout=timeout, 

1312 metadata=metadata, 

1313 ) 

1314 

1315 # Wrap the response in an operation future. 

1316 response = operation_async.from_gapic( 

1317 response, 

1318 self._client._transport.operations_client, 

1319 projects.Project, 

1320 metadata_type=projects.UndeleteProjectMetadata, 

1321 ) 

1322 

1323 # Done; return the response. 

1324 return response 

1325 

1326 async def get_iam_policy( 

1327 self, 

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

1329 *, 

1330 resource: Optional[str] = None, 

1331 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1334 ) -> policy_pb2.Policy: 

1335 r"""Returns the IAM access control policy for the specified project, 

1336 in the format ``projects/{ProjectIdOrNumber}`` e.g. 

1337 projects/123. Permission is denied if the policy or the resource 

1338 do not exist. 

1339 

1340 .. code-block:: python 

1341 

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

1343 # code template only. 

1344 # It will require modifications to work: 

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

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

1347 # client as shown in: 

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

1349 from google.cloud import resourcemanager_v3 

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

1351 

1352 async def sample_get_iam_policy(): 

1353 # Create a client 

1354 client = resourcemanager_v3.ProjectsAsyncClient() 

1355 

1356 # Initialize request argument(s) 

1357 request = iam_policy_pb2.GetIamPolicyRequest( 

1358 resource="resource_value", 

1359 ) 

1360 

1361 # Make the request 

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

1363 

1364 # Handle the response 

1365 print(response) 

1366 

1367 Args: 

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

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

1370 resource (:class:`str`): 

1371 REQUIRED: The resource for which the 

1372 policy is being requested. See the 

1373 operation documentation for the 

1374 appropriate value for this field. 

1375 

1376 This corresponds to the ``resource`` field 

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

1378 should not be set. 

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

1380 should be retried. 

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

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

1383 sent along with the request as metadata. 

1384 

1385 Returns: 

1386 google.iam.v1.policy_pb2.Policy: 

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

1388 controls for Google Cloud resources. 

1389 

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

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

1392 Principals can be user accounts, service accounts, 

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

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

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

1396 

1397 For some types of Google Cloud resources, a binding 

1398 can also specify a condition, which is a logical 

1399 expression that allows access to a resource only if 

1400 the expression evaluates to true. A condition can add 

1401 constraints based on attributes of the request, the 

1402 resource, or both. To learn which resources support 

1403 conditions in their IAM policies, see the [IAM 

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

1405 

1406 **JSON example:** 

1407 

1408 { 

1409 "bindings": [ 

1410 { 

1411 "role": 

1412 "roles/resourcemanager.organizationAdmin", 

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

1414 "group:admins@example.com", 

1415 "domain:google.com", 

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

1417 ] 

1418 

1419 }, { "role": 

1420 "roles/resourcemanager.organizationViewer", 

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

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

1423 "description": "Does not grant access after 

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

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

1426 

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

1428 

1429 } 

1430 

1431 **YAML example:** 

1432 

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

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

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

1436 role: roles/resourcemanager.organizationAdmin - 

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

1438 roles/resourcemanager.organizationViewer 

1439 condition: title: expirable access description: 

1440 Does not grant access after Sep 2020 expression: 

1441 request.time < 

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

1443 BwWWja0YfJA= version: 3 

1444 

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

1446 [IAM 

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

1448 

1449 """ 

1450 # Create or coerce a protobuf request object. 

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

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

1453 has_flattened_params = any([resource]) 

1454 if request is not None and has_flattened_params: 

1455 raise ValueError( 

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

1457 "the individual field arguments should be set." 

1458 ) 

1459 

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

1461 # so it must be constructed via keyword expansion. 

1462 if isinstance(request, dict): 

1463 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1464 elif not request: 

1465 request = iam_policy_pb2.GetIamPolicyRequest( 

1466 resource=resource, 

1467 ) 

1468 

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

1470 # and friendly error handling. 

1471 rpc = gapic_v1.method_async.wrap_method( 

1472 self._client._transport.get_iam_policy, 

1473 default_retry=retries.Retry( 

1474 initial=0.1, 

1475 maximum=60.0, 

1476 multiplier=1.3, 

1477 predicate=retries.if_exception_type( 

1478 core_exceptions.ServiceUnavailable, 

1479 ), 

1480 deadline=60.0, 

1481 ), 

1482 default_timeout=60.0, 

1483 client_info=DEFAULT_CLIENT_INFO, 

1484 ) 

1485 

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

1487 # add these here. 

1488 metadata = tuple(metadata) + ( 

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

1490 ) 

1491 

1492 # Send the request. 

1493 response = await rpc( 

1494 request, 

1495 retry=retry, 

1496 timeout=timeout, 

1497 metadata=metadata, 

1498 ) 

1499 

1500 # Done; return the response. 

1501 return response 

1502 

1503 async def set_iam_policy( 

1504 self, 

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

1506 *, 

1507 resource: Optional[str] = None, 

1508 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1511 ) -> policy_pb2.Policy: 

1512 r"""Sets the IAM access control policy for the specified project, in 

1513 the format ``projects/{ProjectIdOrNumber}`` e.g. projects/123. 

1514 

1515 CAUTION: This method will replace the existing policy, and 

1516 cannot be used to append additional IAM settings. 

1517 

1518 Note: Removing service accounts from policies or changing their 

1519 roles can render services completely inoperable. It is important 

1520 to understand how the service account is being used before 

1521 removing or updating its roles. 

1522 

1523 The following constraints apply when using ``setIamPolicy()``: 

1524 

1525 - Project does not support ``allUsers`` and 

1526 ``allAuthenticatedUsers`` as ``members`` in a ``Binding`` of 

1527 a ``Policy``. 

1528 

1529 - The owner role can be granted to a ``user``, 

1530 ``serviceAccount``, or a group that is part of an 

1531 organization. For example, group@myownpersonaldomain.com 

1532 could be added as an owner to a project in the 

1533 myownpersonaldomain.com organization, but not the 

1534 examplepetstore.com organization. 

1535 

1536 - Service accounts can be made owners of a project directly 

1537 without any restrictions. However, to be added as an owner, a 

1538 user must be invited using the Cloud Platform console and 

1539 must accept the invitation. 

1540 

1541 - A user cannot be granted the owner role using 

1542 ``setIamPolicy()``. The user must be granted the owner role 

1543 using the Cloud Platform Console and must explicitly accept 

1544 the invitation. 

1545 

1546 - Invitations to grant the owner role cannot be sent using 

1547 ``setIamPolicy()``; they must be sent only using the Cloud 

1548 Platform Console. 

1549 

1550 - If the project is not part of an organization, there must be 

1551 at least one owner who has accepted the Terms of Service 

1552 (ToS) agreement in the policy. Calling ``setIamPolicy()`` to 

1553 remove the last ToS-accepted owner from the policy will fail. 

1554 This restriction also applies to legacy projects that no 

1555 longer have owners who have accepted the ToS. Edits to IAM 

1556 policies will be rejected until the lack of a ToS-accepting 

1557 owner is rectified. If the project is part of an 

1558 organization, you can remove all owners, potentially making 

1559 the organization inaccessible. 

1560 

1561 .. code-block:: python 

1562 

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

1564 # code template only. 

1565 # It will require modifications to work: 

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

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

1568 # client as shown in: 

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

1570 from google.cloud import resourcemanager_v3 

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

1572 

1573 async def sample_set_iam_policy(): 

1574 # Create a client 

1575 client = resourcemanager_v3.ProjectsAsyncClient() 

1576 

1577 # Initialize request argument(s) 

1578 request = iam_policy_pb2.SetIamPolicyRequest( 

1579 resource="resource_value", 

1580 ) 

1581 

1582 # Make the request 

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

1584 

1585 # Handle the response 

1586 print(response) 

1587 

1588 Args: 

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

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

1591 resource (:class:`str`): 

1592 REQUIRED: The resource for which the 

1593 policy is being specified. See the 

1594 operation documentation for the 

1595 appropriate value for this field. 

1596 

1597 This corresponds to the ``resource`` field 

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

1599 should not be set. 

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

1601 should be retried. 

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

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

1604 sent along with the request as metadata. 

1605 

1606 Returns: 

1607 google.iam.v1.policy_pb2.Policy: 

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

1609 controls for Google Cloud resources. 

1610 

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

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

1613 Principals can be user accounts, service accounts, 

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

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

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

1617 

1618 For some types of Google Cloud resources, a binding 

1619 can also specify a condition, which is a logical 

1620 expression that allows access to a resource only if 

1621 the expression evaluates to true. A condition can add 

1622 constraints based on attributes of the request, the 

1623 resource, or both. To learn which resources support 

1624 conditions in their IAM policies, see the [IAM 

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

1626 

1627 **JSON example:** 

1628 

1629 { 

1630 "bindings": [ 

1631 { 

1632 "role": 

1633 "roles/resourcemanager.organizationAdmin", 

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

1635 "group:admins@example.com", 

1636 "domain:google.com", 

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

1638 ] 

1639 

1640 }, { "role": 

1641 "roles/resourcemanager.organizationViewer", 

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

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

1644 "description": "Does not grant access after 

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

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

1647 

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

1649 

1650 } 

1651 

1652 **YAML example:** 

1653 

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

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

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

1657 role: roles/resourcemanager.organizationAdmin - 

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

1659 roles/resourcemanager.organizationViewer 

1660 condition: title: expirable access description: 

1661 Does not grant access after Sep 2020 expression: 

1662 request.time < 

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

1664 BwWWja0YfJA= version: 3 

1665 

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

1667 [IAM 

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

1669 

1670 """ 

1671 # Create or coerce a protobuf request object. 

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

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

1674 has_flattened_params = any([resource]) 

1675 if request is not None and has_flattened_params: 

1676 raise ValueError( 

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

1678 "the individual field arguments should be set." 

1679 ) 

1680 

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

1682 # so it must be constructed via keyword expansion. 

1683 if isinstance(request, dict): 

1684 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1685 elif not request: 

1686 request = iam_policy_pb2.SetIamPolicyRequest( 

1687 resource=resource, 

1688 ) 

1689 

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

1691 # and friendly error handling. 

1692 rpc = gapic_v1.method_async.wrap_method( 

1693 self._client._transport.set_iam_policy, 

1694 default_timeout=60.0, 

1695 client_info=DEFAULT_CLIENT_INFO, 

1696 ) 

1697 

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

1699 # add these here. 

1700 metadata = tuple(metadata) + ( 

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

1702 ) 

1703 

1704 # Send the request. 

1705 response = await rpc( 

1706 request, 

1707 retry=retry, 

1708 timeout=timeout, 

1709 metadata=metadata, 

1710 ) 

1711 

1712 # Done; return the response. 

1713 return response 

1714 

1715 async def test_iam_permissions( 

1716 self, 

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

1718 *, 

1719 resource: Optional[str] = None, 

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

1721 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1724 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1725 r"""Returns permissions that a caller has on the specified project, 

1726 in the format ``projects/{ProjectIdOrNumber}`` e.g. 

1727 projects/123.. 

1728 

1729 .. code-block:: python 

1730 

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

1732 # code template only. 

1733 # It will require modifications to work: 

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

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

1736 # client as shown in: 

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

1738 from google.cloud import resourcemanager_v3 

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

1740 

1741 async def sample_test_iam_permissions(): 

1742 # Create a client 

1743 client = resourcemanager_v3.ProjectsAsyncClient() 

1744 

1745 # Initialize request argument(s) 

1746 request = iam_policy_pb2.TestIamPermissionsRequest( 

1747 resource="resource_value", 

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

1749 ) 

1750 

1751 # Make the request 

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

1753 

1754 # Handle the response 

1755 print(response) 

1756 

1757 Args: 

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

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

1760 resource (:class:`str`): 

1761 REQUIRED: The resource for which the 

1762 policy detail is being requested. See 

1763 the operation documentation for the 

1764 appropriate value for this field. 

1765 

1766 This corresponds to the ``resource`` field 

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

1768 should not be set. 

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

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

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

1772 are not allowed. For more information see `IAM 

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

1774 

1775 This corresponds to the ``permissions`` field 

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

1777 should not be set. 

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

1779 should be retried. 

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

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

1782 sent along with the request as metadata. 

1783 

1784 Returns: 

1785 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: 

1786 Response message for TestIamPermissions method. 

1787 """ 

1788 # Create or coerce a protobuf request object. 

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

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

1791 has_flattened_params = any([resource, permissions]) 

1792 if request is not None and has_flattened_params: 

1793 raise ValueError( 

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

1795 "the individual field arguments should be set." 

1796 ) 

1797 

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

1799 # so it must be constructed via keyword expansion. 

1800 if isinstance(request, dict): 

1801 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1802 elif not request: 

1803 request = iam_policy_pb2.TestIamPermissionsRequest( 

1804 resource=resource, 

1805 permissions=permissions, 

1806 ) 

1807 

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

1809 # and friendly error handling. 

1810 rpc = gapic_v1.method_async.wrap_method( 

1811 self._client._transport.test_iam_permissions, 

1812 default_timeout=None, 

1813 client_info=DEFAULT_CLIENT_INFO, 

1814 ) 

1815 

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

1817 # add these here. 

1818 metadata = tuple(metadata) + ( 

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

1820 ) 

1821 

1822 # Send the request. 

1823 response = await rpc( 

1824 request, 

1825 retry=retry, 

1826 timeout=timeout, 

1827 metadata=metadata, 

1828 ) 

1829 

1830 # Done; return the response. 

1831 return response 

1832 

1833 async def get_operation( 

1834 self, 

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

1836 *, 

1837 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1840 ) -> operations_pb2.Operation: 

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

1842 

1843 Args: 

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

1845 The request object. Request message for 

1846 `GetOperation` method. 

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

1848 if any, should be retried. 

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

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

1851 sent along with the request as metadata. 

1852 Returns: 

1853 ~.operations_pb2.Operation: 

1854 An ``Operation`` object. 

1855 """ 

1856 # Create or coerce a protobuf request object. 

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

1858 # so it must be constructed via keyword expansion. 

1859 if isinstance(request, dict): 

1860 request = operations_pb2.GetOperationRequest(**request) 

1861 

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

1863 # and friendly error handling. 

1864 rpc = gapic_v1.method.wrap_method( 

1865 self._client._transport.get_operation, 

1866 default_timeout=None, 

1867 client_info=DEFAULT_CLIENT_INFO, 

1868 ) 

1869 

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

1871 # add these here. 

1872 metadata = tuple(metadata) + ( 

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

1874 ) 

1875 

1876 # Send the request. 

1877 response = await rpc( 

1878 request, 

1879 retry=retry, 

1880 timeout=timeout, 

1881 metadata=metadata, 

1882 ) 

1883 

1884 # Done; return the response. 

1885 return response 

1886 

1887 async def __aenter__(self): 

1888 return self 

1889 

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

1891 await self.transport.close() 

1892 

1893 

1894DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1895 gapic_version=package_version.__version__ 

1896) 

1897 

1898 

1899__all__ = ("ProjectsAsyncClient",)