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

117 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 Callable, Dict, Optional, Sequence, Tuple, Union 

17import warnings 

18 

19from google.api_core import gapic_v1, grpc_helpers, operations_v1 

20import google.auth # type: ignore 

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

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

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

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

25from google.longrunning import operations_pb2 # type: ignore 

26import grpc # type: ignore 

27 

28from google.cloud.resourcemanager_v3.types import projects 

29 

30from .base import DEFAULT_CLIENT_INFO, ProjectsTransport 

31 

32 

33class ProjectsGrpcTransport(ProjectsTransport): 

34 """gRPC backend transport for Projects. 

35 

36 Manages Google Cloud Projects. 

37 

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

39 primary client can load the underlying transport implementation 

40 and call it. 

41 

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

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

44 """ 

45 

46 _stubs: Dict[str, Callable] 

47 

48 def __init__( 

49 self, 

50 *, 

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

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

53 credentials_file: Optional[str] = None, 

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

55 channel: Optional[grpc.Channel] = None, 

56 api_mtls_endpoint: Optional[str] = None, 

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

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

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

60 quota_project_id: Optional[str] = None, 

61 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

62 always_use_jwt_access: Optional[bool] = False, 

63 api_audience: Optional[str] = None, 

64 ) -> None: 

65 """Instantiate the transport. 

66 

67 Args: 

68 host (Optional[str]): 

69 The hostname to connect to. 

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

71 authorization credentials to attach to requests. These 

72 credentials identify the application to the service; if none 

73 are specified, the client will attempt to ascertain the 

74 credentials from the environment. 

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

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

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

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

79 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

80 ignored if ``channel`` is provided. 

81 channel (Optional[grpc.Channel]): A ``Channel`` instance through 

82 which to make calls. 

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

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

85 a mutual TLS channel with client SSL credentials from 

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

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

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

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

90 ``api_mtls_endpoint`` is None. 

91 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

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

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

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

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

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

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

98 and quota. 

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

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

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

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

103 your own client library. 

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

105 be used for service account credentials. 

106 

107 Raises: 

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

109 creation failed for any reason. 

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

111 and ``credentials_file`` are passed. 

112 """ 

113 self._grpc_channel = None 

114 self._ssl_channel_credentials = ssl_channel_credentials 

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

116 self._operations_client: Optional[operations_v1.OperationsClient] = None 

117 

118 if api_mtls_endpoint: 

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

120 if client_cert_source: 

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

122 

123 if channel: 

124 # Ignore credentials if a channel was passed. 

125 credentials = False 

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

127 self._grpc_channel = channel 

128 self._ssl_channel_credentials = None 

129 

130 else: 

131 if api_mtls_endpoint: 

132 host = api_mtls_endpoint 

133 

134 # Create SSL credentials with client_cert_source or application 

135 # default SSL credentials. 

136 if client_cert_source: 

137 cert, key = client_cert_source() 

138 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

139 certificate_chain=cert, private_key=key 

140 ) 

141 else: 

142 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

143 

144 else: 

145 if client_cert_source_for_mtls and not ssl_channel_credentials: 

146 cert, key = client_cert_source_for_mtls() 

147 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

148 certificate_chain=cert, private_key=key 

149 ) 

150 

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

152 super().__init__( 

153 host=host, 

154 credentials=credentials, 

155 credentials_file=credentials_file, 

156 scopes=scopes, 

157 quota_project_id=quota_project_id, 

158 client_info=client_info, 

159 always_use_jwt_access=always_use_jwt_access, 

160 api_audience=api_audience, 

161 ) 

162 

163 if not self._grpc_channel: 

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

165 self._host, 

166 # use the credentials which are saved 

167 credentials=self._credentials, 

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

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

170 credentials_file=None, 

171 scopes=self._scopes, 

172 ssl_credentials=self._ssl_channel_credentials, 

173 quota_project_id=quota_project_id, 

174 options=[ 

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

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

177 ], 

178 ) 

179 

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

181 self._prep_wrapped_messages(client_info) 

182 

183 @classmethod 

184 def create_channel( 

185 cls, 

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

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

188 credentials_file: Optional[str] = None, 

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

190 quota_project_id: Optional[str] = None, 

191 **kwargs, 

192 ) -> grpc.Channel: 

193 """Create and return a gRPC channel object. 

194 Args: 

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

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

197 authorization credentials to attach to requests. These 

198 credentials identify this application to the service. If 

199 none are specified, the client will attempt to ascertain 

200 the credentials from the environment. 

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

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

203 This argument is mutually exclusive with credentials. 

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

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

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

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

208 and quota. 

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

210 channel creation. 

211 Returns: 

212 grpc.Channel: A gRPC channel object. 

213 

214 Raises: 

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

216 and ``credentials_file`` are passed. 

217 """ 

218 

219 return grpc_helpers.create_channel( 

220 host, 

221 credentials=credentials, 

222 credentials_file=credentials_file, 

223 quota_project_id=quota_project_id, 

224 default_scopes=cls.AUTH_SCOPES, 

225 scopes=scopes, 

226 default_host=cls.DEFAULT_HOST, 

227 **kwargs, 

228 ) 

229 

230 @property 

231 def grpc_channel(self) -> grpc.Channel: 

232 """Return the channel designed to connect to this service.""" 

233 return self._grpc_channel 

234 

235 @property 

236 def operations_client(self) -> operations_v1.OperationsClient: 

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

238 

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

240 client. 

241 """ 

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

243 if self._operations_client is None: 

244 self._operations_client = operations_v1.OperationsClient(self.grpc_channel) 

245 

246 # Return the client from cache. 

247 return self._operations_client 

248 

249 @property 

250 def get_project(self) -> Callable[[projects.GetProjectRequest], projects.Project]: 

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

252 

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

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

255 

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

257 for this project. 

258 

259 Returns: 

260 Callable[[~.GetProjectRequest], 

261 ~.Project]: 

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

263 on the server. 

264 """ 

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

266 # the request. 

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

268 # to pass in the functions for each. 

269 if "get_project" not in self._stubs: 

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

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

272 request_serializer=projects.GetProjectRequest.serialize, 

273 response_deserializer=projects.Project.deserialize, 

274 ) 

275 return self._stubs["get_project"] 

276 

277 @property 

278 def list_projects( 

279 self, 

280 ) -> Callable[[projects.ListProjectsRequest], projects.ListProjectsResponse]: 

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

282 

283 Lists projects that are direct children of the specified folder 

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

285 consistent view of the projects underneath the specified parent 

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

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

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

289 the identified parent. 

290 

291 Returns: 

292 Callable[[~.ListProjectsRequest], 

293 ~.ListProjectsResponse]: 

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

295 on the server. 

296 """ 

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

298 # the request. 

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

300 # to pass in the functions for each. 

301 if "list_projects" not in self._stubs: 

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

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

304 request_serializer=projects.ListProjectsRequest.serialize, 

305 response_deserializer=projects.ListProjectsResponse.deserialize, 

306 ) 

307 return self._stubs["list_projects"] 

308 

309 @property 

310 def search_projects( 

311 self, 

312 ) -> Callable[[projects.SearchProjectsRequest], projects.SearchProjectsResponse]: 

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

314 

315 Search for projects that the caller has both 

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

317 the specified query. 

318 

319 This method returns projects in an unspecified order. 

320 

321 This method is eventually consistent with project mutations; 

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

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

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

325 project, use the 

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

327 method. 

328 

329 Returns: 

330 Callable[[~.SearchProjectsRequest], 

331 ~.SearchProjectsResponse]: 

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

333 on the server. 

334 """ 

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

336 # the request. 

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

338 # to pass in the functions for each. 

339 if "search_projects" not in self._stubs: 

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

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

342 request_serializer=projects.SearchProjectsRequest.serialize, 

343 response_deserializer=projects.SearchProjectsResponse.deserialize, 

344 ) 

345 return self._stubs["search_projects"] 

346 

347 @property 

348 def create_project( 

349 self, 

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

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

352 

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

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

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

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

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

358 ``DeleteOperation``. 

359 

360 Returns: 

361 Callable[[~.CreateProjectRequest], 

362 ~.Operation]: 

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

364 on the server. 

365 """ 

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

367 # the request. 

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

369 # to pass in the functions for each. 

370 if "create_project" not in self._stubs: 

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

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

373 request_serializer=projects.CreateProjectRequest.serialize, 

374 response_deserializer=operations_pb2.Operation.FromString, 

375 ) 

376 return self._stubs["create_project"] 

377 

378 @property 

379 def update_project( 

380 self, 

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

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

383 

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

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

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

387 update mask for labels field. 

388 

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

390 permission for this project. 

391 

392 Returns: 

393 Callable[[~.UpdateProjectRequest], 

394 ~.Operation]: 

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

396 on the server. 

397 """ 

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

399 # the request. 

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

401 # to pass in the functions for each. 

402 if "update_project" not in self._stubs: 

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

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

405 request_serializer=projects.UpdateProjectRequest.serialize, 

406 response_deserializer=operations_pb2.Operation.FromString, 

407 ) 

408 return self._stubs["update_project"] 

409 

410 @property 

411 def move_project( 

412 self, 

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

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

415 

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

417 under a new resource parent. 

418 

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

420 the project move workflow. Upon success, the 

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

422 project. 

423 

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

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

426 new parent. 

427 

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

429 an associated organization resource, you will also need the 

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

431 project. 

432 

433 Returns: 

434 Callable[[~.MoveProjectRequest], 

435 ~.Operation]: 

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

437 on the server. 

438 """ 

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

440 # the request. 

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

442 # to pass in the functions for each. 

443 if "move_project" not in self._stubs: 

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

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

446 request_serializer=projects.MoveProjectRequest.serialize, 

447 response_deserializer=operations_pb2.Operation.FromString, 

448 ) 

449 return self._stubs["move_project"] 

450 

451 @property 

452 def delete_project( 

453 self, 

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

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

456 

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

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

459 

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

461 state of 

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

463 

464 This method changes the Project's lifecycle state from 

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

466 to 

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

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

469 Project is no longer accessible. 

470 

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

472 checked by retrieving the project with [GetProject] 

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

474 project remains visible to [ListProjects] 

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

476 However, you cannot update the project. 

477 

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

479 the [GetProject] 

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

481 [ListProjects] 

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

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

484 methods. 

485 

486 This method behaves idempotently, such that deleting a 

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

488 won't do anything. 

489 

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

491 permissions for this project. 

492 

493 Returns: 

494 Callable[[~.DeleteProjectRequest], 

495 ~.Operation]: 

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

497 on the server. 

498 """ 

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

500 # the request. 

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

502 # to pass in the functions for each. 

503 if "delete_project" not in self._stubs: 

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

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

506 request_serializer=projects.DeleteProjectRequest.serialize, 

507 response_deserializer=operations_pb2.Operation.FromString, 

508 ) 

509 return self._stubs["delete_project"] 

510 

511 @property 

512 def undelete_project( 

513 self, 

514 ) -> Callable[[projects.UndeleteProjectRequest], operations_pb2.Operation]: 

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

516 

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

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

519 method for a project that has a lifecycle state of 

520 [DELETE_REQUESTED] [Projects.State.DELETE_REQUESTED]. After 

521 deletion starts, the project cannot be restored. 

522 

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

524 permission for this project. 

525 

526 Returns: 

527 Callable[[~.UndeleteProjectRequest], 

528 ~.Operation]: 

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

530 on the server. 

531 """ 

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

533 # the request. 

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

535 # to pass in the functions for each. 

536 if "undelete_project" not in self._stubs: 

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

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

539 request_serializer=projects.UndeleteProjectRequest.serialize, 

540 response_deserializer=operations_pb2.Operation.FromString, 

541 ) 

542 return self._stubs["undelete_project"] 

543 

544 @property 

545 def get_iam_policy( 

546 self, 

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

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

549 

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

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

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

553 do not exist. 

554 

555 Returns: 

556 Callable[[~.GetIamPolicyRequest], 

557 ~.Policy]: 

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

559 on the server. 

560 """ 

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

562 # the request. 

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

564 # to pass in the functions for each. 

565 if "get_iam_policy" not in self._stubs: 

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

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

568 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

569 response_deserializer=policy_pb2.Policy.FromString, 

570 ) 

571 return self._stubs["get_iam_policy"] 

572 

573 @property 

574 def set_iam_policy( 

575 self, 

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

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

578 

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

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

581 

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

583 cannot be used to append additional IAM settings. 

584 

585 Note: Removing service accounts from policies or changing their 

586 roles can render services completely inoperable. It is important 

587 to understand how the service account is being used before 

588 removing or updating its roles. 

589 

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

591 

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

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

594 a ``Policy``. 

595 

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

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

598 organization. For example, group@myownpersonaldomain.com 

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

600 myownpersonaldomain.com organization, but not the 

601 examplepetstore.com organization. 

602 

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

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

605 user must be invited using the Cloud Platform console and 

606 must accept the invitation. 

607 

608 - A user cannot be granted the owner role using 

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

610 using the Cloud Platform Console and must explicitly accept 

611 the invitation. 

612 

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

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

615 Platform Console. 

616 

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

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

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

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

621 This restriction also applies to legacy projects that no 

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

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

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

625 organization, you can remove all owners, potentially making 

626 the organization inaccessible. 

627 

628 Returns: 

629 Callable[[~.SetIamPolicyRequest], 

630 ~.Policy]: 

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

632 on the server. 

633 """ 

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

635 # the request. 

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

637 # to pass in the functions for each. 

638 if "set_iam_policy" not in self._stubs: 

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

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

641 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

642 response_deserializer=policy_pb2.Policy.FromString, 

643 ) 

644 return self._stubs["set_iam_policy"] 

645 

646 @property 

647 def test_iam_permissions( 

648 self, 

649 ) -> Callable[ 

650 [iam_policy_pb2.TestIamPermissionsRequest], 

651 iam_policy_pb2.TestIamPermissionsResponse, 

652 ]: 

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

654 

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

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

657 projects/123.. 

658 

659 Returns: 

660 Callable[[~.TestIamPermissionsRequest], 

661 ~.TestIamPermissionsResponse]: 

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

663 on the server. 

664 """ 

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

666 # the request. 

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

668 # to pass in the functions for each. 

669 if "test_iam_permissions" not in self._stubs: 

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

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

672 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

673 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

674 ) 

675 return self._stubs["test_iam_permissions"] 

676 

677 def close(self): 

678 self.grpc_channel.close() 

679 

680 @property 

681 def get_operation( 

682 self, 

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

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

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

686 # the request. 

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

688 # to pass in the functions for each. 

689 if "get_operation" not in self._stubs: 

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

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

692 request_serializer=operations_pb2.GetOperationRequest.SerializeToString, 

693 response_deserializer=operations_pb2.Operation.FromString, 

694 ) 

695 return self._stubs["get_operation"] 

696 

697 @property 

698 def kind(self) -> str: 

699 return "grpc" 

700 

701 

702__all__ = ("ProjectsGrpcTransport",)