Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/resourcemanager_v3/services/folders/transports/rest.py: 33%

452 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# 

16 

17import dataclasses 

18import json # type: ignore 

19import re 

20from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union 

21import warnings 

22 

23from google.api_core import ( 

24 gapic_v1, 

25 operations_v1, 

26 path_template, 

27 rest_helpers, 

28 rest_streaming, 

29) 

30from google.api_core import exceptions as core_exceptions 

31from google.api_core import retry as retries 

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

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

34from google.auth.transport.requests import AuthorizedSession # type: ignore 

35from google.longrunning import operations_pb2 

36from google.protobuf import json_format 

37import grpc # type: ignore 

38from requests import __version__ as requests_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 

45 

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

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

48from google.longrunning import operations_pb2 # type: ignore 

49 

50from google.cloud.resourcemanager_v3.types import folders 

51 

52from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

53from .base import FoldersTransport 

54 

55DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

56 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

57 grpc_version=None, 

58 rest_version=requests_version, 

59) 

60 

61 

62class FoldersRestInterceptor: 

63 """Interceptor for Folders. 

64 

65 Interceptors are used to manipulate requests, request metadata, and responses 

66 in arbitrary ways. 

67 Example use cases include: 

68 * Logging 

69 * Verifying requests according to service or custom semantics 

70 * Stripping extraneous information from responses 

71 

72 These use cases and more can be enabled by injecting an 

73 instance of a custom subclass when constructing the FoldersRestTransport. 

74 

75 .. code-block:: python 

76 class MyCustomFoldersInterceptor(FoldersRestInterceptor): 

77 def pre_create_folder(self, request, metadata): 

78 logging.log(f"Received request: {request}") 

79 return request, metadata 

80 

81 def post_create_folder(self, response): 

82 logging.log(f"Received response: {response}") 

83 return response 

84 

85 def pre_delete_folder(self, request, metadata): 

86 logging.log(f"Received request: {request}") 

87 return request, metadata 

88 

89 def post_delete_folder(self, response): 

90 logging.log(f"Received response: {response}") 

91 return response 

92 

93 def pre_get_folder(self, request, metadata): 

94 logging.log(f"Received request: {request}") 

95 return request, metadata 

96 

97 def post_get_folder(self, response): 

98 logging.log(f"Received response: {response}") 

99 return response 

100 

101 def pre_get_iam_policy(self, request, metadata): 

102 logging.log(f"Received request: {request}") 

103 return request, metadata 

104 

105 def post_get_iam_policy(self, response): 

106 logging.log(f"Received response: {response}") 

107 return response 

108 

109 def pre_list_folders(self, request, metadata): 

110 logging.log(f"Received request: {request}") 

111 return request, metadata 

112 

113 def post_list_folders(self, response): 

114 logging.log(f"Received response: {response}") 

115 return response 

116 

117 def pre_move_folder(self, request, metadata): 

118 logging.log(f"Received request: {request}") 

119 return request, metadata 

120 

121 def post_move_folder(self, response): 

122 logging.log(f"Received response: {response}") 

123 return response 

124 

125 def pre_search_folders(self, request, metadata): 

126 logging.log(f"Received request: {request}") 

127 return request, metadata 

128 

129 def post_search_folders(self, response): 

130 logging.log(f"Received response: {response}") 

131 return response 

132 

133 def pre_set_iam_policy(self, request, metadata): 

134 logging.log(f"Received request: {request}") 

135 return request, metadata 

136 

137 def post_set_iam_policy(self, response): 

138 logging.log(f"Received response: {response}") 

139 return response 

140 

141 def pre_test_iam_permissions(self, request, metadata): 

142 logging.log(f"Received request: {request}") 

143 return request, metadata 

144 

145 def post_test_iam_permissions(self, response): 

146 logging.log(f"Received response: {response}") 

147 return response 

148 

149 def pre_undelete_folder(self, request, metadata): 

150 logging.log(f"Received request: {request}") 

151 return request, metadata 

152 

153 def post_undelete_folder(self, response): 

154 logging.log(f"Received response: {response}") 

155 return response 

156 

157 def pre_update_folder(self, request, metadata): 

158 logging.log(f"Received request: {request}") 

159 return request, metadata 

160 

161 def post_update_folder(self, response): 

162 logging.log(f"Received response: {response}") 

163 return response 

164 

165 transport = FoldersRestTransport(interceptor=MyCustomFoldersInterceptor()) 

166 client = FoldersClient(transport=transport) 

167 

168 

169 """ 

170 

171 def pre_create_folder( 

172 self, request: folders.CreateFolderRequest, metadata: Sequence[Tuple[str, str]] 

173 ) -> Tuple[folders.CreateFolderRequest, Sequence[Tuple[str, str]]]: 

174 """Pre-rpc interceptor for create_folder 

175 

176 Override in a subclass to manipulate the request or metadata 

177 before they are sent to the Folders server. 

178 """ 

179 return request, metadata 

180 

181 def post_create_folder( 

182 self, response: operations_pb2.Operation 

183 ) -> operations_pb2.Operation: 

184 """Post-rpc interceptor for create_folder 

185 

186 Override in a subclass to manipulate the response 

187 after it is returned by the Folders server but before 

188 it is returned to user code. 

189 """ 

190 return response 

191 

192 def pre_delete_folder( 

193 self, request: folders.DeleteFolderRequest, metadata: Sequence[Tuple[str, str]] 

194 ) -> Tuple[folders.DeleteFolderRequest, Sequence[Tuple[str, str]]]: 

195 """Pre-rpc interceptor for delete_folder 

196 

197 Override in a subclass to manipulate the request or metadata 

198 before they are sent to the Folders server. 

199 """ 

200 return request, metadata 

201 

202 def post_delete_folder( 

203 self, response: operations_pb2.Operation 

204 ) -> operations_pb2.Operation: 

205 """Post-rpc interceptor for delete_folder 

206 

207 Override in a subclass to manipulate the response 

208 after it is returned by the Folders server but before 

209 it is returned to user code. 

210 """ 

211 return response 

212 

213 def pre_get_folder( 

214 self, request: folders.GetFolderRequest, metadata: Sequence[Tuple[str, str]] 

215 ) -> Tuple[folders.GetFolderRequest, Sequence[Tuple[str, str]]]: 

216 """Pre-rpc interceptor for get_folder 

217 

218 Override in a subclass to manipulate the request or metadata 

219 before they are sent to the Folders server. 

220 """ 

221 return request, metadata 

222 

223 def post_get_folder(self, response: folders.Folder) -> folders.Folder: 

224 """Post-rpc interceptor for get_folder 

225 

226 Override in a subclass to manipulate the response 

227 after it is returned by the Folders server but before 

228 it is returned to user code. 

229 """ 

230 return response 

231 

232 def pre_get_iam_policy( 

233 self, 

234 request: iam_policy_pb2.GetIamPolicyRequest, 

235 metadata: Sequence[Tuple[str, str]], 

236 ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: 

237 """Pre-rpc interceptor for get_iam_policy 

238 

239 Override in a subclass to manipulate the request or metadata 

240 before they are sent to the Folders server. 

241 """ 

242 return request, metadata 

243 

244 def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: 

245 """Post-rpc interceptor for get_iam_policy 

246 

247 Override in a subclass to manipulate the response 

248 after it is returned by the Folders server but before 

249 it is returned to user code. 

250 """ 

251 return response 

252 

253 def pre_list_folders( 

254 self, request: folders.ListFoldersRequest, metadata: Sequence[Tuple[str, str]] 

255 ) -> Tuple[folders.ListFoldersRequest, Sequence[Tuple[str, str]]]: 

256 """Pre-rpc interceptor for list_folders 

257 

258 Override in a subclass to manipulate the request or metadata 

259 before they are sent to the Folders server. 

260 """ 

261 return request, metadata 

262 

263 def post_list_folders( 

264 self, response: folders.ListFoldersResponse 

265 ) -> folders.ListFoldersResponse: 

266 """Post-rpc interceptor for list_folders 

267 

268 Override in a subclass to manipulate the response 

269 after it is returned by the Folders server but before 

270 it is returned to user code. 

271 """ 

272 return response 

273 

274 def pre_move_folder( 

275 self, request: folders.MoveFolderRequest, metadata: Sequence[Tuple[str, str]] 

276 ) -> Tuple[folders.MoveFolderRequest, Sequence[Tuple[str, str]]]: 

277 """Pre-rpc interceptor for move_folder 

278 

279 Override in a subclass to manipulate the request or metadata 

280 before they are sent to the Folders server. 

281 """ 

282 return request, metadata 

283 

284 def post_move_folder( 

285 self, response: operations_pb2.Operation 

286 ) -> operations_pb2.Operation: 

287 """Post-rpc interceptor for move_folder 

288 

289 Override in a subclass to manipulate the response 

290 after it is returned by the Folders server but before 

291 it is returned to user code. 

292 """ 

293 return response 

294 

295 def pre_search_folders( 

296 self, request: folders.SearchFoldersRequest, metadata: Sequence[Tuple[str, str]] 

297 ) -> Tuple[folders.SearchFoldersRequest, Sequence[Tuple[str, str]]]: 

298 """Pre-rpc interceptor for search_folders 

299 

300 Override in a subclass to manipulate the request or metadata 

301 before they are sent to the Folders server. 

302 """ 

303 return request, metadata 

304 

305 def post_search_folders( 

306 self, response: folders.SearchFoldersResponse 

307 ) -> folders.SearchFoldersResponse: 

308 """Post-rpc interceptor for search_folders 

309 

310 Override in a subclass to manipulate the response 

311 after it is returned by the Folders server but before 

312 it is returned to user code. 

313 """ 

314 return response 

315 

316 def pre_set_iam_policy( 

317 self, 

318 request: iam_policy_pb2.SetIamPolicyRequest, 

319 metadata: Sequence[Tuple[str, str]], 

320 ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: 

321 """Pre-rpc interceptor for set_iam_policy 

322 

323 Override in a subclass to manipulate the request or metadata 

324 before they are sent to the Folders server. 

325 """ 

326 return request, metadata 

327 

328 def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: 

329 """Post-rpc interceptor for set_iam_policy 

330 

331 Override in a subclass to manipulate the response 

332 after it is returned by the Folders server but before 

333 it is returned to user code. 

334 """ 

335 return response 

336 

337 def pre_test_iam_permissions( 

338 self, 

339 request: iam_policy_pb2.TestIamPermissionsRequest, 

340 metadata: Sequence[Tuple[str, str]], 

341 ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: 

342 """Pre-rpc interceptor for test_iam_permissions 

343 

344 Override in a subclass to manipulate the request or metadata 

345 before they are sent to the Folders server. 

346 """ 

347 return request, metadata 

348 

349 def post_test_iam_permissions( 

350 self, response: iam_policy_pb2.TestIamPermissionsResponse 

351 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

352 """Post-rpc interceptor for test_iam_permissions 

353 

354 Override in a subclass to manipulate the response 

355 after it is returned by the Folders server but before 

356 it is returned to user code. 

357 """ 

358 return response 

359 

360 def pre_undelete_folder( 

361 self, 

362 request: folders.UndeleteFolderRequest, 

363 metadata: Sequence[Tuple[str, str]], 

364 ) -> Tuple[folders.UndeleteFolderRequest, Sequence[Tuple[str, str]]]: 

365 """Pre-rpc interceptor for undelete_folder 

366 

367 Override in a subclass to manipulate the request or metadata 

368 before they are sent to the Folders server. 

369 """ 

370 return request, metadata 

371 

372 def post_undelete_folder( 

373 self, response: operations_pb2.Operation 

374 ) -> operations_pb2.Operation: 

375 """Post-rpc interceptor for undelete_folder 

376 

377 Override in a subclass to manipulate the response 

378 after it is returned by the Folders server but before 

379 it is returned to user code. 

380 """ 

381 return response 

382 

383 def pre_update_folder( 

384 self, request: folders.UpdateFolderRequest, metadata: Sequence[Tuple[str, str]] 

385 ) -> Tuple[folders.UpdateFolderRequest, Sequence[Tuple[str, str]]]: 

386 """Pre-rpc interceptor for update_folder 

387 

388 Override in a subclass to manipulate the request or metadata 

389 before they are sent to the Folders server. 

390 """ 

391 return request, metadata 

392 

393 def post_update_folder( 

394 self, response: operations_pb2.Operation 

395 ) -> operations_pb2.Operation: 

396 """Post-rpc interceptor for update_folder 

397 

398 Override in a subclass to manipulate the response 

399 after it is returned by the Folders server but before 

400 it is returned to user code. 

401 """ 

402 return response 

403 

404 def pre_get_operation( 

405 self, 

406 request: operations_pb2.GetOperationRequest, 

407 metadata: Sequence[Tuple[str, str]], 

408 ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: 

409 """Pre-rpc interceptor for get_operation 

410 

411 Override in a subclass to manipulate the request or metadata 

412 before they are sent to the Folders server. 

413 """ 

414 return request, metadata 

415 

416 def post_get_operation( 

417 self, response: operations_pb2.Operation 

418 ) -> operations_pb2.Operation: 

419 """Post-rpc interceptor for get_operation 

420 

421 Override in a subclass to manipulate the response 

422 after it is returned by the Folders server but before 

423 it is returned to user code. 

424 """ 

425 return response 

426 

427 

428@dataclasses.dataclass 

429class FoldersRestStub: 

430 _session: AuthorizedSession 

431 _host: str 

432 _interceptor: FoldersRestInterceptor 

433 

434 

435class FoldersRestTransport(FoldersTransport): 

436 """REST backend transport for Folders. 

437 

438 Manages Cloud Platform folder resources. 

439 Folders can be used to organize the resources under an 

440 organization and to control the policies applied to groups of 

441 resources. 

442 

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

444 primary client can load the underlying transport implementation 

445 and call it. 

446 

447 It sends JSON representations of protocol buffers over HTTP/1.1 

448 

449 """ 

450 

451 def __init__( 

452 self, 

453 *, 

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

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

456 credentials_file: Optional[str] = None, 

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

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

459 quota_project_id: Optional[str] = None, 

460 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

461 always_use_jwt_access: Optional[bool] = False, 

462 url_scheme: str = "https", 

463 interceptor: Optional[FoldersRestInterceptor] = None, 

464 api_audience: Optional[str] = None, 

465 ) -> None: 

466 """Instantiate the transport. 

467 

468 Args: 

469 host (Optional[str]): 

470 The hostname to connect to. 

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

472 authorization credentials to attach to requests. These 

473 credentials identify the application to the service; if none 

474 are specified, the client will attempt to ascertain the 

475 credentials from the environment. 

476 

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

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

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

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

481 ignored if ``channel`` is provided. 

482 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client 

483 certificate to configure mutual TLS HTTP channel. It is ignored 

484 if ``channel`` is provided. 

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

486 and quota. 

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

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

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

490 Generally, you only need to set this if you are developing 

491 your own client library. 

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

493 be used for service account credentials. 

494 url_scheme: the protocol scheme for the API endpoint. Normally 

495 "https", but for testing or local servers, 

496 "http" can be specified. 

497 """ 

498 # Run the base constructor 

499 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. 

500 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the 

501 # credentials object 

502 maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host) 

503 if maybe_url_match is None: 

504 raise ValueError( 

505 f"Unexpected hostname structure: {host}" 

506 ) # pragma: NO COVER 

507 

508 url_match_items = maybe_url_match.groupdict() 

509 

510 host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host 

511 

512 super().__init__( 

513 host=host, 

514 credentials=credentials, 

515 client_info=client_info, 

516 always_use_jwt_access=always_use_jwt_access, 

517 api_audience=api_audience, 

518 ) 

519 self._session = AuthorizedSession( 

520 self._credentials, default_host=self.DEFAULT_HOST 

521 ) 

522 self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None 

523 if client_cert_source_for_mtls: 

524 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

525 self._interceptor = interceptor or FoldersRestInterceptor() 

526 self._prep_wrapped_messages(client_info) 

527 

528 @property 

529 def operations_client(self) -> operations_v1.AbstractOperationsClient: 

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

531 

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

533 client. 

534 """ 

535 # Only create a new client if we do not already have one. 

536 if self._operations_client is None: 

537 http_options: Dict[str, List[Dict[str, str]]] = { 

538 "google.longrunning.Operations.GetOperation": [ 

539 { 

540 "method": "get", 

541 "uri": "/v3/{name=operations/**}", 

542 }, 

543 ], 

544 } 

545 

546 rest_transport = operations_v1.OperationsRestTransport( 

547 host=self._host, 

548 # use the credentials which are saved 

549 credentials=self._credentials, 

550 scopes=self._scopes, 

551 http_options=http_options, 

552 path_prefix="v3", 

553 ) 

554 

555 self._operations_client = operations_v1.AbstractOperationsClient( 

556 transport=rest_transport 

557 ) 

558 

559 # Return the client from cache. 

560 return self._operations_client 

561 

562 class _CreateFolder(FoldersRestStub): 

563 def __hash__(self): 

564 return hash("CreateFolder") 

565 

566 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

567 

568 @classmethod 

569 def _get_unset_required_fields(cls, message_dict): 

570 return { 

571 k: v 

572 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

573 if k not in message_dict 

574 } 

575 

576 def __call__( 

577 self, 

578 request: folders.CreateFolderRequest, 

579 *, 

580 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

581 timeout: Optional[float] = None, 

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

583 ) -> operations_pb2.Operation: 

584 r"""Call the create folder method over HTTP. 

585 

586 Args: 

587 request (~.folders.CreateFolderRequest): 

588 The request object. The CreateFolder request message. 

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

590 should be retried. 

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

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

593 sent along with the request as metadata. 

594 

595 Returns: 

596 ~.operations_pb2.Operation: 

597 This resource represents a 

598 long-running operation that is the 

599 result of a network API call. 

600 

601 """ 

602 

603 http_options: List[Dict[str, str]] = [ 

604 { 

605 "method": "post", 

606 "uri": "/v3/folders", 

607 "body": "folder", 

608 }, 

609 ] 

610 request, metadata = self._interceptor.pre_create_folder(request, metadata) 

611 pb_request = folders.CreateFolderRequest.pb(request) 

612 transcoded_request = path_template.transcode(http_options, pb_request) 

613 

614 # Jsonify the request body 

615 

616 body = json_format.MessageToJson( 

617 transcoded_request["body"], 

618 including_default_value_fields=False, 

619 use_integers_for_enums=True, 

620 ) 

621 uri = transcoded_request["uri"] 

622 method = transcoded_request["method"] 

623 

624 # Jsonify the query params 

625 query_params = json.loads( 

626 json_format.MessageToJson( 

627 transcoded_request["query_params"], 

628 including_default_value_fields=False, 

629 use_integers_for_enums=True, 

630 ) 

631 ) 

632 query_params.update(self._get_unset_required_fields(query_params)) 

633 

634 query_params["$alt"] = "json;enum-encoding=int" 

635 

636 # Send the request 

637 headers = dict(metadata) 

638 headers["Content-Type"] = "application/json" 

639 response = getattr(self._session, method)( 

640 "{host}{uri}".format(host=self._host, uri=uri), 

641 timeout=timeout, 

642 headers=headers, 

643 params=rest_helpers.flatten_query_params(query_params, strict=True), 

644 data=body, 

645 ) 

646 

647 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

648 # subclass. 

649 if response.status_code >= 400: 

650 raise core_exceptions.from_http_response(response) 

651 

652 # Return the response 

653 resp = operations_pb2.Operation() 

654 json_format.Parse(response.content, resp, ignore_unknown_fields=True) 

655 resp = self._interceptor.post_create_folder(resp) 

656 return resp 

657 

658 class _DeleteFolder(FoldersRestStub): 

659 def __hash__(self): 

660 return hash("DeleteFolder") 

661 

662 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

663 

664 @classmethod 

665 def _get_unset_required_fields(cls, message_dict): 

666 return { 

667 k: v 

668 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

669 if k not in message_dict 

670 } 

671 

672 def __call__( 

673 self, 

674 request: folders.DeleteFolderRequest, 

675 *, 

676 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

677 timeout: Optional[float] = None, 

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

679 ) -> operations_pb2.Operation: 

680 r"""Call the delete folder method over HTTP. 

681 

682 Args: 

683 request (~.folders.DeleteFolderRequest): 

684 The request object. The DeleteFolder request message. 

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

686 should be retried. 

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

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

689 sent along with the request as metadata. 

690 

691 Returns: 

692 ~.operations_pb2.Operation: 

693 This resource represents a 

694 long-running operation that is the 

695 result of a network API call. 

696 

697 """ 

698 

699 http_options: List[Dict[str, str]] = [ 

700 { 

701 "method": "delete", 

702 "uri": "/v3/{name=folders/*}", 

703 }, 

704 ] 

705 request, metadata = self._interceptor.pre_delete_folder(request, metadata) 

706 pb_request = folders.DeleteFolderRequest.pb(request) 

707 transcoded_request = path_template.transcode(http_options, pb_request) 

708 

709 uri = transcoded_request["uri"] 

710 method = transcoded_request["method"] 

711 

712 # Jsonify the query params 

713 query_params = json.loads( 

714 json_format.MessageToJson( 

715 transcoded_request["query_params"], 

716 including_default_value_fields=False, 

717 use_integers_for_enums=True, 

718 ) 

719 ) 

720 query_params.update(self._get_unset_required_fields(query_params)) 

721 

722 query_params["$alt"] = "json;enum-encoding=int" 

723 

724 # Send the request 

725 headers = dict(metadata) 

726 headers["Content-Type"] = "application/json" 

727 response = getattr(self._session, method)( 

728 "{host}{uri}".format(host=self._host, uri=uri), 

729 timeout=timeout, 

730 headers=headers, 

731 params=rest_helpers.flatten_query_params(query_params, strict=True), 

732 ) 

733 

734 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

735 # subclass. 

736 if response.status_code >= 400: 

737 raise core_exceptions.from_http_response(response) 

738 

739 # Return the response 

740 resp = operations_pb2.Operation() 

741 json_format.Parse(response.content, resp, ignore_unknown_fields=True) 

742 resp = self._interceptor.post_delete_folder(resp) 

743 return resp 

744 

745 class _GetFolder(FoldersRestStub): 

746 def __hash__(self): 

747 return hash("GetFolder") 

748 

749 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

750 

751 @classmethod 

752 def _get_unset_required_fields(cls, message_dict): 

753 return { 

754 k: v 

755 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

756 if k not in message_dict 

757 } 

758 

759 def __call__( 

760 self, 

761 request: folders.GetFolderRequest, 

762 *, 

763 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

764 timeout: Optional[float] = None, 

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

766 ) -> folders.Folder: 

767 r"""Call the get folder method over HTTP. 

768 

769 Args: 

770 request (~.folders.GetFolderRequest): 

771 The request object. The GetFolder request message. 

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

773 should be retried. 

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

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

776 sent along with the request as metadata. 

777 

778 Returns: 

779 ~.folders.Folder: 

780 A folder in an organization's 

781 resource hierarchy, used to organize 

782 that organization's resources. 

783 

784 """ 

785 

786 http_options: List[Dict[str, str]] = [ 

787 { 

788 "method": "get", 

789 "uri": "/v3/{name=folders/*}", 

790 }, 

791 ] 

792 request, metadata = self._interceptor.pre_get_folder(request, metadata) 

793 pb_request = folders.GetFolderRequest.pb(request) 

794 transcoded_request = path_template.transcode(http_options, pb_request) 

795 

796 uri = transcoded_request["uri"] 

797 method = transcoded_request["method"] 

798 

799 # Jsonify the query params 

800 query_params = json.loads( 

801 json_format.MessageToJson( 

802 transcoded_request["query_params"], 

803 including_default_value_fields=False, 

804 use_integers_for_enums=True, 

805 ) 

806 ) 

807 query_params.update(self._get_unset_required_fields(query_params)) 

808 

809 query_params["$alt"] = "json;enum-encoding=int" 

810 

811 # Send the request 

812 headers = dict(metadata) 

813 headers["Content-Type"] = "application/json" 

814 response = getattr(self._session, method)( 

815 "{host}{uri}".format(host=self._host, uri=uri), 

816 timeout=timeout, 

817 headers=headers, 

818 params=rest_helpers.flatten_query_params(query_params, strict=True), 

819 ) 

820 

821 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

822 # subclass. 

823 if response.status_code >= 400: 

824 raise core_exceptions.from_http_response(response) 

825 

826 # Return the response 

827 resp = folders.Folder() 

828 pb_resp = folders.Folder.pb(resp) 

829 

830 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

831 resp = self._interceptor.post_get_folder(resp) 

832 return resp 

833 

834 class _GetIamPolicy(FoldersRestStub): 

835 def __hash__(self): 

836 return hash("GetIamPolicy") 

837 

838 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

839 

840 @classmethod 

841 def _get_unset_required_fields(cls, message_dict): 

842 return { 

843 k: v 

844 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

845 if k not in message_dict 

846 } 

847 

848 def __call__( 

849 self, 

850 request: iam_policy_pb2.GetIamPolicyRequest, 

851 *, 

852 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

853 timeout: Optional[float] = None, 

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

855 ) -> policy_pb2.Policy: 

856 r"""Call the get iam policy method over HTTP. 

857 

858 Args: 

859 request (~.iam_policy_pb2.GetIamPolicyRequest): 

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

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

862 should be retried. 

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

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

865 sent along with the request as metadata. 

866 

867 Returns: 

868 ~.policy_pb2.Policy: 

869 An Identity and Access Management (IAM) policy, which 

870 specifies access controls for Google Cloud resources. 

871 

872 A ``Policy`` is a collection of ``bindings``. A 

873 ``binding`` binds one or more ``members``, or 

874 principals, to a single ``role``. Principals can be user 

875 accounts, service accounts, Google groups, and domains 

876 (such as G Suite). A ``role`` is a named list of 

877 permissions; each ``role`` can be an IAM predefined role 

878 or a user-created custom role. 

879 

880 For some types of Google Cloud resources, a ``binding`` 

881 can also specify a ``condition``, which is a logical 

882 expression that allows access to a resource only if the 

883 expression evaluates to ``true``. A condition can add 

884 constraints based on attributes of the request, the 

885 resource, or both. To learn which resources support 

886 conditions in their IAM policies, see the `IAM 

887 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. 

888 

889 **JSON example:** 

890 

891 :: 

892 

893 { 

894 "bindings": [ 

895 { 

896 "role": "roles/resourcemanager.organizationAdmin", 

897 "members": [ 

898 "user:mike@example.com", 

899 "group:admins@example.com", 

900 "domain:google.com", 

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

902 ] 

903 }, 

904 { 

905 "role": "roles/resourcemanager.organizationViewer", 

906 "members": [ 

907 "user:eve@example.com" 

908 ], 

909 "condition": { 

910 "title": "expirable access", 

911 "description": "Does not grant access after Sep 2020", 

912 "expression": "request.time < 

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

914 } 

915 } 

916 ], 

917 "etag": "BwWWja0YfJA=", 

918 "version": 3 

919 } 

920 

921 **YAML example:** 

922 

923 :: 

924 

925 bindings: 

926 - members: 

927 - user:mike@example.com 

928 - group:admins@example.com 

929 - domain:google.com 

930 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

931 role: roles/resourcemanager.organizationAdmin 

932 - members: 

933 - user:eve@example.com 

934 role: roles/resourcemanager.organizationViewer 

935 condition: 

936 title: expirable access 

937 description: Does not grant access after Sep 2020 

938 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

939 etag: BwWWja0YfJA= 

940 version: 3 

941 

942 For a description of IAM and its features, see the `IAM 

943 documentation <https://cloud.google.com/iam/docs/>`__. 

944 

945 """ 

946 

947 http_options: List[Dict[str, str]] = [ 

948 { 

949 "method": "post", 

950 "uri": "/v3/{resource=folders/*}:getIamPolicy", 

951 "body": "*", 

952 }, 

953 ] 

954 request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) 

955 pb_request = request 

956 transcoded_request = path_template.transcode(http_options, pb_request) 

957 

958 # Jsonify the request body 

959 

960 body = json_format.MessageToJson( 

961 transcoded_request["body"], 

962 including_default_value_fields=False, 

963 use_integers_for_enums=True, 

964 ) 

965 uri = transcoded_request["uri"] 

966 method = transcoded_request["method"] 

967 

968 # Jsonify the query params 

969 query_params = json.loads( 

970 json_format.MessageToJson( 

971 transcoded_request["query_params"], 

972 including_default_value_fields=False, 

973 use_integers_for_enums=True, 

974 ) 

975 ) 

976 query_params.update(self._get_unset_required_fields(query_params)) 

977 

978 query_params["$alt"] = "json;enum-encoding=int" 

979 

980 # Send the request 

981 headers = dict(metadata) 

982 headers["Content-Type"] = "application/json" 

983 response = getattr(self._session, method)( 

984 "{host}{uri}".format(host=self._host, uri=uri), 

985 timeout=timeout, 

986 headers=headers, 

987 params=rest_helpers.flatten_query_params(query_params, strict=True), 

988 data=body, 

989 ) 

990 

991 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

992 # subclass. 

993 if response.status_code >= 400: 

994 raise core_exceptions.from_http_response(response) 

995 

996 # Return the response 

997 resp = policy_pb2.Policy() 

998 pb_resp = resp 

999 

1000 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1001 resp = self._interceptor.post_get_iam_policy(resp) 

1002 return resp 

1003 

1004 class _ListFolders(FoldersRestStub): 

1005 def __hash__(self): 

1006 return hash("ListFolders") 

1007 

1008 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { 

1009 "parent": "", 

1010 } 

1011 

1012 @classmethod 

1013 def _get_unset_required_fields(cls, message_dict): 

1014 return { 

1015 k: v 

1016 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1017 if k not in message_dict 

1018 } 

1019 

1020 def __call__( 

1021 self, 

1022 request: folders.ListFoldersRequest, 

1023 *, 

1024 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1025 timeout: Optional[float] = None, 

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

1027 ) -> folders.ListFoldersResponse: 

1028 r"""Call the list folders method over HTTP. 

1029 

1030 Args: 

1031 request (~.folders.ListFoldersRequest): 

1032 The request object. The ListFolders request message. 

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

1034 should be retried. 

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

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

1037 sent along with the request as metadata. 

1038 

1039 Returns: 

1040 ~.folders.ListFoldersResponse: 

1041 The ListFolders response message. 

1042 """ 

1043 

1044 http_options: List[Dict[str, str]] = [ 

1045 { 

1046 "method": "get", 

1047 "uri": "/v3/folders", 

1048 }, 

1049 ] 

1050 request, metadata = self._interceptor.pre_list_folders(request, metadata) 

1051 pb_request = folders.ListFoldersRequest.pb(request) 

1052 transcoded_request = path_template.transcode(http_options, pb_request) 

1053 

1054 uri = transcoded_request["uri"] 

1055 method = transcoded_request["method"] 

1056 

1057 # Jsonify the query params 

1058 query_params = json.loads( 

1059 json_format.MessageToJson( 

1060 transcoded_request["query_params"], 

1061 including_default_value_fields=False, 

1062 use_integers_for_enums=True, 

1063 ) 

1064 ) 

1065 query_params.update(self._get_unset_required_fields(query_params)) 

1066 

1067 query_params["$alt"] = "json;enum-encoding=int" 

1068 

1069 # Send the request 

1070 headers = dict(metadata) 

1071 headers["Content-Type"] = "application/json" 

1072 response = getattr(self._session, method)( 

1073 "{host}{uri}".format(host=self._host, uri=uri), 

1074 timeout=timeout, 

1075 headers=headers, 

1076 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1077 ) 

1078 

1079 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1080 # subclass. 

1081 if response.status_code >= 400: 

1082 raise core_exceptions.from_http_response(response) 

1083 

1084 # Return the response 

1085 resp = folders.ListFoldersResponse() 

1086 pb_resp = folders.ListFoldersResponse.pb(resp) 

1087 

1088 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1089 resp = self._interceptor.post_list_folders(resp) 

1090 return resp 

1091 

1092 class _MoveFolder(FoldersRestStub): 

1093 def __hash__(self): 

1094 return hash("MoveFolder") 

1095 

1096 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1097 

1098 @classmethod 

1099 def _get_unset_required_fields(cls, message_dict): 

1100 return { 

1101 k: v 

1102 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1103 if k not in message_dict 

1104 } 

1105 

1106 def __call__( 

1107 self, 

1108 request: folders.MoveFolderRequest, 

1109 *, 

1110 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1111 timeout: Optional[float] = None, 

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

1113 ) -> operations_pb2.Operation: 

1114 r"""Call the move folder method over HTTP. 

1115 

1116 Args: 

1117 request (~.folders.MoveFolderRequest): 

1118 The request object. The MoveFolder request message. 

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

1120 should be retried. 

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

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

1123 sent along with the request as metadata. 

1124 

1125 Returns: 

1126 ~.operations_pb2.Operation: 

1127 This resource represents a 

1128 long-running operation that is the 

1129 result of a network API call. 

1130 

1131 """ 

1132 

1133 http_options: List[Dict[str, str]] = [ 

1134 { 

1135 "method": "post", 

1136 "uri": "/v3/{name=folders/*}:move", 

1137 "body": "*", 

1138 }, 

1139 ] 

1140 request, metadata = self._interceptor.pre_move_folder(request, metadata) 

1141 pb_request = folders.MoveFolderRequest.pb(request) 

1142 transcoded_request = path_template.transcode(http_options, pb_request) 

1143 

1144 # Jsonify the request body 

1145 

1146 body = json_format.MessageToJson( 

1147 transcoded_request["body"], 

1148 including_default_value_fields=False, 

1149 use_integers_for_enums=True, 

1150 ) 

1151 uri = transcoded_request["uri"] 

1152 method = transcoded_request["method"] 

1153 

1154 # Jsonify the query params 

1155 query_params = json.loads( 

1156 json_format.MessageToJson( 

1157 transcoded_request["query_params"], 

1158 including_default_value_fields=False, 

1159 use_integers_for_enums=True, 

1160 ) 

1161 ) 

1162 query_params.update(self._get_unset_required_fields(query_params)) 

1163 

1164 query_params["$alt"] = "json;enum-encoding=int" 

1165 

1166 # Send the request 

1167 headers = dict(metadata) 

1168 headers["Content-Type"] = "application/json" 

1169 response = getattr(self._session, method)( 

1170 "{host}{uri}".format(host=self._host, uri=uri), 

1171 timeout=timeout, 

1172 headers=headers, 

1173 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1174 data=body, 

1175 ) 

1176 

1177 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1178 # subclass. 

1179 if response.status_code >= 400: 

1180 raise core_exceptions.from_http_response(response) 

1181 

1182 # Return the response 

1183 resp = operations_pb2.Operation() 

1184 json_format.Parse(response.content, resp, ignore_unknown_fields=True) 

1185 resp = self._interceptor.post_move_folder(resp) 

1186 return resp 

1187 

1188 class _SearchFolders(FoldersRestStub): 

1189 def __hash__(self): 

1190 return hash("SearchFolders") 

1191 

1192 def __call__( 

1193 self, 

1194 request: folders.SearchFoldersRequest, 

1195 *, 

1196 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1197 timeout: Optional[float] = None, 

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

1199 ) -> folders.SearchFoldersResponse: 

1200 r"""Call the search folders method over HTTP. 

1201 

1202 Args: 

1203 request (~.folders.SearchFoldersRequest): 

1204 The request object. The request message for searching 

1205 folders. 

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

1207 should be retried. 

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

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

1210 sent along with the request as metadata. 

1211 

1212 Returns: 

1213 ~.folders.SearchFoldersResponse: 

1214 The response message for searching 

1215 folders. 

1216 

1217 """ 

1218 

1219 http_options: List[Dict[str, str]] = [ 

1220 { 

1221 "method": "get", 

1222 "uri": "/v3/folders:search", 

1223 }, 

1224 ] 

1225 request, metadata = self._interceptor.pre_search_folders(request, metadata) 

1226 pb_request = folders.SearchFoldersRequest.pb(request) 

1227 transcoded_request = path_template.transcode(http_options, pb_request) 

1228 

1229 uri = transcoded_request["uri"] 

1230 method = transcoded_request["method"] 

1231 

1232 # Jsonify the query params 

1233 query_params = json.loads( 

1234 json_format.MessageToJson( 

1235 transcoded_request["query_params"], 

1236 including_default_value_fields=False, 

1237 use_integers_for_enums=True, 

1238 ) 

1239 ) 

1240 

1241 query_params["$alt"] = "json;enum-encoding=int" 

1242 

1243 # Send the request 

1244 headers = dict(metadata) 

1245 headers["Content-Type"] = "application/json" 

1246 response = getattr(self._session, method)( 

1247 "{host}{uri}".format(host=self._host, uri=uri), 

1248 timeout=timeout, 

1249 headers=headers, 

1250 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1251 ) 

1252 

1253 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1254 # subclass. 

1255 if response.status_code >= 400: 

1256 raise core_exceptions.from_http_response(response) 

1257 

1258 # Return the response 

1259 resp = folders.SearchFoldersResponse() 

1260 pb_resp = folders.SearchFoldersResponse.pb(resp) 

1261 

1262 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1263 resp = self._interceptor.post_search_folders(resp) 

1264 return resp 

1265 

1266 class _SetIamPolicy(FoldersRestStub): 

1267 def __hash__(self): 

1268 return hash("SetIamPolicy") 

1269 

1270 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1271 

1272 @classmethod 

1273 def _get_unset_required_fields(cls, message_dict): 

1274 return { 

1275 k: v 

1276 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1277 if k not in message_dict 

1278 } 

1279 

1280 def __call__( 

1281 self, 

1282 request: iam_policy_pb2.SetIamPolicyRequest, 

1283 *, 

1284 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1285 timeout: Optional[float] = None, 

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

1287 ) -> policy_pb2.Policy: 

1288 r"""Call the set iam policy method over HTTP. 

1289 

1290 Args: 

1291 request (~.iam_policy_pb2.SetIamPolicyRequest): 

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

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

1294 should be retried. 

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

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

1297 sent along with the request as metadata. 

1298 

1299 Returns: 

1300 ~.policy_pb2.Policy: 

1301 An Identity and Access Management (IAM) policy, which 

1302 specifies access controls for Google Cloud resources. 

1303 

1304 A ``Policy`` is a collection of ``bindings``. A 

1305 ``binding`` binds one or more ``members``, or 

1306 principals, to a single ``role``. Principals can be user 

1307 accounts, service accounts, Google groups, and domains 

1308 (such as G Suite). A ``role`` is a named list of 

1309 permissions; each ``role`` can be an IAM predefined role 

1310 or a user-created custom role. 

1311 

1312 For some types of Google Cloud resources, a ``binding`` 

1313 can also specify a ``condition``, which is a logical 

1314 expression that allows access to a resource only if the 

1315 expression evaluates to ``true``. A condition can add 

1316 constraints based on attributes of the request, the 

1317 resource, or both. To learn which resources support 

1318 conditions in their IAM policies, see the `IAM 

1319 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. 

1320 

1321 **JSON example:** 

1322 

1323 :: 

1324 

1325 { 

1326 "bindings": [ 

1327 { 

1328 "role": "roles/resourcemanager.organizationAdmin", 

1329 "members": [ 

1330 "user:mike@example.com", 

1331 "group:admins@example.com", 

1332 "domain:google.com", 

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

1334 ] 

1335 }, 

1336 { 

1337 "role": "roles/resourcemanager.organizationViewer", 

1338 "members": [ 

1339 "user:eve@example.com" 

1340 ], 

1341 "condition": { 

1342 "title": "expirable access", 

1343 "description": "Does not grant access after Sep 2020", 

1344 "expression": "request.time < 

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

1346 } 

1347 } 

1348 ], 

1349 "etag": "BwWWja0YfJA=", 

1350 "version": 3 

1351 } 

1352 

1353 **YAML example:** 

1354 

1355 :: 

1356 

1357 bindings: 

1358 - members: 

1359 - user:mike@example.com 

1360 - group:admins@example.com 

1361 - domain:google.com 

1362 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

1363 role: roles/resourcemanager.organizationAdmin 

1364 - members: 

1365 - user:eve@example.com 

1366 role: roles/resourcemanager.organizationViewer 

1367 condition: 

1368 title: expirable access 

1369 description: Does not grant access after Sep 2020 

1370 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

1371 etag: BwWWja0YfJA= 

1372 version: 3 

1373 

1374 For a description of IAM and its features, see the `IAM 

1375 documentation <https://cloud.google.com/iam/docs/>`__. 

1376 

1377 """ 

1378 

1379 http_options: List[Dict[str, str]] = [ 

1380 { 

1381 "method": "post", 

1382 "uri": "/v3/{resource=folders/*}:setIamPolicy", 

1383 "body": "*", 

1384 }, 

1385 ] 

1386 request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) 

1387 pb_request = request 

1388 transcoded_request = path_template.transcode(http_options, pb_request) 

1389 

1390 # Jsonify the request body 

1391 

1392 body = json_format.MessageToJson( 

1393 transcoded_request["body"], 

1394 including_default_value_fields=False, 

1395 use_integers_for_enums=True, 

1396 ) 

1397 uri = transcoded_request["uri"] 

1398 method = transcoded_request["method"] 

1399 

1400 # Jsonify the query params 

1401 query_params = json.loads( 

1402 json_format.MessageToJson( 

1403 transcoded_request["query_params"], 

1404 including_default_value_fields=False, 

1405 use_integers_for_enums=True, 

1406 ) 

1407 ) 

1408 query_params.update(self._get_unset_required_fields(query_params)) 

1409 

1410 query_params["$alt"] = "json;enum-encoding=int" 

1411 

1412 # Send the request 

1413 headers = dict(metadata) 

1414 headers["Content-Type"] = "application/json" 

1415 response = getattr(self._session, method)( 

1416 "{host}{uri}".format(host=self._host, uri=uri), 

1417 timeout=timeout, 

1418 headers=headers, 

1419 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1420 data=body, 

1421 ) 

1422 

1423 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1424 # subclass. 

1425 if response.status_code >= 400: 

1426 raise core_exceptions.from_http_response(response) 

1427 

1428 # Return the response 

1429 resp = policy_pb2.Policy() 

1430 pb_resp = resp 

1431 

1432 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1433 resp = self._interceptor.post_set_iam_policy(resp) 

1434 return resp 

1435 

1436 class _TestIamPermissions(FoldersRestStub): 

1437 def __hash__(self): 

1438 return hash("TestIamPermissions") 

1439 

1440 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1441 

1442 @classmethod 

1443 def _get_unset_required_fields(cls, message_dict): 

1444 return { 

1445 k: v 

1446 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1447 if k not in message_dict 

1448 } 

1449 

1450 def __call__( 

1451 self, 

1452 request: iam_policy_pb2.TestIamPermissionsRequest, 

1453 *, 

1454 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1455 timeout: Optional[float] = None, 

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

1457 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1458 r"""Call the test iam permissions method over HTTP. 

1459 

1460 Args: 

1461 request (~.iam_policy_pb2.TestIamPermissionsRequest): 

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

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

1464 should be retried. 

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

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

1467 sent along with the request as metadata. 

1468 

1469 Returns: 

1470 ~.iam_policy_pb2.TestIamPermissionsResponse: 

1471 Response message for ``TestIamPermissions`` method. 

1472 """ 

1473 

1474 http_options: List[Dict[str, str]] = [ 

1475 { 

1476 "method": "post", 

1477 "uri": "/v3/{resource=folders/*}:testIamPermissions", 

1478 "body": "*", 

1479 }, 

1480 ] 

1481 request, metadata = self._interceptor.pre_test_iam_permissions( 

1482 request, metadata 

1483 ) 

1484 pb_request = request 

1485 transcoded_request = path_template.transcode(http_options, pb_request) 

1486 

1487 # Jsonify the request body 

1488 

1489 body = json_format.MessageToJson( 

1490 transcoded_request["body"], 

1491 including_default_value_fields=False, 

1492 use_integers_for_enums=True, 

1493 ) 

1494 uri = transcoded_request["uri"] 

1495 method = transcoded_request["method"] 

1496 

1497 # Jsonify the query params 

1498 query_params = json.loads( 

1499 json_format.MessageToJson( 

1500 transcoded_request["query_params"], 

1501 including_default_value_fields=False, 

1502 use_integers_for_enums=True, 

1503 ) 

1504 ) 

1505 query_params.update(self._get_unset_required_fields(query_params)) 

1506 

1507 query_params["$alt"] = "json;enum-encoding=int" 

1508 

1509 # Send the request 

1510 headers = dict(metadata) 

1511 headers["Content-Type"] = "application/json" 

1512 response = getattr(self._session, method)( 

1513 "{host}{uri}".format(host=self._host, uri=uri), 

1514 timeout=timeout, 

1515 headers=headers, 

1516 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1517 data=body, 

1518 ) 

1519 

1520 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1521 # subclass. 

1522 if response.status_code >= 400: 

1523 raise core_exceptions.from_http_response(response) 

1524 

1525 # Return the response 

1526 resp = iam_policy_pb2.TestIamPermissionsResponse() 

1527 pb_resp = resp 

1528 

1529 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1530 resp = self._interceptor.post_test_iam_permissions(resp) 

1531 return resp 

1532 

1533 class _UndeleteFolder(FoldersRestStub): 

1534 def __hash__(self): 

1535 return hash("UndeleteFolder") 

1536 

1537 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1538 

1539 @classmethod 

1540 def _get_unset_required_fields(cls, message_dict): 

1541 return { 

1542 k: v 

1543 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1544 if k not in message_dict 

1545 } 

1546 

1547 def __call__( 

1548 self, 

1549 request: folders.UndeleteFolderRequest, 

1550 *, 

1551 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1552 timeout: Optional[float] = None, 

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

1554 ) -> operations_pb2.Operation: 

1555 r"""Call the undelete folder method over HTTP. 

1556 

1557 Args: 

1558 request (~.folders.UndeleteFolderRequest): 

1559 The request object. The UndeleteFolder request message. 

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

1561 should be retried. 

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

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

1564 sent along with the request as metadata. 

1565 

1566 Returns: 

1567 ~.operations_pb2.Operation: 

1568 This resource represents a 

1569 long-running operation that is the 

1570 result of a network API call. 

1571 

1572 """ 

1573 

1574 http_options: List[Dict[str, str]] = [ 

1575 { 

1576 "method": "post", 

1577 "uri": "/v3/{name=folders/*}:undelete", 

1578 "body": "*", 

1579 }, 

1580 ] 

1581 request, metadata = self._interceptor.pre_undelete_folder(request, metadata) 

1582 pb_request = folders.UndeleteFolderRequest.pb(request) 

1583 transcoded_request = path_template.transcode(http_options, pb_request) 

1584 

1585 # Jsonify the request body 

1586 

1587 body = json_format.MessageToJson( 

1588 transcoded_request["body"], 

1589 including_default_value_fields=False, 

1590 use_integers_for_enums=True, 

1591 ) 

1592 uri = transcoded_request["uri"] 

1593 method = transcoded_request["method"] 

1594 

1595 # Jsonify the query params 

1596 query_params = json.loads( 

1597 json_format.MessageToJson( 

1598 transcoded_request["query_params"], 

1599 including_default_value_fields=False, 

1600 use_integers_for_enums=True, 

1601 ) 

1602 ) 

1603 query_params.update(self._get_unset_required_fields(query_params)) 

1604 

1605 query_params["$alt"] = "json;enum-encoding=int" 

1606 

1607 # Send the request 

1608 headers = dict(metadata) 

1609 headers["Content-Type"] = "application/json" 

1610 response = getattr(self._session, method)( 

1611 "{host}{uri}".format(host=self._host, uri=uri), 

1612 timeout=timeout, 

1613 headers=headers, 

1614 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1615 data=body, 

1616 ) 

1617 

1618 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1619 # subclass. 

1620 if response.status_code >= 400: 

1621 raise core_exceptions.from_http_response(response) 

1622 

1623 # Return the response 

1624 resp = operations_pb2.Operation() 

1625 json_format.Parse(response.content, resp, ignore_unknown_fields=True) 

1626 resp = self._interceptor.post_undelete_folder(resp) 

1627 return resp 

1628 

1629 class _UpdateFolder(FoldersRestStub): 

1630 def __hash__(self): 

1631 return hash("UpdateFolder") 

1632 

1633 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { 

1634 "updateMask": {}, 

1635 } 

1636 

1637 @classmethod 

1638 def _get_unset_required_fields(cls, message_dict): 

1639 return { 

1640 k: v 

1641 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1642 if k not in message_dict 

1643 } 

1644 

1645 def __call__( 

1646 self, 

1647 request: folders.UpdateFolderRequest, 

1648 *, 

1649 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1650 timeout: Optional[float] = None, 

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

1652 ) -> operations_pb2.Operation: 

1653 r"""Call the update folder method over HTTP. 

1654 

1655 Args: 

1656 request (~.folders.UpdateFolderRequest): 

1657 The request object. The request sent to the 

1658 [UpdateFolder][google.cloud.resourcemanager.v3.Folder.UpdateFolder] 

1659 method. 

1660 

1661 Only the ``display_name`` field can be changed. All 

1662 other fields will be ignored. Use the 

1663 [MoveFolder][google.cloud.resourcemanager.v3.Folders.MoveFolder] 

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

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

1666 should be retried. 

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

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

1669 sent along with the request as metadata. 

1670 

1671 Returns: 

1672 ~.operations_pb2.Operation: 

1673 This resource represents a 

1674 long-running operation that is the 

1675 result of a network API call. 

1676 

1677 """ 

1678 

1679 http_options: List[Dict[str, str]] = [ 

1680 { 

1681 "method": "patch", 

1682 "uri": "/v3/{folder.name=folders/*}", 

1683 "body": "folder", 

1684 }, 

1685 ] 

1686 request, metadata = self._interceptor.pre_update_folder(request, metadata) 

1687 pb_request = folders.UpdateFolderRequest.pb(request) 

1688 transcoded_request = path_template.transcode(http_options, pb_request) 

1689 

1690 # Jsonify the request body 

1691 

1692 body = json_format.MessageToJson( 

1693 transcoded_request["body"], 

1694 including_default_value_fields=False, 

1695 use_integers_for_enums=True, 

1696 ) 

1697 uri = transcoded_request["uri"] 

1698 method = transcoded_request["method"] 

1699 

1700 # Jsonify the query params 

1701 query_params = json.loads( 

1702 json_format.MessageToJson( 

1703 transcoded_request["query_params"], 

1704 including_default_value_fields=False, 

1705 use_integers_for_enums=True, 

1706 ) 

1707 ) 

1708 query_params.update(self._get_unset_required_fields(query_params)) 

1709 

1710 query_params["$alt"] = "json;enum-encoding=int" 

1711 

1712 # Send the request 

1713 headers = dict(metadata) 

1714 headers["Content-Type"] = "application/json" 

1715 response = getattr(self._session, method)( 

1716 "{host}{uri}".format(host=self._host, uri=uri), 

1717 timeout=timeout, 

1718 headers=headers, 

1719 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1720 data=body, 

1721 ) 

1722 

1723 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1724 # subclass. 

1725 if response.status_code >= 400: 

1726 raise core_exceptions.from_http_response(response) 

1727 

1728 # Return the response 

1729 resp = operations_pb2.Operation() 

1730 json_format.Parse(response.content, resp, ignore_unknown_fields=True) 

1731 resp = self._interceptor.post_update_folder(resp) 

1732 return resp 

1733 

1734 @property 

1735 def create_folder( 

1736 self, 

1737 ) -> Callable[[folders.CreateFolderRequest], operations_pb2.Operation]: 

1738 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1739 # In C++ this would require a dynamic_cast 

1740 return self._CreateFolder(self._session, self._host, self._interceptor) # type: ignore 

1741 

1742 @property 

1743 def delete_folder( 

1744 self, 

1745 ) -> Callable[[folders.DeleteFolderRequest], operations_pb2.Operation]: 

1746 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1747 # In C++ this would require a dynamic_cast 

1748 return self._DeleteFolder(self._session, self._host, self._interceptor) # type: ignore 

1749 

1750 @property 

1751 def get_folder(self) -> Callable[[folders.GetFolderRequest], folders.Folder]: 

1752 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1753 # In C++ this would require a dynamic_cast 

1754 return self._GetFolder(self._session, self._host, self._interceptor) # type: ignore 

1755 

1756 @property 

1757 def get_iam_policy( 

1758 self, 

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

1760 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1761 # In C++ this would require a dynamic_cast 

1762 return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore 

1763 

1764 @property 

1765 def list_folders( 

1766 self, 

1767 ) -> Callable[[folders.ListFoldersRequest], folders.ListFoldersResponse]: 

1768 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1769 # In C++ this would require a dynamic_cast 

1770 return self._ListFolders(self._session, self._host, self._interceptor) # type: ignore 

1771 

1772 @property 

1773 def move_folder( 

1774 self, 

1775 ) -> Callable[[folders.MoveFolderRequest], operations_pb2.Operation]: 

1776 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1777 # In C++ this would require a dynamic_cast 

1778 return self._MoveFolder(self._session, self._host, self._interceptor) # type: ignore 

1779 

1780 @property 

1781 def search_folders( 

1782 self, 

1783 ) -> Callable[[folders.SearchFoldersRequest], folders.SearchFoldersResponse]: 

1784 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1785 # In C++ this would require a dynamic_cast 

1786 return self._SearchFolders(self._session, self._host, self._interceptor) # type: ignore 

1787 

1788 @property 

1789 def set_iam_policy( 

1790 self, 

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

1792 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1793 # In C++ this would require a dynamic_cast 

1794 return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore 

1795 

1796 @property 

1797 def test_iam_permissions( 

1798 self, 

1799 ) -> Callable[ 

1800 [iam_policy_pb2.TestIamPermissionsRequest], 

1801 iam_policy_pb2.TestIamPermissionsResponse, 

1802 ]: 

1803 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1804 # In C++ this would require a dynamic_cast 

1805 return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore 

1806 

1807 @property 

1808 def undelete_folder( 

1809 self, 

1810 ) -> Callable[[folders.UndeleteFolderRequest], operations_pb2.Operation]: 

1811 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1812 # In C++ this would require a dynamic_cast 

1813 return self._UndeleteFolder(self._session, self._host, self._interceptor) # type: ignore 

1814 

1815 @property 

1816 def update_folder( 

1817 self, 

1818 ) -> Callable[[folders.UpdateFolderRequest], operations_pb2.Operation]: 

1819 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

1820 # In C++ this would require a dynamic_cast 

1821 return self._UpdateFolder(self._session, self._host, self._interceptor) # type: ignore 

1822 

1823 @property 

1824 def get_operation(self): 

1825 return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore 

1826 

1827 class _GetOperation(FoldersRestStub): 

1828 def __call__( 

1829 self, 

1830 request: operations_pb2.GetOperationRequest, 

1831 *, 

1832 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1833 timeout: Optional[float] = None, 

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

1835 ) -> operations_pb2.Operation: 

1836 

1837 r"""Call the get operation method over HTTP. 

1838 

1839 Args: 

1840 request (operations_pb2.GetOperationRequest): 

1841 The request object for GetOperation method. 

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

1843 should be retried. 

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

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

1846 sent along with the request as metadata. 

1847 

1848 Returns: 

1849 operations_pb2.Operation: Response from GetOperation method. 

1850 """ 

1851 

1852 http_options: List[Dict[str, str]] = [ 

1853 { 

1854 "method": "get", 

1855 "uri": "/v3/{name=operations/**}", 

1856 }, 

1857 ] 

1858 

1859 request, metadata = self._interceptor.pre_get_operation(request, metadata) 

1860 request_kwargs = json_format.MessageToDict(request) 

1861 transcoded_request = path_template.transcode(http_options, **request_kwargs) 

1862 

1863 uri = transcoded_request["uri"] 

1864 method = transcoded_request["method"] 

1865 

1866 # Jsonify the query params 

1867 query_params = json.loads(json.dumps(transcoded_request["query_params"])) 

1868 

1869 # Send the request 

1870 headers = dict(metadata) 

1871 headers["Content-Type"] = "application/json" 

1872 

1873 response = getattr(self._session, method)( 

1874 "{host}{uri}".format(host=self._host, uri=uri), 

1875 timeout=timeout, 

1876 headers=headers, 

1877 params=rest_helpers.flatten_query_params(query_params), 

1878 ) 

1879 

1880 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1881 # subclass. 

1882 if response.status_code >= 400: 

1883 raise core_exceptions.from_http_response(response) 

1884 

1885 resp = operations_pb2.Operation() 

1886 resp = json_format.Parse(response.content.decode("utf-8"), resp) 

1887 resp = self._interceptor.post_get_operation(resp) 

1888 return resp 

1889 

1890 @property 

1891 def kind(self) -> str: 

1892 return "rest" 

1893 

1894 def close(self): 

1895 self._session.close() 

1896 

1897 

1898__all__ = ("FoldersRestTransport",)