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

389 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 tag_keys 

51 

52from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

53from .base import TagKeysTransport 

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 TagKeysRestInterceptor: 

63 """Interceptor for TagKeys. 

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 TagKeysRestTransport. 

74 

75 .. code-block:: python 

76 class MyCustomTagKeysInterceptor(TagKeysRestInterceptor): 

77 def pre_create_tag_key(self, request, metadata): 

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

79 return request, metadata 

80 

81 def post_create_tag_key(self, response): 

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

83 return response 

84 

85 def pre_delete_tag_key(self, request, metadata): 

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

87 return request, metadata 

88 

89 def post_delete_tag_key(self, response): 

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

91 return response 

92 

93 def pre_get_iam_policy(self, request, metadata): 

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

95 return request, metadata 

96 

97 def post_get_iam_policy(self, response): 

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

99 return response 

100 

101 def pre_get_namespaced_tag_key(self, request, metadata): 

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

103 return request, metadata 

104 

105 def post_get_namespaced_tag_key(self, response): 

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

107 return response 

108 

109 def pre_get_tag_key(self, request, metadata): 

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

111 return request, metadata 

112 

113 def post_get_tag_key(self, response): 

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

115 return response 

116 

117 def pre_list_tag_keys(self, request, metadata): 

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

119 return request, metadata 

120 

121 def post_list_tag_keys(self, response): 

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

123 return response 

124 

125 def pre_set_iam_policy(self, request, metadata): 

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

127 return request, metadata 

128 

129 def post_set_iam_policy(self, response): 

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

131 return response 

132 

133 def pre_test_iam_permissions(self, request, metadata): 

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

135 return request, metadata 

136 

137 def post_test_iam_permissions(self, response): 

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

139 return response 

140 

141 def pre_update_tag_key(self, request, metadata): 

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

143 return request, metadata 

144 

145 def post_update_tag_key(self, response): 

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

147 return response 

148 

149 transport = TagKeysRestTransport(interceptor=MyCustomTagKeysInterceptor()) 

150 client = TagKeysClient(transport=transport) 

151 

152 

153 """ 

154 

155 def pre_create_tag_key( 

156 self, request: tag_keys.CreateTagKeyRequest, metadata: Sequence[Tuple[str, str]] 

157 ) -> Tuple[tag_keys.CreateTagKeyRequest, Sequence[Tuple[str, str]]]: 

158 """Pre-rpc interceptor for create_tag_key 

159 

160 Override in a subclass to manipulate the request or metadata 

161 before they are sent to the TagKeys server. 

162 """ 

163 return request, metadata 

164 

165 def post_create_tag_key( 

166 self, response: operations_pb2.Operation 

167 ) -> operations_pb2.Operation: 

168 """Post-rpc interceptor for create_tag_key 

169 

170 Override in a subclass to manipulate the response 

171 after it is returned by the TagKeys server but before 

172 it is returned to user code. 

173 """ 

174 return response 

175 

176 def pre_delete_tag_key( 

177 self, request: tag_keys.DeleteTagKeyRequest, metadata: Sequence[Tuple[str, str]] 

178 ) -> Tuple[tag_keys.DeleteTagKeyRequest, Sequence[Tuple[str, str]]]: 

179 """Pre-rpc interceptor for delete_tag_key 

180 

181 Override in a subclass to manipulate the request or metadata 

182 before they are sent to the TagKeys server. 

183 """ 

184 return request, metadata 

185 

186 def post_delete_tag_key( 

187 self, response: operations_pb2.Operation 

188 ) -> operations_pb2.Operation: 

189 """Post-rpc interceptor for delete_tag_key 

190 

191 Override in a subclass to manipulate the response 

192 after it is returned by the TagKeys server but before 

193 it is returned to user code. 

194 """ 

195 return response 

196 

197 def pre_get_iam_policy( 

198 self, 

199 request: iam_policy_pb2.GetIamPolicyRequest, 

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

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

202 """Pre-rpc interceptor for get_iam_policy 

203 

204 Override in a subclass to manipulate the request or metadata 

205 before they are sent to the TagKeys server. 

206 """ 

207 return request, metadata 

208 

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

210 """Post-rpc interceptor for get_iam_policy 

211 

212 Override in a subclass to manipulate the response 

213 after it is returned by the TagKeys server but before 

214 it is returned to user code. 

215 """ 

216 return response 

217 

218 def pre_get_namespaced_tag_key( 

219 self, 

220 request: tag_keys.GetNamespacedTagKeyRequest, 

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

222 ) -> Tuple[tag_keys.GetNamespacedTagKeyRequest, Sequence[Tuple[str, str]]]: 

223 """Pre-rpc interceptor for get_namespaced_tag_key 

224 

225 Override in a subclass to manipulate the request or metadata 

226 before they are sent to the TagKeys server. 

227 """ 

228 return request, metadata 

229 

230 def post_get_namespaced_tag_key(self, response: tag_keys.TagKey) -> tag_keys.TagKey: 

231 """Post-rpc interceptor for get_namespaced_tag_key 

232 

233 Override in a subclass to manipulate the response 

234 after it is returned by the TagKeys server but before 

235 it is returned to user code. 

236 """ 

237 return response 

238 

239 def pre_get_tag_key( 

240 self, request: tag_keys.GetTagKeyRequest, metadata: Sequence[Tuple[str, str]] 

241 ) -> Tuple[tag_keys.GetTagKeyRequest, Sequence[Tuple[str, str]]]: 

242 """Pre-rpc interceptor for get_tag_key 

243 

244 Override in a subclass to manipulate the request or metadata 

245 before they are sent to the TagKeys server. 

246 """ 

247 return request, metadata 

248 

249 def post_get_tag_key(self, response: tag_keys.TagKey) -> tag_keys.TagKey: 

250 """Post-rpc interceptor for get_tag_key 

251 

252 Override in a subclass to manipulate the response 

253 after it is returned by the TagKeys server but before 

254 it is returned to user code. 

255 """ 

256 return response 

257 

258 def pre_list_tag_keys( 

259 self, request: tag_keys.ListTagKeysRequest, metadata: Sequence[Tuple[str, str]] 

260 ) -> Tuple[tag_keys.ListTagKeysRequest, Sequence[Tuple[str, str]]]: 

261 """Pre-rpc interceptor for list_tag_keys 

262 

263 Override in a subclass to manipulate the request or metadata 

264 before they are sent to the TagKeys server. 

265 """ 

266 return request, metadata 

267 

268 def post_list_tag_keys( 

269 self, response: tag_keys.ListTagKeysResponse 

270 ) -> tag_keys.ListTagKeysResponse: 

271 """Post-rpc interceptor for list_tag_keys 

272 

273 Override in a subclass to manipulate the response 

274 after it is returned by the TagKeys server but before 

275 it is returned to user code. 

276 """ 

277 return response 

278 

279 def pre_set_iam_policy( 

280 self, 

281 request: iam_policy_pb2.SetIamPolicyRequest, 

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

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

284 """Pre-rpc interceptor for set_iam_policy 

285 

286 Override in a subclass to manipulate the request or metadata 

287 before they are sent to the TagKeys server. 

288 """ 

289 return request, metadata 

290 

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

292 """Post-rpc interceptor for set_iam_policy 

293 

294 Override in a subclass to manipulate the response 

295 after it is returned by the TagKeys server but before 

296 it is returned to user code. 

297 """ 

298 return response 

299 

300 def pre_test_iam_permissions( 

301 self, 

302 request: iam_policy_pb2.TestIamPermissionsRequest, 

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

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

305 """Pre-rpc interceptor for test_iam_permissions 

306 

307 Override in a subclass to manipulate the request or metadata 

308 before they are sent to the TagKeys server. 

309 """ 

310 return request, metadata 

311 

312 def post_test_iam_permissions( 

313 self, response: iam_policy_pb2.TestIamPermissionsResponse 

314 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

315 """Post-rpc interceptor for test_iam_permissions 

316 

317 Override in a subclass to manipulate the response 

318 after it is returned by the TagKeys server but before 

319 it is returned to user code. 

320 """ 

321 return response 

322 

323 def pre_update_tag_key( 

324 self, request: tag_keys.UpdateTagKeyRequest, metadata: Sequence[Tuple[str, str]] 

325 ) -> Tuple[tag_keys.UpdateTagKeyRequest, Sequence[Tuple[str, str]]]: 

326 """Pre-rpc interceptor for update_tag_key 

327 

328 Override in a subclass to manipulate the request or metadata 

329 before they are sent to the TagKeys server. 

330 """ 

331 return request, metadata 

332 

333 def post_update_tag_key( 

334 self, response: operations_pb2.Operation 

335 ) -> operations_pb2.Operation: 

336 """Post-rpc interceptor for update_tag_key 

337 

338 Override in a subclass to manipulate the response 

339 after it is returned by the TagKeys server but before 

340 it is returned to user code. 

341 """ 

342 return response 

343 

344 def pre_get_operation( 

345 self, 

346 request: operations_pb2.GetOperationRequest, 

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

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

349 """Pre-rpc interceptor for get_operation 

350 

351 Override in a subclass to manipulate the request or metadata 

352 before they are sent to the TagKeys server. 

353 """ 

354 return request, metadata 

355 

356 def post_get_operation( 

357 self, response: operations_pb2.Operation 

358 ) -> operations_pb2.Operation: 

359 """Post-rpc interceptor for get_operation 

360 

361 Override in a subclass to manipulate the response 

362 after it is returned by the TagKeys server but before 

363 it is returned to user code. 

364 """ 

365 return response 

366 

367 

368@dataclasses.dataclass 

369class TagKeysRestStub: 

370 _session: AuthorizedSession 

371 _host: str 

372 _interceptor: TagKeysRestInterceptor 

373 

374 

375class TagKeysRestTransport(TagKeysTransport): 

376 """REST backend transport for TagKeys. 

377 

378 Allow users to create and manage tag keys. 

379 

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

381 primary client can load the underlying transport implementation 

382 and call it. 

383 

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

385 

386 """ 

387 

388 def __init__( 

389 self, 

390 *, 

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

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

393 credentials_file: Optional[str] = None, 

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

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

396 quota_project_id: Optional[str] = None, 

397 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

398 always_use_jwt_access: Optional[bool] = False, 

399 url_scheme: str = "https", 

400 interceptor: Optional[TagKeysRestInterceptor] = None, 

401 api_audience: Optional[str] = None, 

402 ) -> None: 

403 """Instantiate the transport. 

404 

405 Args: 

406 host (Optional[str]): 

407 The hostname to connect to. 

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

409 authorization credentials to attach to requests. These 

410 credentials identify the application to the service; if none 

411 are specified, the client will attempt to ascertain the 

412 credentials from the environment. 

413 

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

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

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

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

418 ignored if ``channel`` is provided. 

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

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

421 if ``channel`` is provided. 

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

423 and quota. 

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

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

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

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

428 your own client library. 

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

430 be used for service account credentials. 

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

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

433 "http" can be specified. 

434 """ 

435 # Run the base constructor 

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

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

438 # credentials object 

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

440 if maybe_url_match is None: 

441 raise ValueError( 

442 f"Unexpected hostname structure: {host}" 

443 ) # pragma: NO COVER 

444 

445 url_match_items = maybe_url_match.groupdict() 

446 

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

448 

449 super().__init__( 

450 host=host, 

451 credentials=credentials, 

452 client_info=client_info, 

453 always_use_jwt_access=always_use_jwt_access, 

454 api_audience=api_audience, 

455 ) 

456 self._session = AuthorizedSession( 

457 self._credentials, default_host=self.DEFAULT_HOST 

458 ) 

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

460 if client_cert_source_for_mtls: 

461 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

462 self._interceptor = interceptor or TagKeysRestInterceptor() 

463 self._prep_wrapped_messages(client_info) 

464 

465 @property 

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

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

468 

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

470 client. 

471 """ 

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

473 if self._operations_client is None: 

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

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

476 { 

477 "method": "get", 

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

479 }, 

480 ], 

481 } 

482 

483 rest_transport = operations_v1.OperationsRestTransport( 

484 host=self._host, 

485 # use the credentials which are saved 

486 credentials=self._credentials, 

487 scopes=self._scopes, 

488 http_options=http_options, 

489 path_prefix="v3", 

490 ) 

491 

492 self._operations_client = operations_v1.AbstractOperationsClient( 

493 transport=rest_transport 

494 ) 

495 

496 # Return the client from cache. 

497 return self._operations_client 

498 

499 class _CreateTagKey(TagKeysRestStub): 

500 def __hash__(self): 

501 return hash("CreateTagKey") 

502 

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

504 

505 @classmethod 

506 def _get_unset_required_fields(cls, message_dict): 

507 return { 

508 k: v 

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

510 if k not in message_dict 

511 } 

512 

513 def __call__( 

514 self, 

515 request: tag_keys.CreateTagKeyRequest, 

516 *, 

517 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

518 timeout: Optional[float] = None, 

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

520 ) -> operations_pb2.Operation: 

521 r"""Call the create tag key method over HTTP. 

522 

523 Args: 

524 request (~.tag_keys.CreateTagKeyRequest): 

525 The request object. The request message for creating a 

526 TagKey. 

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

528 should be retried. 

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

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

531 sent along with the request as metadata. 

532 

533 Returns: 

534 ~.operations_pb2.Operation: 

535 This resource represents a 

536 long-running operation that is the 

537 result of a network API call. 

538 

539 """ 

540 

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

542 { 

543 "method": "post", 

544 "uri": "/v3/tagKeys", 

545 "body": "tag_key", 

546 }, 

547 ] 

548 request, metadata = self._interceptor.pre_create_tag_key(request, metadata) 

549 pb_request = tag_keys.CreateTagKeyRequest.pb(request) 

550 transcoded_request = path_template.transcode(http_options, pb_request) 

551 

552 # Jsonify the request body 

553 

554 body = json_format.MessageToJson( 

555 transcoded_request["body"], 

556 including_default_value_fields=False, 

557 use_integers_for_enums=True, 

558 ) 

559 uri = transcoded_request["uri"] 

560 method = transcoded_request["method"] 

561 

562 # Jsonify the query params 

563 query_params = json.loads( 

564 json_format.MessageToJson( 

565 transcoded_request["query_params"], 

566 including_default_value_fields=False, 

567 use_integers_for_enums=True, 

568 ) 

569 ) 

570 query_params.update(self._get_unset_required_fields(query_params)) 

571 

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

573 

574 # Send the request 

575 headers = dict(metadata) 

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

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

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

579 timeout=timeout, 

580 headers=headers, 

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

582 data=body, 

583 ) 

584 

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

586 # subclass. 

587 if response.status_code >= 400: 

588 raise core_exceptions.from_http_response(response) 

589 

590 # Return the response 

591 resp = operations_pb2.Operation() 

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

593 resp = self._interceptor.post_create_tag_key(resp) 

594 return resp 

595 

596 class _DeleteTagKey(TagKeysRestStub): 

597 def __hash__(self): 

598 return hash("DeleteTagKey") 

599 

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

601 

602 @classmethod 

603 def _get_unset_required_fields(cls, message_dict): 

604 return { 

605 k: v 

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

607 if k not in message_dict 

608 } 

609 

610 def __call__( 

611 self, 

612 request: tag_keys.DeleteTagKeyRequest, 

613 *, 

614 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

615 timeout: Optional[float] = None, 

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

617 ) -> operations_pb2.Operation: 

618 r"""Call the delete tag key method over HTTP. 

619 

620 Args: 

621 request (~.tag_keys.DeleteTagKeyRequest): 

622 The request object. The request message for deleting a 

623 TagKey. 

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

625 should be retried. 

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

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

628 sent along with the request as metadata. 

629 

630 Returns: 

631 ~.operations_pb2.Operation: 

632 This resource represents a 

633 long-running operation that is the 

634 result of a network API call. 

635 

636 """ 

637 

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

639 { 

640 "method": "delete", 

641 "uri": "/v3/{name=tagKeys/*}", 

642 }, 

643 ] 

644 request, metadata = self._interceptor.pre_delete_tag_key(request, metadata) 

645 pb_request = tag_keys.DeleteTagKeyRequest.pb(request) 

646 transcoded_request = path_template.transcode(http_options, pb_request) 

647 

648 uri = transcoded_request["uri"] 

649 method = transcoded_request["method"] 

650 

651 # Jsonify the query params 

652 query_params = json.loads( 

653 json_format.MessageToJson( 

654 transcoded_request["query_params"], 

655 including_default_value_fields=False, 

656 use_integers_for_enums=True, 

657 ) 

658 ) 

659 query_params.update(self._get_unset_required_fields(query_params)) 

660 

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

662 

663 # Send the request 

664 headers = dict(metadata) 

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

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

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

668 timeout=timeout, 

669 headers=headers, 

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

671 ) 

672 

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

674 # subclass. 

675 if response.status_code >= 400: 

676 raise core_exceptions.from_http_response(response) 

677 

678 # Return the response 

679 resp = operations_pb2.Operation() 

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

681 resp = self._interceptor.post_delete_tag_key(resp) 

682 return resp 

683 

684 class _GetIamPolicy(TagKeysRestStub): 

685 def __hash__(self): 

686 return hash("GetIamPolicy") 

687 

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

689 

690 @classmethod 

691 def _get_unset_required_fields(cls, message_dict): 

692 return { 

693 k: v 

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

695 if k not in message_dict 

696 } 

697 

698 def __call__( 

699 self, 

700 request: iam_policy_pb2.GetIamPolicyRequest, 

701 *, 

702 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

703 timeout: Optional[float] = None, 

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

705 ) -> policy_pb2.Policy: 

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

707 

708 Args: 

709 request (~.iam_policy_pb2.GetIamPolicyRequest): 

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

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

712 should be retried. 

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

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

715 sent along with the request as metadata. 

716 

717 Returns: 

718 ~.policy_pb2.Policy: 

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

720 specifies access controls for Google Cloud resources. 

721 

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

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

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

725 accounts, service accounts, Google groups, and domains 

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

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

728 or a user-created custom role. 

729 

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

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

732 expression that allows access to a resource only if the 

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

734 constraints based on attributes of the request, the 

735 resource, or both. To learn which resources support 

736 conditions in their IAM policies, see the `IAM 

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

738 

739 **JSON example:** 

740 

741 :: 

742 

743 { 

744 "bindings": [ 

745 { 

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

747 "members": [ 

748 "user:mike@example.com", 

749 "group:admins@example.com", 

750 "domain:google.com", 

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

752 ] 

753 }, 

754 { 

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

756 "members": [ 

757 "user:eve@example.com" 

758 ], 

759 "condition": { 

760 "title": "expirable access", 

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

762 "expression": "request.time < 

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

764 } 

765 } 

766 ], 

767 "etag": "BwWWja0YfJA=", 

768 "version": 3 

769 } 

770 

771 **YAML example:** 

772 

773 :: 

774 

775 bindings: 

776 - members: 

777 - user:mike@example.com 

778 - group:admins@example.com 

779 - domain:google.com 

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

781 role: roles/resourcemanager.organizationAdmin 

782 - members: 

783 - user:eve@example.com 

784 role: roles/resourcemanager.organizationViewer 

785 condition: 

786 title: expirable access 

787 description: Does not grant access after Sep 2020 

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

789 etag: BwWWja0YfJA= 

790 version: 3 

791 

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

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

794 

795 """ 

796 

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

798 { 

799 "method": "post", 

800 "uri": "/v3/{resource=tagKeys/*}:getIamPolicy", 

801 "body": "*", 

802 }, 

803 ] 

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

805 pb_request = request 

806 transcoded_request = path_template.transcode(http_options, pb_request) 

807 

808 # Jsonify the request body 

809 

810 body = json_format.MessageToJson( 

811 transcoded_request["body"], 

812 including_default_value_fields=False, 

813 use_integers_for_enums=True, 

814 ) 

815 uri = transcoded_request["uri"] 

816 method = transcoded_request["method"] 

817 

818 # Jsonify the query params 

819 query_params = json.loads( 

820 json_format.MessageToJson( 

821 transcoded_request["query_params"], 

822 including_default_value_fields=False, 

823 use_integers_for_enums=True, 

824 ) 

825 ) 

826 query_params.update(self._get_unset_required_fields(query_params)) 

827 

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

829 

830 # Send the request 

831 headers = dict(metadata) 

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

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

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

835 timeout=timeout, 

836 headers=headers, 

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

838 data=body, 

839 ) 

840 

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

842 # subclass. 

843 if response.status_code >= 400: 

844 raise core_exceptions.from_http_response(response) 

845 

846 # Return the response 

847 resp = policy_pb2.Policy() 

848 pb_resp = resp 

849 

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

851 resp = self._interceptor.post_get_iam_policy(resp) 

852 return resp 

853 

854 class _GetNamespacedTagKey(TagKeysRestStub): 

855 def __hash__(self): 

856 return hash("GetNamespacedTagKey") 

857 

858 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { 

859 "name": "", 

860 } 

861 

862 @classmethod 

863 def _get_unset_required_fields(cls, message_dict): 

864 return { 

865 k: v 

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

867 if k not in message_dict 

868 } 

869 

870 def __call__( 

871 self, 

872 request: tag_keys.GetNamespacedTagKeyRequest, 

873 *, 

874 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

875 timeout: Optional[float] = None, 

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

877 ) -> tag_keys.TagKey: 

878 r"""Call the get namespaced tag key method over HTTP. 

879 

880 Args: 

881 request (~.tag_keys.GetNamespacedTagKeyRequest): 

882 The request object. The request message for getting a 

883 TagKey by its namespaced name. 

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

885 should be retried. 

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

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

888 sent along with the request as metadata. 

889 

890 Returns: 

891 ~.tag_keys.TagKey: 

892 A TagKey, used to group a set of 

893 TagValues. 

894 

895 """ 

896 

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

898 { 

899 "method": "get", 

900 "uri": "/v3/tagKeys/namespaced", 

901 }, 

902 ] 

903 request, metadata = self._interceptor.pre_get_namespaced_tag_key( 

904 request, metadata 

905 ) 

906 pb_request = tag_keys.GetNamespacedTagKeyRequest.pb(request) 

907 transcoded_request = path_template.transcode(http_options, pb_request) 

908 

909 uri = transcoded_request["uri"] 

910 method = transcoded_request["method"] 

911 

912 # Jsonify the query params 

913 query_params = json.loads( 

914 json_format.MessageToJson( 

915 transcoded_request["query_params"], 

916 including_default_value_fields=False, 

917 use_integers_for_enums=True, 

918 ) 

919 ) 

920 query_params.update(self._get_unset_required_fields(query_params)) 

921 

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

923 

924 # Send the request 

925 headers = dict(metadata) 

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

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

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

929 timeout=timeout, 

930 headers=headers, 

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

932 ) 

933 

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

935 # subclass. 

936 if response.status_code >= 400: 

937 raise core_exceptions.from_http_response(response) 

938 

939 # Return the response 

940 resp = tag_keys.TagKey() 

941 pb_resp = tag_keys.TagKey.pb(resp) 

942 

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

944 resp = self._interceptor.post_get_namespaced_tag_key(resp) 

945 return resp 

946 

947 class _GetTagKey(TagKeysRestStub): 

948 def __hash__(self): 

949 return hash("GetTagKey") 

950 

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

952 

953 @classmethod 

954 def _get_unset_required_fields(cls, message_dict): 

955 return { 

956 k: v 

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

958 if k not in message_dict 

959 } 

960 

961 def __call__( 

962 self, 

963 request: tag_keys.GetTagKeyRequest, 

964 *, 

965 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

966 timeout: Optional[float] = None, 

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

968 ) -> tag_keys.TagKey: 

969 r"""Call the get tag key method over HTTP. 

970 

971 Args: 

972 request (~.tag_keys.GetTagKeyRequest): 

973 The request object. The request message for getting a 

974 TagKey. 

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

976 should be retried. 

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

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

979 sent along with the request as metadata. 

980 

981 Returns: 

982 ~.tag_keys.TagKey: 

983 A TagKey, used to group a set of 

984 TagValues. 

985 

986 """ 

987 

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

989 { 

990 "method": "get", 

991 "uri": "/v3/{name=tagKeys/*}", 

992 }, 

993 ] 

994 request, metadata = self._interceptor.pre_get_tag_key(request, metadata) 

995 pb_request = tag_keys.GetTagKeyRequest.pb(request) 

996 transcoded_request = path_template.transcode(http_options, pb_request) 

997 

998 uri = transcoded_request["uri"] 

999 method = transcoded_request["method"] 

1000 

1001 # Jsonify the query params 

1002 query_params = json.loads( 

1003 json_format.MessageToJson( 

1004 transcoded_request["query_params"], 

1005 including_default_value_fields=False, 

1006 use_integers_for_enums=True, 

1007 ) 

1008 ) 

1009 query_params.update(self._get_unset_required_fields(query_params)) 

1010 

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

1012 

1013 # Send the request 

1014 headers = dict(metadata) 

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

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

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

1018 timeout=timeout, 

1019 headers=headers, 

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

1021 ) 

1022 

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

1024 # subclass. 

1025 if response.status_code >= 400: 

1026 raise core_exceptions.from_http_response(response) 

1027 

1028 # Return the response 

1029 resp = tag_keys.TagKey() 

1030 pb_resp = tag_keys.TagKey.pb(resp) 

1031 

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

1033 resp = self._interceptor.post_get_tag_key(resp) 

1034 return resp 

1035 

1036 class _ListTagKeys(TagKeysRestStub): 

1037 def __hash__(self): 

1038 return hash("ListTagKeys") 

1039 

1040 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { 

1041 "parent": "", 

1042 } 

1043 

1044 @classmethod 

1045 def _get_unset_required_fields(cls, message_dict): 

1046 return { 

1047 k: v 

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

1049 if k not in message_dict 

1050 } 

1051 

1052 def __call__( 

1053 self, 

1054 request: tag_keys.ListTagKeysRequest, 

1055 *, 

1056 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1057 timeout: Optional[float] = None, 

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

1059 ) -> tag_keys.ListTagKeysResponse: 

1060 r"""Call the list tag keys method over HTTP. 

1061 

1062 Args: 

1063 request (~.tag_keys.ListTagKeysRequest): 

1064 The request object. The request message for listing all 

1065 TagKeys under a parent resource. 

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

1067 should be retried. 

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

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

1070 sent along with the request as metadata. 

1071 

1072 Returns: 

1073 ~.tag_keys.ListTagKeysResponse: 

1074 The ListTagKeys response message. 

1075 """ 

1076 

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

1078 { 

1079 "method": "get", 

1080 "uri": "/v3/tagKeys", 

1081 }, 

1082 ] 

1083 request, metadata = self._interceptor.pre_list_tag_keys(request, metadata) 

1084 pb_request = tag_keys.ListTagKeysRequest.pb(request) 

1085 transcoded_request = path_template.transcode(http_options, pb_request) 

1086 

1087 uri = transcoded_request["uri"] 

1088 method = transcoded_request["method"] 

1089 

1090 # Jsonify the query params 

1091 query_params = json.loads( 

1092 json_format.MessageToJson( 

1093 transcoded_request["query_params"], 

1094 including_default_value_fields=False, 

1095 use_integers_for_enums=True, 

1096 ) 

1097 ) 

1098 query_params.update(self._get_unset_required_fields(query_params)) 

1099 

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

1101 

1102 # Send the request 

1103 headers = dict(metadata) 

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

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

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

1107 timeout=timeout, 

1108 headers=headers, 

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

1110 ) 

1111 

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

1113 # subclass. 

1114 if response.status_code >= 400: 

1115 raise core_exceptions.from_http_response(response) 

1116 

1117 # Return the response 

1118 resp = tag_keys.ListTagKeysResponse() 

1119 pb_resp = tag_keys.ListTagKeysResponse.pb(resp) 

1120 

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

1122 resp = self._interceptor.post_list_tag_keys(resp) 

1123 return resp 

1124 

1125 class _SetIamPolicy(TagKeysRestStub): 

1126 def __hash__(self): 

1127 return hash("SetIamPolicy") 

1128 

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

1130 

1131 @classmethod 

1132 def _get_unset_required_fields(cls, message_dict): 

1133 return { 

1134 k: v 

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

1136 if k not in message_dict 

1137 } 

1138 

1139 def __call__( 

1140 self, 

1141 request: iam_policy_pb2.SetIamPolicyRequest, 

1142 *, 

1143 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1144 timeout: Optional[float] = None, 

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

1146 ) -> policy_pb2.Policy: 

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

1148 

1149 Args: 

1150 request (~.iam_policy_pb2.SetIamPolicyRequest): 

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

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

1153 should be retried. 

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

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

1156 sent along with the request as metadata. 

1157 

1158 Returns: 

1159 ~.policy_pb2.Policy: 

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

1161 specifies access controls for Google Cloud resources. 

1162 

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

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

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

1166 accounts, service accounts, Google groups, and domains 

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

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

1169 or a user-created custom role. 

1170 

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

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

1173 expression that allows access to a resource only if the 

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

1175 constraints based on attributes of the request, the 

1176 resource, or both. To learn which resources support 

1177 conditions in their IAM policies, see the `IAM 

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

1179 

1180 **JSON example:** 

1181 

1182 :: 

1183 

1184 { 

1185 "bindings": [ 

1186 { 

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

1188 "members": [ 

1189 "user:mike@example.com", 

1190 "group:admins@example.com", 

1191 "domain:google.com", 

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

1193 ] 

1194 }, 

1195 { 

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

1197 "members": [ 

1198 "user:eve@example.com" 

1199 ], 

1200 "condition": { 

1201 "title": "expirable access", 

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

1203 "expression": "request.time < 

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

1205 } 

1206 } 

1207 ], 

1208 "etag": "BwWWja0YfJA=", 

1209 "version": 3 

1210 } 

1211 

1212 **YAML example:** 

1213 

1214 :: 

1215 

1216 bindings: 

1217 - members: 

1218 - user:mike@example.com 

1219 - group:admins@example.com 

1220 - domain:google.com 

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

1222 role: roles/resourcemanager.organizationAdmin 

1223 - members: 

1224 - user:eve@example.com 

1225 role: roles/resourcemanager.organizationViewer 

1226 condition: 

1227 title: expirable access 

1228 description: Does not grant access after Sep 2020 

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

1230 etag: BwWWja0YfJA= 

1231 version: 3 

1232 

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

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

1235 

1236 """ 

1237 

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

1239 { 

1240 "method": "post", 

1241 "uri": "/v3/{resource=tagKeys/*}:setIamPolicy", 

1242 "body": "*", 

1243 }, 

1244 ] 

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

1246 pb_request = request 

1247 transcoded_request = path_template.transcode(http_options, pb_request) 

1248 

1249 # Jsonify the request body 

1250 

1251 body = json_format.MessageToJson( 

1252 transcoded_request["body"], 

1253 including_default_value_fields=False, 

1254 use_integers_for_enums=True, 

1255 ) 

1256 uri = transcoded_request["uri"] 

1257 method = transcoded_request["method"] 

1258 

1259 # Jsonify the query params 

1260 query_params = json.loads( 

1261 json_format.MessageToJson( 

1262 transcoded_request["query_params"], 

1263 including_default_value_fields=False, 

1264 use_integers_for_enums=True, 

1265 ) 

1266 ) 

1267 query_params.update(self._get_unset_required_fields(query_params)) 

1268 

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

1270 

1271 # Send the request 

1272 headers = dict(metadata) 

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

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

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

1276 timeout=timeout, 

1277 headers=headers, 

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

1279 data=body, 

1280 ) 

1281 

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

1283 # subclass. 

1284 if response.status_code >= 400: 

1285 raise core_exceptions.from_http_response(response) 

1286 

1287 # Return the response 

1288 resp = policy_pb2.Policy() 

1289 pb_resp = resp 

1290 

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

1292 resp = self._interceptor.post_set_iam_policy(resp) 

1293 return resp 

1294 

1295 class _TestIamPermissions(TagKeysRestStub): 

1296 def __hash__(self): 

1297 return hash("TestIamPermissions") 

1298 

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

1300 

1301 @classmethod 

1302 def _get_unset_required_fields(cls, message_dict): 

1303 return { 

1304 k: v 

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

1306 if k not in message_dict 

1307 } 

1308 

1309 def __call__( 

1310 self, 

1311 request: iam_policy_pb2.TestIamPermissionsRequest, 

1312 *, 

1313 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1314 timeout: Optional[float] = None, 

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

1316 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

1318 

1319 Args: 

1320 request (~.iam_policy_pb2.TestIamPermissionsRequest): 

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

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

1323 should be retried. 

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

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

1326 sent along with the request as metadata. 

1327 

1328 Returns: 

1329 ~.iam_policy_pb2.TestIamPermissionsResponse: 

1330 Response message for ``TestIamPermissions`` method. 

1331 """ 

1332 

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

1334 { 

1335 "method": "post", 

1336 "uri": "/v3/{resource=tagKeys/*}:testIamPermissions", 

1337 "body": "*", 

1338 }, 

1339 ] 

1340 request, metadata = self._interceptor.pre_test_iam_permissions( 

1341 request, metadata 

1342 ) 

1343 pb_request = request 

1344 transcoded_request = path_template.transcode(http_options, pb_request) 

1345 

1346 # Jsonify the request body 

1347 

1348 body = json_format.MessageToJson( 

1349 transcoded_request["body"], 

1350 including_default_value_fields=False, 

1351 use_integers_for_enums=True, 

1352 ) 

1353 uri = transcoded_request["uri"] 

1354 method = transcoded_request["method"] 

1355 

1356 # Jsonify the query params 

1357 query_params = json.loads( 

1358 json_format.MessageToJson( 

1359 transcoded_request["query_params"], 

1360 including_default_value_fields=False, 

1361 use_integers_for_enums=True, 

1362 ) 

1363 ) 

1364 query_params.update(self._get_unset_required_fields(query_params)) 

1365 

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

1367 

1368 # Send the request 

1369 headers = dict(metadata) 

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

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

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

1373 timeout=timeout, 

1374 headers=headers, 

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

1376 data=body, 

1377 ) 

1378 

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

1380 # subclass. 

1381 if response.status_code >= 400: 

1382 raise core_exceptions.from_http_response(response) 

1383 

1384 # Return the response 

1385 resp = iam_policy_pb2.TestIamPermissionsResponse() 

1386 pb_resp = resp 

1387 

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

1389 resp = self._interceptor.post_test_iam_permissions(resp) 

1390 return resp 

1391 

1392 class _UpdateTagKey(TagKeysRestStub): 

1393 def __hash__(self): 

1394 return hash("UpdateTagKey") 

1395 

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

1397 

1398 @classmethod 

1399 def _get_unset_required_fields(cls, message_dict): 

1400 return { 

1401 k: v 

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

1403 if k not in message_dict 

1404 } 

1405 

1406 def __call__( 

1407 self, 

1408 request: tag_keys.UpdateTagKeyRequest, 

1409 *, 

1410 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1411 timeout: Optional[float] = None, 

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

1413 ) -> operations_pb2.Operation: 

1414 r"""Call the update tag key method over HTTP. 

1415 

1416 Args: 

1417 request (~.tag_keys.UpdateTagKeyRequest): 

1418 The request object. The request message for updating a 

1419 TagKey. 

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

1421 should be retried. 

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

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

1424 sent along with the request as metadata. 

1425 

1426 Returns: 

1427 ~.operations_pb2.Operation: 

1428 This resource represents a 

1429 long-running operation that is the 

1430 result of a network API call. 

1431 

1432 """ 

1433 

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

1435 { 

1436 "method": "patch", 

1437 "uri": "/v3/{tag_key.name=tagKeys/*}", 

1438 "body": "tag_key", 

1439 }, 

1440 ] 

1441 request, metadata = self._interceptor.pre_update_tag_key(request, metadata) 

1442 pb_request = tag_keys.UpdateTagKeyRequest.pb(request) 

1443 transcoded_request = path_template.transcode(http_options, pb_request) 

1444 

1445 # Jsonify the request body 

1446 

1447 body = json_format.MessageToJson( 

1448 transcoded_request["body"], 

1449 including_default_value_fields=False, 

1450 use_integers_for_enums=True, 

1451 ) 

1452 uri = transcoded_request["uri"] 

1453 method = transcoded_request["method"] 

1454 

1455 # Jsonify the query params 

1456 query_params = json.loads( 

1457 json_format.MessageToJson( 

1458 transcoded_request["query_params"], 

1459 including_default_value_fields=False, 

1460 use_integers_for_enums=True, 

1461 ) 

1462 ) 

1463 query_params.update(self._get_unset_required_fields(query_params)) 

1464 

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

1466 

1467 # Send the request 

1468 headers = dict(metadata) 

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

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

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

1472 timeout=timeout, 

1473 headers=headers, 

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

1475 data=body, 

1476 ) 

1477 

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

1479 # subclass. 

1480 if response.status_code >= 400: 

1481 raise core_exceptions.from_http_response(response) 

1482 

1483 # Return the response 

1484 resp = operations_pb2.Operation() 

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

1486 resp = self._interceptor.post_update_tag_key(resp) 

1487 return resp 

1488 

1489 @property 

1490 def create_tag_key( 

1491 self, 

1492 ) -> Callable[[tag_keys.CreateTagKeyRequest], operations_pb2.Operation]: 

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

1494 # In C++ this would require a dynamic_cast 

1495 return self._CreateTagKey(self._session, self._host, self._interceptor) # type: ignore 

1496 

1497 @property 

1498 def delete_tag_key( 

1499 self, 

1500 ) -> Callable[[tag_keys.DeleteTagKeyRequest], operations_pb2.Operation]: 

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

1502 # In C++ this would require a dynamic_cast 

1503 return self._DeleteTagKey(self._session, self._host, self._interceptor) # type: ignore 

1504 

1505 @property 

1506 def get_iam_policy( 

1507 self, 

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

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

1510 # In C++ this would require a dynamic_cast 

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

1512 

1513 @property 

1514 def get_namespaced_tag_key( 

1515 self, 

1516 ) -> Callable[[tag_keys.GetNamespacedTagKeyRequest], tag_keys.TagKey]: 

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

1518 # In C++ this would require a dynamic_cast 

1519 return self._GetNamespacedTagKey(self._session, self._host, self._interceptor) # type: ignore 

1520 

1521 @property 

1522 def get_tag_key(self) -> Callable[[tag_keys.GetTagKeyRequest], tag_keys.TagKey]: 

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

1524 # In C++ this would require a dynamic_cast 

1525 return self._GetTagKey(self._session, self._host, self._interceptor) # type: ignore 

1526 

1527 @property 

1528 def list_tag_keys( 

1529 self, 

1530 ) -> Callable[[tag_keys.ListTagKeysRequest], tag_keys.ListTagKeysResponse]: 

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

1532 # In C++ this would require a dynamic_cast 

1533 return self._ListTagKeys(self._session, self._host, self._interceptor) # type: ignore 

1534 

1535 @property 

1536 def set_iam_policy( 

1537 self, 

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

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

1540 # In C++ this would require a dynamic_cast 

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

1542 

1543 @property 

1544 def test_iam_permissions( 

1545 self, 

1546 ) -> Callable[ 

1547 [iam_policy_pb2.TestIamPermissionsRequest], 

1548 iam_policy_pb2.TestIamPermissionsResponse, 

1549 ]: 

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

1551 # In C++ this would require a dynamic_cast 

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

1553 

1554 @property 

1555 def update_tag_key( 

1556 self, 

1557 ) -> Callable[[tag_keys.UpdateTagKeyRequest], operations_pb2.Operation]: 

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

1559 # In C++ this would require a dynamic_cast 

1560 return self._UpdateTagKey(self._session, self._host, self._interceptor) # type: ignore 

1561 

1562 @property 

1563 def get_operation(self): 

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

1565 

1566 class _GetOperation(TagKeysRestStub): 

1567 def __call__( 

1568 self, 

1569 request: operations_pb2.GetOperationRequest, 

1570 *, 

1571 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1572 timeout: Optional[float] = None, 

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

1574 ) -> operations_pb2.Operation: 

1575 

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

1577 

1578 Args: 

1579 request (operations_pb2.GetOperationRequest): 

1580 The request object for GetOperation method. 

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

1582 should be retried. 

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

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

1585 sent along with the request as metadata. 

1586 

1587 Returns: 

1588 operations_pb2.Operation: Response from GetOperation method. 

1589 """ 

1590 

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

1592 { 

1593 "method": "get", 

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

1595 }, 

1596 ] 

1597 

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

1599 request_kwargs = json_format.MessageToDict(request) 

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

1601 

1602 uri = transcoded_request["uri"] 

1603 method = transcoded_request["method"] 

1604 

1605 # Jsonify the query params 

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

1607 

1608 # Send the request 

1609 headers = dict(metadata) 

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

1611 

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

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

1614 timeout=timeout, 

1615 headers=headers, 

1616 params=rest_helpers.flatten_query_params(query_params), 

1617 ) 

1618 

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

1620 # subclass. 

1621 if response.status_code >= 400: 

1622 raise core_exceptions.from_http_response(response) 

1623 

1624 resp = operations_pb2.Operation() 

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

1626 resp = self._interceptor.post_get_operation(resp) 

1627 return resp 

1628 

1629 @property 

1630 def kind(self) -> str: 

1631 return "rest" 

1632 

1633 def close(self): 

1634 self._session.close() 

1635 

1636 

1637__all__ = ("TagKeysRestTransport",)