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

116 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 typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union 

17import warnings 

18 

19from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 

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

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

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

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

24from google.longrunning import operations_pb2 # type: ignore 

25import grpc # type: ignore 

26from grpc.experimental import aio # type: ignore 

27 

28from google.cloud.resourcemanager_v3.types import projects 

29 

30from .base import DEFAULT_CLIENT_INFO, ProjectsTransport 

31from .grpc import ProjectsGrpcTransport 

32 

33 

34class ProjectsGrpcAsyncIOTransport(ProjectsTransport): 

35 """gRPC AsyncIO backend transport for Projects. 

36 

37 Manages Google Cloud Projects. 

38 

39 This class defines the same methods as the primary client, so the 

40 primary client can load the underlying transport implementation 

41 and call it. 

42 

43 It sends protocol buffers over the wire using gRPC (which is built on 

44 top of HTTP/2); the ``grpcio`` package must be installed. 

45 """ 

46 

47 _grpc_channel: aio.Channel 

48 _stubs: Dict[str, Callable] = {} 

49 

50 @classmethod 

51 def create_channel( 

52 cls, 

53 host: str = "cloudresourcemanager.googleapis.com", 

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

55 credentials_file: Optional[str] = None, 

56 scopes: Optional[Sequence[str]] = None, 

57 quota_project_id: Optional[str] = None, 

58 **kwargs, 

59 ) -> aio.Channel: 

60 """Create and return a gRPC AsyncIO channel object. 

61 Args: 

62 host (Optional[str]): The host for the channel to use. 

63 credentials (Optional[~.Credentials]): The 

64 authorization credentials to attach to requests. These 

65 credentials identify this application to the service. If 

66 none are specified, the client will attempt to ascertain 

67 the credentials from the environment. 

68 credentials_file (Optional[str]): A file with credentials that can 

69 be loaded with :func:`google.auth.load_credentials_from_file`. 

70 This argument is ignored if ``channel`` is provided. 

71 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

72 service. These are only used when credentials are not specified and 

73 are passed to :func:`google.auth.default`. 

74 quota_project_id (Optional[str]): An optional project to use for billing 

75 and quota. 

76 kwargs (Optional[dict]): Keyword arguments, which are passed to the 

77 channel creation. 

78 Returns: 

79 aio.Channel: A gRPC AsyncIO channel object. 

80 """ 

81 

82 return grpc_helpers_async.create_channel( 

83 host, 

84 credentials=credentials, 

85 credentials_file=credentials_file, 

86 quota_project_id=quota_project_id, 

87 default_scopes=cls.AUTH_SCOPES, 

88 scopes=scopes, 

89 default_host=cls.DEFAULT_HOST, 

90 **kwargs, 

91 ) 

92 

93 def __init__( 

94 self, 

95 *, 

96 host: str = "cloudresourcemanager.googleapis.com", 

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

98 credentials_file: Optional[str] = None, 

99 scopes: Optional[Sequence[str]] = None, 

100 channel: Optional[aio.Channel] = None, 

101 api_mtls_endpoint: Optional[str] = None, 

102 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

103 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, 

104 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

105 quota_project_id: Optional[str] = None, 

106 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

107 always_use_jwt_access: Optional[bool] = False, 

108 api_audience: Optional[str] = None, 

109 ) -> None: 

110 """Instantiate the transport. 

111 

112 Args: 

113 host (Optional[str]): 

114 The hostname to connect to. 

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

116 authorization credentials to attach to requests. These 

117 credentials identify the application to the service; if none 

118 are specified, the client will attempt to ascertain the 

119 credentials from the environment. 

120 This argument is ignored if ``channel`` is provided. 

121 credentials_file (Optional[str]): A file with credentials that can 

122 be loaded with :func:`google.auth.load_credentials_from_file`. 

123 This argument is ignored if ``channel`` is provided. 

124 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

125 service. These are only used when credentials are not specified and 

126 are passed to :func:`google.auth.default`. 

127 channel (Optional[aio.Channel]): A ``Channel`` instance through 

128 which to make calls. 

129 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. 

130 If provided, it overrides the ``host`` argument and tries to create 

131 a mutual TLS channel with client SSL credentials from 

132 ``client_cert_source`` or application default SSL credentials. 

133 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): 

134 Deprecated. A callback to provide client SSL certificate bytes and 

135 private key bytes, both in PEM format. It is ignored if 

136 ``api_mtls_endpoint`` is None. 

137 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

138 for the grpc channel. It is ignored if ``channel`` is provided. 

139 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): 

140 A callback to provide client certificate bytes and private key bytes, 

141 both in PEM format. It is used to configure a mutual TLS channel. It is 

142 ignored if ``channel`` or ``ssl_channel_credentials`` is provided. 

143 quota_project_id (Optional[str]): An optional project to use for billing 

144 and quota. 

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

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

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

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

149 your own client library. 

150 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

151 be used for service account credentials. 

152 

153 Raises: 

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

155 creation failed for any reason. 

156 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` 

157 and ``credentials_file`` are passed. 

158 """ 

159 self._grpc_channel = None 

160 self._ssl_channel_credentials = ssl_channel_credentials 

161 self._stubs: Dict[str, Callable] = {} 

162 self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None 

163 

164 if api_mtls_endpoint: 

165 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 

166 if client_cert_source: 

167 warnings.warn("client_cert_source is deprecated", DeprecationWarning) 

168 

169 if channel: 

170 # Ignore credentials if a channel was passed. 

171 credentials = False 

172 # If a channel was explicitly provided, set it. 

173 self._grpc_channel = channel 

174 self._ssl_channel_credentials = None 

175 else: 

176 if api_mtls_endpoint: 

177 host = api_mtls_endpoint 

178 

179 # Create SSL credentials with client_cert_source or application 

180 # default SSL credentials. 

181 if client_cert_source: 

182 cert, key = client_cert_source() 

183 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

184 certificate_chain=cert, private_key=key 

185 ) 

186 else: 

187 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

188 

189 else: 

190 if client_cert_source_for_mtls and not ssl_channel_credentials: 

191 cert, key = client_cert_source_for_mtls() 

192 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

193 certificate_chain=cert, private_key=key 

194 ) 

195 

196 # The base transport sets the host, credentials and scopes 

197 super().__init__( 

198 host=host, 

199 credentials=credentials, 

200 credentials_file=credentials_file, 

201 scopes=scopes, 

202 quota_project_id=quota_project_id, 

203 client_info=client_info, 

204 always_use_jwt_access=always_use_jwt_access, 

205 api_audience=api_audience, 

206 ) 

207 

208 if not self._grpc_channel: 

209 self._grpc_channel = type(self).create_channel( 

210 self._host, 

211 # use the credentials which are saved 

212 credentials=self._credentials, 

213 # Set ``credentials_file`` to ``None`` here as 

214 # the credentials that we saved earlier should be used. 

215 credentials_file=None, 

216 scopes=self._scopes, 

217 ssl_credentials=self._ssl_channel_credentials, 

218 quota_project_id=quota_project_id, 

219 options=[ 

220 ("grpc.max_send_message_length", -1), 

221 ("grpc.max_receive_message_length", -1), 

222 ], 

223 ) 

224 

225 # Wrap messages. This must be done after self._grpc_channel exists 

226 self._prep_wrapped_messages(client_info) 

227 

228 @property 

229 def grpc_channel(self) -> aio.Channel: 

230 """Create the channel designed to connect to this service. 

231 

232 This property caches on the instance; repeated calls return 

233 the same channel. 

234 """ 

235 # Return the channel from cache. 

236 return self._grpc_channel 

237 

238 @property 

239 def operations_client(self) -> operations_v1.OperationsAsyncClient: 

240 """Create the client designed to process long-running operations. 

241 

242 This property caches on the instance; repeated calls return the same 

243 client. 

244 """ 

245 # Quick check: Only create a new client if we do not already have one. 

246 if self._operations_client is None: 

247 self._operations_client = operations_v1.OperationsAsyncClient( 

248 self.grpc_channel 

249 ) 

250 

251 # Return the client from cache. 

252 return self._operations_client 

253 

254 @property 

255 def get_project( 

256 self, 

257 ) -> Callable[[projects.GetProjectRequest], Awaitable[projects.Project]]: 

258 r"""Return a callable for the get project method over gRPC. 

259 

260 Retrieves the project identified by the specified ``name`` (for 

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

262 

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

264 for this project. 

265 

266 Returns: 

267 Callable[[~.GetProjectRequest], 

268 Awaitable[~.Project]]: 

269 A function that, when called, will call the underlying RPC 

270 on the server. 

271 """ 

272 # Generate a "stub function" on-the-fly which will actually make 

273 # the request. 

274 # gRPC handles serialization and deserialization, so we just need 

275 # to pass in the functions for each. 

276 if "get_project" not in self._stubs: 

277 self._stubs["get_project"] = self.grpc_channel.unary_unary( 

278 "/google.cloud.resourcemanager.v3.Projects/GetProject", 

279 request_serializer=projects.GetProjectRequest.serialize, 

280 response_deserializer=projects.Project.deserialize, 

281 ) 

282 return self._stubs["get_project"] 

283 

284 @property 

285 def list_projects( 

286 self, 

287 ) -> Callable[ 

288 [projects.ListProjectsRequest], Awaitable[projects.ListProjectsResponse] 

289 ]: 

290 r"""Return a callable for the list projects method over gRPC. 

291 

292 Lists projects that are direct children of the specified folder 

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

294 consistent view of the projects underneath the specified parent 

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

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

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

298 the identified parent. 

299 

300 Returns: 

301 Callable[[~.ListProjectsRequest], 

302 Awaitable[~.ListProjectsResponse]]: 

303 A function that, when called, will call the underlying RPC 

304 on the server. 

305 """ 

306 # Generate a "stub function" on-the-fly which will actually make 

307 # the request. 

308 # gRPC handles serialization and deserialization, so we just need 

309 # to pass in the functions for each. 

310 if "list_projects" not in self._stubs: 

311 self._stubs["list_projects"] = self.grpc_channel.unary_unary( 

312 "/google.cloud.resourcemanager.v3.Projects/ListProjects", 

313 request_serializer=projects.ListProjectsRequest.serialize, 

314 response_deserializer=projects.ListProjectsResponse.deserialize, 

315 ) 

316 return self._stubs["list_projects"] 

317 

318 @property 

319 def search_projects( 

320 self, 

321 ) -> Callable[ 

322 [projects.SearchProjectsRequest], Awaitable[projects.SearchProjectsResponse] 

323 ]: 

324 r"""Return a callable for the search projects method over gRPC. 

325 

326 Search for projects that the caller has both 

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

328 the specified query. 

329 

330 This method returns projects in an unspecified order. 

331 

332 This method is eventually consistent with project mutations; 

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

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

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

336 project, use the 

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

338 method. 

339 

340 Returns: 

341 Callable[[~.SearchProjectsRequest], 

342 Awaitable[~.SearchProjectsResponse]]: 

343 A function that, when called, will call the underlying RPC 

344 on the server. 

345 """ 

346 # Generate a "stub function" on-the-fly which will actually make 

347 # the request. 

348 # gRPC handles serialization and deserialization, so we just need 

349 # to pass in the functions for each. 

350 if "search_projects" not in self._stubs: 

351 self._stubs["search_projects"] = self.grpc_channel.unary_unary( 

352 "/google.cloud.resourcemanager.v3.Projects/SearchProjects", 

353 request_serializer=projects.SearchProjectsRequest.serialize, 

354 response_deserializer=projects.SearchProjectsResponse.deserialize, 

355 ) 

356 return self._stubs["search_projects"] 

357 

358 @property 

359 def create_project( 

360 self, 

361 ) -> Callable[[projects.CreateProjectRequest], Awaitable[operations_pb2.Operation]]: 

362 r"""Return a callable for the create project method over gRPC. 

363 

364 Request that a new project be created. The result is an 

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

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

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

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

369 ``DeleteOperation``. 

370 

371 Returns: 

372 Callable[[~.CreateProjectRequest], 

373 Awaitable[~.Operation]]: 

374 A function that, when called, will call the underlying RPC 

375 on the server. 

376 """ 

377 # Generate a "stub function" on-the-fly which will actually make 

378 # the request. 

379 # gRPC handles serialization and deserialization, so we just need 

380 # to pass in the functions for each. 

381 if "create_project" not in self._stubs: 

382 self._stubs["create_project"] = self.grpc_channel.unary_unary( 

383 "/google.cloud.resourcemanager.v3.Projects/CreateProject", 

384 request_serializer=projects.CreateProjectRequest.serialize, 

385 response_deserializer=operations_pb2.Operation.FromString, 

386 ) 

387 return self._stubs["create_project"] 

388 

389 @property 

390 def update_project( 

391 self, 

392 ) -> Callable[[projects.UpdateProjectRequest], Awaitable[operations_pb2.Operation]]: 

393 r"""Return a callable for the update project method over gRPC. 

394 

395 Updates the ``display_name`` and labels of the project 

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

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

398 update mask for labels field. 

399 

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

401 permission for this project. 

402 

403 Returns: 

404 Callable[[~.UpdateProjectRequest], 

405 Awaitable[~.Operation]]: 

406 A function that, when called, will call the underlying RPC 

407 on the server. 

408 """ 

409 # Generate a "stub function" on-the-fly which will actually make 

410 # the request. 

411 # gRPC handles serialization and deserialization, so we just need 

412 # to pass in the functions for each. 

413 if "update_project" not in self._stubs: 

414 self._stubs["update_project"] = self.grpc_channel.unary_unary( 

415 "/google.cloud.resourcemanager.v3.Projects/UpdateProject", 

416 request_serializer=projects.UpdateProjectRequest.serialize, 

417 response_deserializer=operations_pb2.Operation.FromString, 

418 ) 

419 return self._stubs["update_project"] 

420 

421 @property 

422 def move_project( 

423 self, 

424 ) -> Callable[[projects.MoveProjectRequest], Awaitable[operations_pb2.Operation]]: 

425 r"""Return a callable for the move project method over gRPC. 

426 

427 Move a project to another place in your resource hierarchy, 

428 under a new resource parent. 

429 

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

431 the project move workflow. Upon success, the 

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

433 project. 

434 

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

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

437 new parent. 

438 

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

440 an associated organization resource, you will also need the 

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

442 project. 

443 

444 Returns: 

445 Callable[[~.MoveProjectRequest], 

446 Awaitable[~.Operation]]: 

447 A function that, when called, will call the underlying RPC 

448 on the server. 

449 """ 

450 # Generate a "stub function" on-the-fly which will actually make 

451 # the request. 

452 # gRPC handles serialization and deserialization, so we just need 

453 # to pass in the functions for each. 

454 if "move_project" not in self._stubs: 

455 self._stubs["move_project"] = self.grpc_channel.unary_unary( 

456 "/google.cloud.resourcemanager.v3.Projects/MoveProject", 

457 request_serializer=projects.MoveProjectRequest.serialize, 

458 response_deserializer=operations_pb2.Operation.FromString, 

459 ) 

460 return self._stubs["move_project"] 

461 

462 @property 

463 def delete_project( 

464 self, 

465 ) -> Callable[[projects.DeleteProjectRequest], Awaitable[operations_pb2.Operation]]: 

466 r"""Return a callable for the delete project method over gRPC. 

467 

468 Marks the project identified by the specified ``name`` (for 

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

470 

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

472 state of 

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

474 

475 This method changes the Project's lifecycle state from 

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

477 to 

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

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

480 Project is no longer accessible. 

481 

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

483 checked by retrieving the project with [GetProject] 

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

485 project remains visible to [ListProjects] 

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

487 However, you cannot update the project. 

488 

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

490 the [GetProject] 

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

492 [ListProjects] 

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

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

495 methods. 

496 

497 This method behaves idempotently, such that deleting a 

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

499 won't do anything. 

500 

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

502 permissions for this project. 

503 

504 Returns: 

505 Callable[[~.DeleteProjectRequest], 

506 Awaitable[~.Operation]]: 

507 A function that, when called, will call the underlying RPC 

508 on the server. 

509 """ 

510 # Generate a "stub function" on-the-fly which will actually make 

511 # the request. 

512 # gRPC handles serialization and deserialization, so we just need 

513 # to pass in the functions for each. 

514 if "delete_project" not in self._stubs: 

515 self._stubs["delete_project"] = self.grpc_channel.unary_unary( 

516 "/google.cloud.resourcemanager.v3.Projects/DeleteProject", 

517 request_serializer=projects.DeleteProjectRequest.serialize, 

518 response_deserializer=operations_pb2.Operation.FromString, 

519 ) 

520 return self._stubs["delete_project"] 

521 

522 @property 

523 def undelete_project( 

524 self, 

525 ) -> Callable[ 

526 [projects.UndeleteProjectRequest], Awaitable[operations_pb2.Operation] 

527 ]: 

528 r"""Return a callable for the undelete project method over gRPC. 

529 

530 Restores the project identified by the specified ``name`` (for 

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

532 method for a project that has a lifecycle state of 

533 [DELETE_REQUESTED] [Projects.State.DELETE_REQUESTED]. After 

534 deletion starts, the project cannot be restored. 

535 

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

537 permission for this project. 

538 

539 Returns: 

540 Callable[[~.UndeleteProjectRequest], 

541 Awaitable[~.Operation]]: 

542 A function that, when called, will call the underlying RPC 

543 on the server. 

544 """ 

545 # Generate a "stub function" on-the-fly which will actually make 

546 # the request. 

547 # gRPC handles serialization and deserialization, so we just need 

548 # to pass in the functions for each. 

549 if "undelete_project" not in self._stubs: 

550 self._stubs["undelete_project"] = self.grpc_channel.unary_unary( 

551 "/google.cloud.resourcemanager.v3.Projects/UndeleteProject", 

552 request_serializer=projects.UndeleteProjectRequest.serialize, 

553 response_deserializer=operations_pb2.Operation.FromString, 

554 ) 

555 return self._stubs["undelete_project"] 

556 

557 @property 

558 def get_iam_policy( 

559 self, 

560 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: 

561 r"""Return a callable for the get iam policy method over gRPC. 

562 

563 Returns the IAM access control policy for the specified project, 

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

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

566 do not exist. 

567 

568 Returns: 

569 Callable[[~.GetIamPolicyRequest], 

570 Awaitable[~.Policy]]: 

571 A function that, when called, will call the underlying RPC 

572 on the server. 

573 """ 

574 # Generate a "stub function" on-the-fly which will actually make 

575 # the request. 

576 # gRPC handles serialization and deserialization, so we just need 

577 # to pass in the functions for each. 

578 if "get_iam_policy" not in self._stubs: 

579 self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( 

580 "/google.cloud.resourcemanager.v3.Projects/GetIamPolicy", 

581 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

582 response_deserializer=policy_pb2.Policy.FromString, 

583 ) 

584 return self._stubs["get_iam_policy"] 

585 

586 @property 

587 def set_iam_policy( 

588 self, 

589 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: 

590 r"""Return a callable for the set iam policy method over gRPC. 

591 

592 Sets the IAM access control policy for the specified project, in 

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

594 

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

596 cannot be used to append additional IAM settings. 

597 

598 Note: Removing service accounts from policies or changing their 

599 roles can render services completely inoperable. It is important 

600 to understand how the service account is being used before 

601 removing or updating its roles. 

602 

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

604 

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

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

607 a ``Policy``. 

608 

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

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

611 organization. For example, group@myownpersonaldomain.com 

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

613 myownpersonaldomain.com organization, but not the 

614 examplepetstore.com organization. 

615 

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

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

618 user must be invited using the Cloud Platform console and 

619 must accept the invitation. 

620 

621 - A user cannot be granted the owner role using 

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

623 using the Cloud Platform Console and must explicitly accept 

624 the invitation. 

625 

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

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

628 Platform Console. 

629 

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

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

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

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

634 This restriction also applies to legacy projects that no 

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

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

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

638 organization, you can remove all owners, potentially making 

639 the organization inaccessible. 

640 

641 Returns: 

642 Callable[[~.SetIamPolicyRequest], 

643 Awaitable[~.Policy]]: 

644 A function that, when called, will call the underlying RPC 

645 on the server. 

646 """ 

647 # Generate a "stub function" on-the-fly which will actually make 

648 # the request. 

649 # gRPC handles serialization and deserialization, so we just need 

650 # to pass in the functions for each. 

651 if "set_iam_policy" not in self._stubs: 

652 self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( 

653 "/google.cloud.resourcemanager.v3.Projects/SetIamPolicy", 

654 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

655 response_deserializer=policy_pb2.Policy.FromString, 

656 ) 

657 return self._stubs["set_iam_policy"] 

658 

659 @property 

660 def test_iam_permissions( 

661 self, 

662 ) -> Callable[ 

663 [iam_policy_pb2.TestIamPermissionsRequest], 

664 Awaitable[iam_policy_pb2.TestIamPermissionsResponse], 

665 ]: 

666 r"""Return a callable for the test iam permissions method over gRPC. 

667 

668 Returns permissions that a caller has on the specified project, 

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

670 projects/123.. 

671 

672 Returns: 

673 Callable[[~.TestIamPermissionsRequest], 

674 Awaitable[~.TestIamPermissionsResponse]]: 

675 A function that, when called, will call the underlying RPC 

676 on the server. 

677 """ 

678 # Generate a "stub function" on-the-fly which will actually make 

679 # the request. 

680 # gRPC handles serialization and deserialization, so we just need 

681 # to pass in the functions for each. 

682 if "test_iam_permissions" not in self._stubs: 

683 self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( 

684 "/google.cloud.resourcemanager.v3.Projects/TestIamPermissions", 

685 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

686 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

687 ) 

688 return self._stubs["test_iam_permissions"] 

689 

690 def close(self): 

691 return self.grpc_channel.close() 

692 

693 @property 

694 def get_operation( 

695 self, 

696 ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: 

697 r"""Return a callable for the get_operation method over gRPC.""" 

698 # Generate a "stub function" on-the-fly which will actually make 

699 # the request. 

700 # gRPC handles serialization and deserialization, so we just need 

701 # to pass in the functions for each. 

702 if "get_operation" not in self._stubs: 

703 self._stubs["get_operation"] = self.grpc_channel.unary_unary( 

704 "/google.longrunning.Operations/GetOperation", 

705 request_serializer=operations_pb2.GetOperationRequest.SerializeToString, 

706 response_deserializer=operations_pb2.Operation.FromString, 

707 ) 

708 return self._stubs["get_operation"] 

709 

710 

711__all__ = ("ProjectsGrpcAsyncIOTransport",)