Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/resourcemanager_v3/services/tag_values/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_values 

51 

52from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

53from .base import TagValuesTransport 

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

63 """Interceptor for TagValues. 

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

74 

75 .. code-block:: python 

76 class MyCustomTagValuesInterceptor(TagValuesRestInterceptor): 

77 def pre_create_tag_value(self, request, metadata): 

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

79 return request, metadata 

80 

81 def post_create_tag_value(self, response): 

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

83 return response 

84 

85 def pre_delete_tag_value(self, request, metadata): 

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

87 return request, metadata 

88 

89 def post_delete_tag_value(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_value(self, request, metadata): 

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

103 return request, metadata 

104 

105 def post_get_namespaced_tag_value(self, response): 

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

107 return response 

108 

109 def pre_get_tag_value(self, request, metadata): 

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

111 return request, metadata 

112 

113 def post_get_tag_value(self, response): 

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

115 return response 

116 

117 def pre_list_tag_values(self, request, metadata): 

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

119 return request, metadata 

120 

121 def post_list_tag_values(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_value(self, request, metadata): 

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

143 return request, metadata 

144 

145 def post_update_tag_value(self, response): 

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

147 return response 

148 

149 transport = TagValuesRestTransport(interceptor=MyCustomTagValuesInterceptor()) 

150 client = TagValuesClient(transport=transport) 

151 

152 

153 """ 

154 

155 def pre_create_tag_value( 

156 self, 

157 request: tag_values.CreateTagValueRequest, 

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

159 ) -> Tuple[tag_values.CreateTagValueRequest, Sequence[Tuple[str, str]]]: 

160 """Pre-rpc interceptor for create_tag_value 

161 

162 Override in a subclass to manipulate the request or metadata 

163 before they are sent to the TagValues server. 

164 """ 

165 return request, metadata 

166 

167 def post_create_tag_value( 

168 self, response: operations_pb2.Operation 

169 ) -> operations_pb2.Operation: 

170 """Post-rpc interceptor for create_tag_value 

171 

172 Override in a subclass to manipulate the response 

173 after it is returned by the TagValues server but before 

174 it is returned to user code. 

175 """ 

176 return response 

177 

178 def pre_delete_tag_value( 

179 self, 

180 request: tag_values.DeleteTagValueRequest, 

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

182 ) -> Tuple[tag_values.DeleteTagValueRequest, Sequence[Tuple[str, str]]]: 

183 """Pre-rpc interceptor for delete_tag_value 

184 

185 Override in a subclass to manipulate the request or metadata 

186 before they are sent to the TagValues server. 

187 """ 

188 return request, metadata 

189 

190 def post_delete_tag_value( 

191 self, response: operations_pb2.Operation 

192 ) -> operations_pb2.Operation: 

193 """Post-rpc interceptor for delete_tag_value 

194 

195 Override in a subclass to manipulate the response 

196 after it is returned by the TagValues server but before 

197 it is returned to user code. 

198 """ 

199 return response 

200 

201 def pre_get_iam_policy( 

202 self, 

203 request: iam_policy_pb2.GetIamPolicyRequest, 

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

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

206 """Pre-rpc interceptor for get_iam_policy 

207 

208 Override in a subclass to manipulate the request or metadata 

209 before they are sent to the TagValues server. 

210 """ 

211 return request, metadata 

212 

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

214 """Post-rpc interceptor for get_iam_policy 

215 

216 Override in a subclass to manipulate the response 

217 after it is returned by the TagValues server but before 

218 it is returned to user code. 

219 """ 

220 return response 

221 

222 def pre_get_namespaced_tag_value( 

223 self, 

224 request: tag_values.GetNamespacedTagValueRequest, 

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

226 ) -> Tuple[tag_values.GetNamespacedTagValueRequest, Sequence[Tuple[str, str]]]: 

227 """Pre-rpc interceptor for get_namespaced_tag_value 

228 

229 Override in a subclass to manipulate the request or metadata 

230 before they are sent to the TagValues server. 

231 """ 

232 return request, metadata 

233 

234 def post_get_namespaced_tag_value( 

235 self, response: tag_values.TagValue 

236 ) -> tag_values.TagValue: 

237 """Post-rpc interceptor for get_namespaced_tag_value 

238 

239 Override in a subclass to manipulate the response 

240 after it is returned by the TagValues server but before 

241 it is returned to user code. 

242 """ 

243 return response 

244 

245 def pre_get_tag_value( 

246 self, 

247 request: tag_values.GetTagValueRequest, 

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

249 ) -> Tuple[tag_values.GetTagValueRequest, Sequence[Tuple[str, str]]]: 

250 """Pre-rpc interceptor for get_tag_value 

251 

252 Override in a subclass to manipulate the request or metadata 

253 before they are sent to the TagValues server. 

254 """ 

255 return request, metadata 

256 

257 def post_get_tag_value(self, response: tag_values.TagValue) -> tag_values.TagValue: 

258 """Post-rpc interceptor for get_tag_value 

259 

260 Override in a subclass to manipulate the response 

261 after it is returned by the TagValues server but before 

262 it is returned to user code. 

263 """ 

264 return response 

265 

266 def pre_list_tag_values( 

267 self, 

268 request: tag_values.ListTagValuesRequest, 

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

270 ) -> Tuple[tag_values.ListTagValuesRequest, Sequence[Tuple[str, str]]]: 

271 """Pre-rpc interceptor for list_tag_values 

272 

273 Override in a subclass to manipulate the request or metadata 

274 before they are sent to the TagValues server. 

275 """ 

276 return request, metadata 

277 

278 def post_list_tag_values( 

279 self, response: tag_values.ListTagValuesResponse 

280 ) -> tag_values.ListTagValuesResponse: 

281 """Post-rpc interceptor for list_tag_values 

282 

283 Override in a subclass to manipulate the response 

284 after it is returned by the TagValues server but before 

285 it is returned to user code. 

286 """ 

287 return response 

288 

289 def pre_set_iam_policy( 

290 self, 

291 request: iam_policy_pb2.SetIamPolicyRequest, 

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

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

294 """Pre-rpc interceptor for set_iam_policy 

295 

296 Override in a subclass to manipulate the request or metadata 

297 before they are sent to the TagValues server. 

298 """ 

299 return request, metadata 

300 

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

302 """Post-rpc interceptor for set_iam_policy 

303 

304 Override in a subclass to manipulate the response 

305 after it is returned by the TagValues server but before 

306 it is returned to user code. 

307 """ 

308 return response 

309 

310 def pre_test_iam_permissions( 

311 self, 

312 request: iam_policy_pb2.TestIamPermissionsRequest, 

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

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

315 """Pre-rpc interceptor for test_iam_permissions 

316 

317 Override in a subclass to manipulate the request or metadata 

318 before they are sent to the TagValues server. 

319 """ 

320 return request, metadata 

321 

322 def post_test_iam_permissions( 

323 self, response: iam_policy_pb2.TestIamPermissionsResponse 

324 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

325 """Post-rpc interceptor for test_iam_permissions 

326 

327 Override in a subclass to manipulate the response 

328 after it is returned by the TagValues server but before 

329 it is returned to user code. 

330 """ 

331 return response 

332 

333 def pre_update_tag_value( 

334 self, 

335 request: tag_values.UpdateTagValueRequest, 

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

337 ) -> Tuple[tag_values.UpdateTagValueRequest, Sequence[Tuple[str, str]]]: 

338 """Pre-rpc interceptor for update_tag_value 

339 

340 Override in a subclass to manipulate the request or metadata 

341 before they are sent to the TagValues server. 

342 """ 

343 return request, metadata 

344 

345 def post_update_tag_value( 

346 self, response: operations_pb2.Operation 

347 ) -> operations_pb2.Operation: 

348 """Post-rpc interceptor for update_tag_value 

349 

350 Override in a subclass to manipulate the response 

351 after it is returned by the TagValues server but before 

352 it is returned to user code. 

353 """ 

354 return response 

355 

356 def pre_get_operation( 

357 self, 

358 request: operations_pb2.GetOperationRequest, 

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

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

361 """Pre-rpc interceptor for get_operation 

362 

363 Override in a subclass to manipulate the request or metadata 

364 before they are sent to the TagValues server. 

365 """ 

366 return request, metadata 

367 

368 def post_get_operation( 

369 self, response: operations_pb2.Operation 

370 ) -> operations_pb2.Operation: 

371 """Post-rpc interceptor for get_operation 

372 

373 Override in a subclass to manipulate the response 

374 after it is returned by the TagValues server but before 

375 it is returned to user code. 

376 """ 

377 return response 

378 

379 

380@dataclasses.dataclass 

381class TagValuesRestStub: 

382 _session: AuthorizedSession 

383 _host: str 

384 _interceptor: TagValuesRestInterceptor 

385 

386 

387class TagValuesRestTransport(TagValuesTransport): 

388 """REST backend transport for TagValues. 

389 

390 Allow users to create and manage tag values. 

391 

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

393 primary client can load the underlying transport implementation 

394 and call it. 

395 

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

397 

398 """ 

399 

400 def __init__( 

401 self, 

402 *, 

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

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

405 credentials_file: Optional[str] = None, 

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

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

408 quota_project_id: Optional[str] = None, 

409 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

410 always_use_jwt_access: Optional[bool] = False, 

411 url_scheme: str = "https", 

412 interceptor: Optional[TagValuesRestInterceptor] = None, 

413 api_audience: Optional[str] = None, 

414 ) -> None: 

415 """Instantiate the transport. 

416 

417 Args: 

418 host (Optional[str]): 

419 The hostname to connect to. 

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

421 authorization credentials to attach to requests. These 

422 credentials identify the application to the service; if none 

423 are specified, the client will attempt to ascertain the 

424 credentials from the environment. 

425 

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

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

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

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

430 ignored if ``channel`` is provided. 

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

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

433 if ``channel`` is provided. 

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

435 and quota. 

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

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

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

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

440 your own client library. 

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

442 be used for service account credentials. 

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

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

445 "http" can be specified. 

446 """ 

447 # Run the base constructor 

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

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

450 # credentials object 

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

452 if maybe_url_match is None: 

453 raise ValueError( 

454 f"Unexpected hostname structure: {host}" 

455 ) # pragma: NO COVER 

456 

457 url_match_items = maybe_url_match.groupdict() 

458 

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

460 

461 super().__init__( 

462 host=host, 

463 credentials=credentials, 

464 client_info=client_info, 

465 always_use_jwt_access=always_use_jwt_access, 

466 api_audience=api_audience, 

467 ) 

468 self._session = AuthorizedSession( 

469 self._credentials, default_host=self.DEFAULT_HOST 

470 ) 

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

472 if client_cert_source_for_mtls: 

473 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

474 self._interceptor = interceptor or TagValuesRestInterceptor() 

475 self._prep_wrapped_messages(client_info) 

476 

477 @property 

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

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

480 

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

482 client. 

483 """ 

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

485 if self._operations_client is None: 

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

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

488 { 

489 "method": "get", 

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

491 }, 

492 ], 

493 } 

494 

495 rest_transport = operations_v1.OperationsRestTransport( 

496 host=self._host, 

497 # use the credentials which are saved 

498 credentials=self._credentials, 

499 scopes=self._scopes, 

500 http_options=http_options, 

501 path_prefix="v3", 

502 ) 

503 

504 self._operations_client = operations_v1.AbstractOperationsClient( 

505 transport=rest_transport 

506 ) 

507 

508 # Return the client from cache. 

509 return self._operations_client 

510 

511 class _CreateTagValue(TagValuesRestStub): 

512 def __hash__(self): 

513 return hash("CreateTagValue") 

514 

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

516 

517 @classmethod 

518 def _get_unset_required_fields(cls, message_dict): 

519 return { 

520 k: v 

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

522 if k not in message_dict 

523 } 

524 

525 def __call__( 

526 self, 

527 request: tag_values.CreateTagValueRequest, 

528 *, 

529 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

530 timeout: Optional[float] = None, 

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

532 ) -> operations_pb2.Operation: 

533 r"""Call the create tag value method over HTTP. 

534 

535 Args: 

536 request (~.tag_values.CreateTagValueRequest): 

537 The request object. The request message for creating a 

538 TagValue. 

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

540 should be retried. 

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

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

543 sent along with the request as metadata. 

544 

545 Returns: 

546 ~.operations_pb2.Operation: 

547 This resource represents a 

548 long-running operation that is the 

549 result of a network API call. 

550 

551 """ 

552 

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

554 { 

555 "method": "post", 

556 "uri": "/v3/tagValues", 

557 "body": "tag_value", 

558 }, 

559 ] 

560 request, metadata = self._interceptor.pre_create_tag_value( 

561 request, metadata 

562 ) 

563 pb_request = tag_values.CreateTagValueRequest.pb(request) 

564 transcoded_request = path_template.transcode(http_options, pb_request) 

565 

566 # Jsonify the request body 

567 

568 body = json_format.MessageToJson( 

569 transcoded_request["body"], 

570 including_default_value_fields=False, 

571 use_integers_for_enums=True, 

572 ) 

573 uri = transcoded_request["uri"] 

574 method = transcoded_request["method"] 

575 

576 # Jsonify the query params 

577 query_params = json.loads( 

578 json_format.MessageToJson( 

579 transcoded_request["query_params"], 

580 including_default_value_fields=False, 

581 use_integers_for_enums=True, 

582 ) 

583 ) 

584 query_params.update(self._get_unset_required_fields(query_params)) 

585 

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

587 

588 # Send the request 

589 headers = dict(metadata) 

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

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

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

593 timeout=timeout, 

594 headers=headers, 

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

596 data=body, 

597 ) 

598 

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

600 # subclass. 

601 if response.status_code >= 400: 

602 raise core_exceptions.from_http_response(response) 

603 

604 # Return the response 

605 resp = operations_pb2.Operation() 

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

607 resp = self._interceptor.post_create_tag_value(resp) 

608 return resp 

609 

610 class _DeleteTagValue(TagValuesRestStub): 

611 def __hash__(self): 

612 return hash("DeleteTagValue") 

613 

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

615 

616 @classmethod 

617 def _get_unset_required_fields(cls, message_dict): 

618 return { 

619 k: v 

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

621 if k not in message_dict 

622 } 

623 

624 def __call__( 

625 self, 

626 request: tag_values.DeleteTagValueRequest, 

627 *, 

628 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

629 timeout: Optional[float] = None, 

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

631 ) -> operations_pb2.Operation: 

632 r"""Call the delete tag value method over HTTP. 

633 

634 Args: 

635 request (~.tag_values.DeleteTagValueRequest): 

636 The request object. The request message for deleting a 

637 TagValue. 

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

639 should be retried. 

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

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

642 sent along with the request as metadata. 

643 

644 Returns: 

645 ~.operations_pb2.Operation: 

646 This resource represents a 

647 long-running operation that is the 

648 result of a network API call. 

649 

650 """ 

651 

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

653 { 

654 "method": "delete", 

655 "uri": "/v3/{name=tagValues/*}", 

656 }, 

657 ] 

658 request, metadata = self._interceptor.pre_delete_tag_value( 

659 request, metadata 

660 ) 

661 pb_request = tag_values.DeleteTagValueRequest.pb(request) 

662 transcoded_request = path_template.transcode(http_options, pb_request) 

663 

664 uri = transcoded_request["uri"] 

665 method = transcoded_request["method"] 

666 

667 # Jsonify the query params 

668 query_params = json.loads( 

669 json_format.MessageToJson( 

670 transcoded_request["query_params"], 

671 including_default_value_fields=False, 

672 use_integers_for_enums=True, 

673 ) 

674 ) 

675 query_params.update(self._get_unset_required_fields(query_params)) 

676 

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

678 

679 # Send the request 

680 headers = dict(metadata) 

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

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

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

684 timeout=timeout, 

685 headers=headers, 

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

687 ) 

688 

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

690 # subclass. 

691 if response.status_code >= 400: 

692 raise core_exceptions.from_http_response(response) 

693 

694 # Return the response 

695 resp = operations_pb2.Operation() 

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

697 resp = self._interceptor.post_delete_tag_value(resp) 

698 return resp 

699 

700 class _GetIamPolicy(TagValuesRestStub): 

701 def __hash__(self): 

702 return hash("GetIamPolicy") 

703 

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

705 

706 @classmethod 

707 def _get_unset_required_fields(cls, message_dict): 

708 return { 

709 k: v 

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

711 if k not in message_dict 

712 } 

713 

714 def __call__( 

715 self, 

716 request: iam_policy_pb2.GetIamPolicyRequest, 

717 *, 

718 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

719 timeout: Optional[float] = None, 

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

721 ) -> policy_pb2.Policy: 

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

723 

724 Args: 

725 request (~.iam_policy_pb2.GetIamPolicyRequest): 

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

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

728 should be retried. 

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

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

731 sent along with the request as metadata. 

732 

733 Returns: 

734 ~.policy_pb2.Policy: 

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

736 specifies access controls for Google Cloud resources. 

737 

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

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

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

741 accounts, service accounts, Google groups, and domains 

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

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

744 or a user-created custom role. 

745 

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

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

748 expression that allows access to a resource only if the 

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

750 constraints based on attributes of the request, the 

751 resource, or both. To learn which resources support 

752 conditions in their IAM policies, see the `IAM 

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

754 

755 **JSON example:** 

756 

757 :: 

758 

759 { 

760 "bindings": [ 

761 { 

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

763 "members": [ 

764 "user:mike@example.com", 

765 "group:admins@example.com", 

766 "domain:google.com", 

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

768 ] 

769 }, 

770 { 

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

772 "members": [ 

773 "user:eve@example.com" 

774 ], 

775 "condition": { 

776 "title": "expirable access", 

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

778 "expression": "request.time < 

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

780 } 

781 } 

782 ], 

783 "etag": "BwWWja0YfJA=", 

784 "version": 3 

785 } 

786 

787 **YAML example:** 

788 

789 :: 

790 

791 bindings: 

792 - members: 

793 - user:mike@example.com 

794 - group:admins@example.com 

795 - domain:google.com 

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

797 role: roles/resourcemanager.organizationAdmin 

798 - members: 

799 - user:eve@example.com 

800 role: roles/resourcemanager.organizationViewer 

801 condition: 

802 title: expirable access 

803 description: Does not grant access after Sep 2020 

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

805 etag: BwWWja0YfJA= 

806 version: 3 

807 

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

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

810 

811 """ 

812 

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

814 { 

815 "method": "post", 

816 "uri": "/v3/{resource=tagValues/*}:getIamPolicy", 

817 "body": "*", 

818 }, 

819 ] 

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

821 pb_request = request 

822 transcoded_request = path_template.transcode(http_options, pb_request) 

823 

824 # Jsonify the request body 

825 

826 body = json_format.MessageToJson( 

827 transcoded_request["body"], 

828 including_default_value_fields=False, 

829 use_integers_for_enums=True, 

830 ) 

831 uri = transcoded_request["uri"] 

832 method = transcoded_request["method"] 

833 

834 # Jsonify the query params 

835 query_params = json.loads( 

836 json_format.MessageToJson( 

837 transcoded_request["query_params"], 

838 including_default_value_fields=False, 

839 use_integers_for_enums=True, 

840 ) 

841 ) 

842 query_params.update(self._get_unset_required_fields(query_params)) 

843 

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

845 

846 # Send the request 

847 headers = dict(metadata) 

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

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

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

851 timeout=timeout, 

852 headers=headers, 

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

854 data=body, 

855 ) 

856 

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

858 # subclass. 

859 if response.status_code >= 400: 

860 raise core_exceptions.from_http_response(response) 

861 

862 # Return the response 

863 resp = policy_pb2.Policy() 

864 pb_resp = resp 

865 

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

867 resp = self._interceptor.post_get_iam_policy(resp) 

868 return resp 

869 

870 class _GetNamespacedTagValue(TagValuesRestStub): 

871 def __hash__(self): 

872 return hash("GetNamespacedTagValue") 

873 

874 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { 

875 "name": "", 

876 } 

877 

878 @classmethod 

879 def _get_unset_required_fields(cls, message_dict): 

880 return { 

881 k: v 

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

883 if k not in message_dict 

884 } 

885 

886 def __call__( 

887 self, 

888 request: tag_values.GetNamespacedTagValueRequest, 

889 *, 

890 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

891 timeout: Optional[float] = None, 

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

893 ) -> tag_values.TagValue: 

894 r"""Call the get namespaced tag value method over HTTP. 

895 

896 Args: 

897 request (~.tag_values.GetNamespacedTagValueRequest): 

898 The request object. The request message for getting a 

899 TagValue by its namespaced name. 

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

901 should be retried. 

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

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

904 sent along with the request as metadata. 

905 

906 Returns: 

907 ~.tag_values.TagValue: 

908 A TagValue is a child of a particular 

909 TagKey. This is used to group cloud 

910 resources for the purpose of controlling 

911 them using policies. 

912 

913 """ 

914 

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

916 { 

917 "method": "get", 

918 "uri": "/v3/tagValues/namespaced", 

919 }, 

920 ] 

921 request, metadata = self._interceptor.pre_get_namespaced_tag_value( 

922 request, metadata 

923 ) 

924 pb_request = tag_values.GetNamespacedTagValueRequest.pb(request) 

925 transcoded_request = path_template.transcode(http_options, pb_request) 

926 

927 uri = transcoded_request["uri"] 

928 method = transcoded_request["method"] 

929 

930 # Jsonify the query params 

931 query_params = json.loads( 

932 json_format.MessageToJson( 

933 transcoded_request["query_params"], 

934 including_default_value_fields=False, 

935 use_integers_for_enums=True, 

936 ) 

937 ) 

938 query_params.update(self._get_unset_required_fields(query_params)) 

939 

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

941 

942 # Send the request 

943 headers = dict(metadata) 

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

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

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

947 timeout=timeout, 

948 headers=headers, 

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

950 ) 

951 

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

953 # subclass. 

954 if response.status_code >= 400: 

955 raise core_exceptions.from_http_response(response) 

956 

957 # Return the response 

958 resp = tag_values.TagValue() 

959 pb_resp = tag_values.TagValue.pb(resp) 

960 

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

962 resp = self._interceptor.post_get_namespaced_tag_value(resp) 

963 return resp 

964 

965 class _GetTagValue(TagValuesRestStub): 

966 def __hash__(self): 

967 return hash("GetTagValue") 

968 

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

970 

971 @classmethod 

972 def _get_unset_required_fields(cls, message_dict): 

973 return { 

974 k: v 

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

976 if k not in message_dict 

977 } 

978 

979 def __call__( 

980 self, 

981 request: tag_values.GetTagValueRequest, 

982 *, 

983 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

984 timeout: Optional[float] = None, 

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

986 ) -> tag_values.TagValue: 

987 r"""Call the get tag value method over HTTP. 

988 

989 Args: 

990 request (~.tag_values.GetTagValueRequest): 

991 The request object. The request message for getting a 

992 TagValue. 

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

994 should be retried. 

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

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

997 sent along with the request as metadata. 

998 

999 Returns: 

1000 ~.tag_values.TagValue: 

1001 A TagValue is a child of a particular 

1002 TagKey. This is used to group cloud 

1003 resources for the purpose of controlling 

1004 them using policies. 

1005 

1006 """ 

1007 

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

1009 { 

1010 "method": "get", 

1011 "uri": "/v3/{name=tagValues/*}", 

1012 }, 

1013 ] 

1014 request, metadata = self._interceptor.pre_get_tag_value(request, metadata) 

1015 pb_request = tag_values.GetTagValueRequest.pb(request) 

1016 transcoded_request = path_template.transcode(http_options, pb_request) 

1017 

1018 uri = transcoded_request["uri"] 

1019 method = transcoded_request["method"] 

1020 

1021 # Jsonify the query params 

1022 query_params = json.loads( 

1023 json_format.MessageToJson( 

1024 transcoded_request["query_params"], 

1025 including_default_value_fields=False, 

1026 use_integers_for_enums=True, 

1027 ) 

1028 ) 

1029 query_params.update(self._get_unset_required_fields(query_params)) 

1030 

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

1032 

1033 # Send the request 

1034 headers = dict(metadata) 

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

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

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

1038 timeout=timeout, 

1039 headers=headers, 

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

1041 ) 

1042 

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

1044 # subclass. 

1045 if response.status_code >= 400: 

1046 raise core_exceptions.from_http_response(response) 

1047 

1048 # Return the response 

1049 resp = tag_values.TagValue() 

1050 pb_resp = tag_values.TagValue.pb(resp) 

1051 

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

1053 resp = self._interceptor.post_get_tag_value(resp) 

1054 return resp 

1055 

1056 class _ListTagValues(TagValuesRestStub): 

1057 def __hash__(self): 

1058 return hash("ListTagValues") 

1059 

1060 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { 

1061 "parent": "", 

1062 } 

1063 

1064 @classmethod 

1065 def _get_unset_required_fields(cls, message_dict): 

1066 return { 

1067 k: v 

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

1069 if k not in message_dict 

1070 } 

1071 

1072 def __call__( 

1073 self, 

1074 request: tag_values.ListTagValuesRequest, 

1075 *, 

1076 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1077 timeout: Optional[float] = None, 

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

1079 ) -> tag_values.ListTagValuesResponse: 

1080 r"""Call the list tag values method over HTTP. 

1081 

1082 Args: 

1083 request (~.tag_values.ListTagValuesRequest): 

1084 The request object. The request message for listing TagValues for the 

1085 specified TagKey. Resource name for TagKey, parent of 

1086 the TagValues to be listed, in the format 

1087 ``tagKeys/123``. 

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

1089 should be retried. 

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

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

1092 sent along with the request as metadata. 

1093 

1094 Returns: 

1095 ~.tag_values.ListTagValuesResponse: 

1096 The ListTagValues response. 

1097 """ 

1098 

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

1100 { 

1101 "method": "get", 

1102 "uri": "/v3/tagValues", 

1103 }, 

1104 ] 

1105 request, metadata = self._interceptor.pre_list_tag_values(request, metadata) 

1106 pb_request = tag_values.ListTagValuesRequest.pb(request) 

1107 transcoded_request = path_template.transcode(http_options, pb_request) 

1108 

1109 uri = transcoded_request["uri"] 

1110 method = transcoded_request["method"] 

1111 

1112 # Jsonify the query params 

1113 query_params = json.loads( 

1114 json_format.MessageToJson( 

1115 transcoded_request["query_params"], 

1116 including_default_value_fields=False, 

1117 use_integers_for_enums=True, 

1118 ) 

1119 ) 

1120 query_params.update(self._get_unset_required_fields(query_params)) 

1121 

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

1123 

1124 # Send the request 

1125 headers = dict(metadata) 

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

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

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

1129 timeout=timeout, 

1130 headers=headers, 

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

1132 ) 

1133 

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

1135 # subclass. 

1136 if response.status_code >= 400: 

1137 raise core_exceptions.from_http_response(response) 

1138 

1139 # Return the response 

1140 resp = tag_values.ListTagValuesResponse() 

1141 pb_resp = tag_values.ListTagValuesResponse.pb(resp) 

1142 

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

1144 resp = self._interceptor.post_list_tag_values(resp) 

1145 return resp 

1146 

1147 class _SetIamPolicy(TagValuesRestStub): 

1148 def __hash__(self): 

1149 return hash("SetIamPolicy") 

1150 

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

1152 

1153 @classmethod 

1154 def _get_unset_required_fields(cls, message_dict): 

1155 return { 

1156 k: v 

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

1158 if k not in message_dict 

1159 } 

1160 

1161 def __call__( 

1162 self, 

1163 request: iam_policy_pb2.SetIamPolicyRequest, 

1164 *, 

1165 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1166 timeout: Optional[float] = None, 

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

1168 ) -> policy_pb2.Policy: 

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

1170 

1171 Args: 

1172 request (~.iam_policy_pb2.SetIamPolicyRequest): 

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

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

1175 should be retried. 

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

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

1178 sent along with the request as metadata. 

1179 

1180 Returns: 

1181 ~.policy_pb2.Policy: 

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

1183 specifies access controls for Google Cloud resources. 

1184 

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

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

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

1188 accounts, service accounts, Google groups, and domains 

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

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

1191 or a user-created custom role. 

1192 

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

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

1195 expression that allows access to a resource only if the 

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

1197 constraints based on attributes of the request, the 

1198 resource, or both. To learn which resources support 

1199 conditions in their IAM policies, see the `IAM 

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

1201 

1202 **JSON example:** 

1203 

1204 :: 

1205 

1206 { 

1207 "bindings": [ 

1208 { 

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

1210 "members": [ 

1211 "user:mike@example.com", 

1212 "group:admins@example.com", 

1213 "domain:google.com", 

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

1215 ] 

1216 }, 

1217 { 

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

1219 "members": [ 

1220 "user:eve@example.com" 

1221 ], 

1222 "condition": { 

1223 "title": "expirable access", 

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

1225 "expression": "request.time < 

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

1227 } 

1228 } 

1229 ], 

1230 "etag": "BwWWja0YfJA=", 

1231 "version": 3 

1232 } 

1233 

1234 **YAML example:** 

1235 

1236 :: 

1237 

1238 bindings: 

1239 - members: 

1240 - user:mike@example.com 

1241 - group:admins@example.com 

1242 - domain:google.com 

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

1244 role: roles/resourcemanager.organizationAdmin 

1245 - members: 

1246 - user:eve@example.com 

1247 role: roles/resourcemanager.organizationViewer 

1248 condition: 

1249 title: expirable access 

1250 description: Does not grant access after Sep 2020 

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

1252 etag: BwWWja0YfJA= 

1253 version: 3 

1254 

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

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

1257 

1258 """ 

1259 

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

1261 { 

1262 "method": "post", 

1263 "uri": "/v3/{resource=tagValues/*}:setIamPolicy", 

1264 "body": "*", 

1265 }, 

1266 ] 

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

1268 pb_request = request 

1269 transcoded_request = path_template.transcode(http_options, pb_request) 

1270 

1271 # Jsonify the request body 

1272 

1273 body = json_format.MessageToJson( 

1274 transcoded_request["body"], 

1275 including_default_value_fields=False, 

1276 use_integers_for_enums=True, 

1277 ) 

1278 uri = transcoded_request["uri"] 

1279 method = transcoded_request["method"] 

1280 

1281 # Jsonify the query params 

1282 query_params = json.loads( 

1283 json_format.MessageToJson( 

1284 transcoded_request["query_params"], 

1285 including_default_value_fields=False, 

1286 use_integers_for_enums=True, 

1287 ) 

1288 ) 

1289 query_params.update(self._get_unset_required_fields(query_params)) 

1290 

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

1292 

1293 # Send the request 

1294 headers = dict(metadata) 

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

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

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

1298 timeout=timeout, 

1299 headers=headers, 

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

1301 data=body, 

1302 ) 

1303 

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

1305 # subclass. 

1306 if response.status_code >= 400: 

1307 raise core_exceptions.from_http_response(response) 

1308 

1309 # Return the response 

1310 resp = policy_pb2.Policy() 

1311 pb_resp = resp 

1312 

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

1314 resp = self._interceptor.post_set_iam_policy(resp) 

1315 return resp 

1316 

1317 class _TestIamPermissions(TagValuesRestStub): 

1318 def __hash__(self): 

1319 return hash("TestIamPermissions") 

1320 

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

1322 

1323 @classmethod 

1324 def _get_unset_required_fields(cls, message_dict): 

1325 return { 

1326 k: v 

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

1328 if k not in message_dict 

1329 } 

1330 

1331 def __call__( 

1332 self, 

1333 request: iam_policy_pb2.TestIamPermissionsRequest, 

1334 *, 

1335 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1336 timeout: Optional[float] = None, 

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

1338 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

1340 

1341 Args: 

1342 request (~.iam_policy_pb2.TestIamPermissionsRequest): 

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

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

1345 should be retried. 

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

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

1348 sent along with the request as metadata. 

1349 

1350 Returns: 

1351 ~.iam_policy_pb2.TestIamPermissionsResponse: 

1352 Response message for ``TestIamPermissions`` method. 

1353 """ 

1354 

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

1356 { 

1357 "method": "post", 

1358 "uri": "/v3/{resource=tagValues/*}:testIamPermissions", 

1359 "body": "*", 

1360 }, 

1361 ] 

1362 request, metadata = self._interceptor.pre_test_iam_permissions( 

1363 request, metadata 

1364 ) 

1365 pb_request = request 

1366 transcoded_request = path_template.transcode(http_options, pb_request) 

1367 

1368 # Jsonify the request body 

1369 

1370 body = json_format.MessageToJson( 

1371 transcoded_request["body"], 

1372 including_default_value_fields=False, 

1373 use_integers_for_enums=True, 

1374 ) 

1375 uri = transcoded_request["uri"] 

1376 method = transcoded_request["method"] 

1377 

1378 # Jsonify the query params 

1379 query_params = json.loads( 

1380 json_format.MessageToJson( 

1381 transcoded_request["query_params"], 

1382 including_default_value_fields=False, 

1383 use_integers_for_enums=True, 

1384 ) 

1385 ) 

1386 query_params.update(self._get_unset_required_fields(query_params)) 

1387 

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

1389 

1390 # Send the request 

1391 headers = dict(metadata) 

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

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

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

1395 timeout=timeout, 

1396 headers=headers, 

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

1398 data=body, 

1399 ) 

1400 

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

1402 # subclass. 

1403 if response.status_code >= 400: 

1404 raise core_exceptions.from_http_response(response) 

1405 

1406 # Return the response 

1407 resp = iam_policy_pb2.TestIamPermissionsResponse() 

1408 pb_resp = resp 

1409 

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

1411 resp = self._interceptor.post_test_iam_permissions(resp) 

1412 return resp 

1413 

1414 class _UpdateTagValue(TagValuesRestStub): 

1415 def __hash__(self): 

1416 return hash("UpdateTagValue") 

1417 

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

1419 

1420 @classmethod 

1421 def _get_unset_required_fields(cls, message_dict): 

1422 return { 

1423 k: v 

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

1425 if k not in message_dict 

1426 } 

1427 

1428 def __call__( 

1429 self, 

1430 request: tag_values.UpdateTagValueRequest, 

1431 *, 

1432 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1433 timeout: Optional[float] = None, 

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

1435 ) -> operations_pb2.Operation: 

1436 r"""Call the update tag value method over HTTP. 

1437 

1438 Args: 

1439 request (~.tag_values.UpdateTagValueRequest): 

1440 The request object. The request message for updating a 

1441 TagValue. 

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

1443 should be retried. 

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

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

1446 sent along with the request as metadata. 

1447 

1448 Returns: 

1449 ~.operations_pb2.Operation: 

1450 This resource represents a 

1451 long-running operation that is the 

1452 result of a network API call. 

1453 

1454 """ 

1455 

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

1457 { 

1458 "method": "patch", 

1459 "uri": "/v3/{tag_value.name=tagValues/*}", 

1460 "body": "tag_value", 

1461 }, 

1462 ] 

1463 request, metadata = self._interceptor.pre_update_tag_value( 

1464 request, metadata 

1465 ) 

1466 pb_request = tag_values.UpdateTagValueRequest.pb(request) 

1467 transcoded_request = path_template.transcode(http_options, pb_request) 

1468 

1469 # Jsonify the request body 

1470 

1471 body = json_format.MessageToJson( 

1472 transcoded_request["body"], 

1473 including_default_value_fields=False, 

1474 use_integers_for_enums=True, 

1475 ) 

1476 uri = transcoded_request["uri"] 

1477 method = transcoded_request["method"] 

1478 

1479 # Jsonify the query params 

1480 query_params = json.loads( 

1481 json_format.MessageToJson( 

1482 transcoded_request["query_params"], 

1483 including_default_value_fields=False, 

1484 use_integers_for_enums=True, 

1485 ) 

1486 ) 

1487 query_params.update(self._get_unset_required_fields(query_params)) 

1488 

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

1490 

1491 # Send the request 

1492 headers = dict(metadata) 

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

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

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

1496 timeout=timeout, 

1497 headers=headers, 

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

1499 data=body, 

1500 ) 

1501 

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

1503 # subclass. 

1504 if response.status_code >= 400: 

1505 raise core_exceptions.from_http_response(response) 

1506 

1507 # Return the response 

1508 resp = operations_pb2.Operation() 

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

1510 resp = self._interceptor.post_update_tag_value(resp) 

1511 return resp 

1512 

1513 @property 

1514 def create_tag_value( 

1515 self, 

1516 ) -> Callable[[tag_values.CreateTagValueRequest], operations_pb2.Operation]: 

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._CreateTagValue(self._session, self._host, self._interceptor) # type: ignore 

1520 

1521 @property 

1522 def delete_tag_value( 

1523 self, 

1524 ) -> Callable[[tag_values.DeleteTagValueRequest], operations_pb2.Operation]: 

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

1526 # In C++ this would require a dynamic_cast 

1527 return self._DeleteTagValue(self._session, self._host, self._interceptor) # type: ignore 

1528 

1529 @property 

1530 def get_iam_policy( 

1531 self, 

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

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

1534 # In C++ this would require a dynamic_cast 

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

1536 

1537 @property 

1538 def get_namespaced_tag_value( 

1539 self, 

1540 ) -> Callable[[tag_values.GetNamespacedTagValueRequest], tag_values.TagValue]: 

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

1542 # In C++ this would require a dynamic_cast 

1543 return self._GetNamespacedTagValue(self._session, self._host, self._interceptor) # type: ignore 

1544 

1545 @property 

1546 def get_tag_value( 

1547 self, 

1548 ) -> Callable[[tag_values.GetTagValueRequest], tag_values.TagValue]: 

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

1550 # In C++ this would require a dynamic_cast 

1551 return self._GetTagValue(self._session, self._host, self._interceptor) # type: ignore 

1552 

1553 @property 

1554 def list_tag_values( 

1555 self, 

1556 ) -> Callable[[tag_values.ListTagValuesRequest], tag_values.ListTagValuesResponse]: 

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

1558 # In C++ this would require a dynamic_cast 

1559 return self._ListTagValues(self._session, self._host, self._interceptor) # type: ignore 

1560 

1561 @property 

1562 def set_iam_policy( 

1563 self, 

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

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

1566 # In C++ this would require a dynamic_cast 

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

1568 

1569 @property 

1570 def test_iam_permissions( 

1571 self, 

1572 ) -> Callable[ 

1573 [iam_policy_pb2.TestIamPermissionsRequest], 

1574 iam_policy_pb2.TestIamPermissionsResponse, 

1575 ]: 

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

1577 # In C++ this would require a dynamic_cast 

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

1579 

1580 @property 

1581 def update_tag_value( 

1582 self, 

1583 ) -> Callable[[tag_values.UpdateTagValueRequest], operations_pb2.Operation]: 

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

1585 # In C++ this would require a dynamic_cast 

1586 return self._UpdateTagValue(self._session, self._host, self._interceptor) # type: ignore 

1587 

1588 @property 

1589 def get_operation(self): 

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

1591 

1592 class _GetOperation(TagValuesRestStub): 

1593 def __call__( 

1594 self, 

1595 request: operations_pb2.GetOperationRequest, 

1596 *, 

1597 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1598 timeout: Optional[float] = None, 

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

1600 ) -> operations_pb2.Operation: 

1601 

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

1603 

1604 Args: 

1605 request (operations_pb2.GetOperationRequest): 

1606 The request object for GetOperation method. 

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

1608 should be retried. 

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

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

1611 sent along with the request as metadata. 

1612 

1613 Returns: 

1614 operations_pb2.Operation: Response from GetOperation method. 

1615 """ 

1616 

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

1618 { 

1619 "method": "get", 

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

1621 }, 

1622 ] 

1623 

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

1625 request_kwargs = json_format.MessageToDict(request) 

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

1627 

1628 uri = transcoded_request["uri"] 

1629 method = transcoded_request["method"] 

1630 

1631 # Jsonify the query params 

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

1633 

1634 # Send the request 

1635 headers = dict(metadata) 

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

1637 

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

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

1640 timeout=timeout, 

1641 headers=headers, 

1642 params=rest_helpers.flatten_query_params(query_params), 

1643 ) 

1644 

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

1646 # subclass. 

1647 if response.status_code >= 400: 

1648 raise core_exceptions.from_http_response(response) 

1649 

1650 resp = operations_pb2.Operation() 

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

1652 resp = self._interceptor.post_get_operation(resp) 

1653 return resp 

1654 

1655 @property 

1656 def kind(self) -> str: 

1657 return "rest" 

1658 

1659 def close(self): 

1660 self._session.close() 

1661 

1662 

1663__all__ = ("TagValuesRestTransport",)