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

467 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 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 

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

18import json # type: ignore 

19import grpc # type: ignore 

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

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

22from google.api_core import exceptions as core_exceptions 

23from google.api_core import retry as retries 

24from google.api_core import rest_helpers 

25from google.api_core import rest_streaming 

26from google.api_core import path_template 

27from google.api_core import gapic_v1 

28 

29from google.protobuf import json_format 

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

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

32from requests import __version__ as requests_version 

33import dataclasses 

34import re 

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

36import warnings 

37 

38try: 

39 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] 

40except AttributeError: # pragma: NO COVER 

41 OptionalRetry = Union[retries.Retry, object] # type: ignore 

42 

43 

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

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

46from google.protobuf import empty_pb2 # type: ignore 

47from google.pubsub_v1.types import schema 

48from google.pubsub_v1.types import schema as gp_schema 

49 

50from .base import ( 

51 SchemaServiceTransport, 

52 DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO, 

53) 

54 

55 

56DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

57 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

58 grpc_version=None, 

59 rest_version=requests_version, 

60) 

61 

62 

63class SchemaServiceRestInterceptor: 

64 """Interceptor for SchemaService. 

65 

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

67 in arbitrary ways. 

68 Example use cases include: 

69 * Logging 

70 * Verifying requests according to service or custom semantics 

71 * Stripping extraneous information from responses 

72 

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

74 instance of a custom subclass when constructing the SchemaServiceRestTransport. 

75 

76 .. code-block:: python 

77 class MyCustomSchemaServiceInterceptor(SchemaServiceRestInterceptor): 

78 def pre_commit_schema(self, request, metadata): 

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

80 return request, metadata 

81 

82 def post_commit_schema(self, response): 

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

84 return response 

85 

86 def pre_create_schema(self, request, metadata): 

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

88 return request, metadata 

89 

90 def post_create_schema(self, response): 

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

92 return response 

93 

94 def pre_delete_schema(self, request, metadata): 

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

96 return request, metadata 

97 

98 def pre_delete_schema_revision(self, request, metadata): 

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

100 return request, metadata 

101 

102 def post_delete_schema_revision(self, response): 

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

104 return response 

105 

106 def pre_get_schema(self, request, metadata): 

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

108 return request, metadata 

109 

110 def post_get_schema(self, response): 

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

112 return response 

113 

114 def pre_list_schema_revisions(self, request, metadata): 

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

116 return request, metadata 

117 

118 def post_list_schema_revisions(self, response): 

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

120 return response 

121 

122 def pre_list_schemas(self, request, metadata): 

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

124 return request, metadata 

125 

126 def post_list_schemas(self, response): 

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

128 return response 

129 

130 def pre_rollback_schema(self, request, metadata): 

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

132 return request, metadata 

133 

134 def post_rollback_schema(self, response): 

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

136 return response 

137 

138 def pre_validate_message(self, request, metadata): 

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

140 return request, metadata 

141 

142 def post_validate_message(self, response): 

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

144 return response 

145 

146 def pre_validate_schema(self, request, metadata): 

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

148 return request, metadata 

149 

150 def post_validate_schema(self, response): 

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

152 return response 

153 

154 transport = SchemaServiceRestTransport(interceptor=MyCustomSchemaServiceInterceptor()) 

155 client = SchemaServiceClient(transport=transport) 

156 

157 

158 """ 

159 

160 def pre_commit_schema( 

161 self, 

162 request: gp_schema.CommitSchemaRequest, 

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

164 ) -> Tuple[gp_schema.CommitSchemaRequest, Sequence[Tuple[str, str]]]: 

165 """Pre-rpc interceptor for commit_schema 

166 

167 Override in a subclass to manipulate the request or metadata 

168 before they are sent to the SchemaService server. 

169 """ 

170 return request, metadata 

171 

172 def post_commit_schema(self, response: gp_schema.Schema) -> gp_schema.Schema: 

173 """Post-rpc interceptor for commit_schema 

174 

175 Override in a subclass to manipulate the response 

176 after it is returned by the SchemaService server but before 

177 it is returned to user code. 

178 """ 

179 return response 

180 

181 def pre_create_schema( 

182 self, 

183 request: gp_schema.CreateSchemaRequest, 

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

185 ) -> Tuple[gp_schema.CreateSchemaRequest, Sequence[Tuple[str, str]]]: 

186 """Pre-rpc interceptor for create_schema 

187 

188 Override in a subclass to manipulate the request or metadata 

189 before they are sent to the SchemaService server. 

190 """ 

191 return request, metadata 

192 

193 def post_create_schema(self, response: gp_schema.Schema) -> gp_schema.Schema: 

194 """Post-rpc interceptor for create_schema 

195 

196 Override in a subclass to manipulate the response 

197 after it is returned by the SchemaService server but before 

198 it is returned to user code. 

199 """ 

200 return response 

201 

202 def pre_delete_schema( 

203 self, request: schema.DeleteSchemaRequest, metadata: Sequence[Tuple[str, str]] 

204 ) -> Tuple[schema.DeleteSchemaRequest, Sequence[Tuple[str, str]]]: 

205 """Pre-rpc interceptor for delete_schema 

206 

207 Override in a subclass to manipulate the request or metadata 

208 before they are sent to the SchemaService server. 

209 """ 

210 return request, metadata 

211 

212 def pre_delete_schema_revision( 

213 self, 

214 request: schema.DeleteSchemaRevisionRequest, 

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

216 ) -> Tuple[schema.DeleteSchemaRevisionRequest, Sequence[Tuple[str, str]]]: 

217 """Pre-rpc interceptor for delete_schema_revision 

218 

219 Override in a subclass to manipulate the request or metadata 

220 before they are sent to the SchemaService server. 

221 """ 

222 return request, metadata 

223 

224 def post_delete_schema_revision(self, response: schema.Schema) -> schema.Schema: 

225 """Post-rpc interceptor for delete_schema_revision 

226 

227 Override in a subclass to manipulate the response 

228 after it is returned by the SchemaService server but before 

229 it is returned to user code. 

230 """ 

231 return response 

232 

233 def pre_get_schema( 

234 self, request: schema.GetSchemaRequest, metadata: Sequence[Tuple[str, str]] 

235 ) -> Tuple[schema.GetSchemaRequest, Sequence[Tuple[str, str]]]: 

236 """Pre-rpc interceptor for get_schema 

237 

238 Override in a subclass to manipulate the request or metadata 

239 before they are sent to the SchemaService server. 

240 """ 

241 return request, metadata 

242 

243 def post_get_schema(self, response: schema.Schema) -> schema.Schema: 

244 """Post-rpc interceptor for get_schema 

245 

246 Override in a subclass to manipulate the response 

247 after it is returned by the SchemaService server but before 

248 it is returned to user code. 

249 """ 

250 return response 

251 

252 def pre_list_schema_revisions( 

253 self, 

254 request: schema.ListSchemaRevisionsRequest, 

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

256 ) -> Tuple[schema.ListSchemaRevisionsRequest, Sequence[Tuple[str, str]]]: 

257 """Pre-rpc interceptor for list_schema_revisions 

258 

259 Override in a subclass to manipulate the request or metadata 

260 before they are sent to the SchemaService server. 

261 """ 

262 return request, metadata 

263 

264 def post_list_schema_revisions( 

265 self, response: schema.ListSchemaRevisionsResponse 

266 ) -> schema.ListSchemaRevisionsResponse: 

267 """Post-rpc interceptor for list_schema_revisions 

268 

269 Override in a subclass to manipulate the response 

270 after it is returned by the SchemaService server but before 

271 it is returned to user code. 

272 """ 

273 return response 

274 

275 def pre_list_schemas( 

276 self, request: schema.ListSchemasRequest, metadata: Sequence[Tuple[str, str]] 

277 ) -> Tuple[schema.ListSchemasRequest, Sequence[Tuple[str, str]]]: 

278 """Pre-rpc interceptor for list_schemas 

279 

280 Override in a subclass to manipulate the request or metadata 

281 before they are sent to the SchemaService server. 

282 """ 

283 return request, metadata 

284 

285 def post_list_schemas( 

286 self, response: schema.ListSchemasResponse 

287 ) -> schema.ListSchemasResponse: 

288 """Post-rpc interceptor for list_schemas 

289 

290 Override in a subclass to manipulate the response 

291 after it is returned by the SchemaService server but before 

292 it is returned to user code. 

293 """ 

294 return response 

295 

296 def pre_rollback_schema( 

297 self, request: schema.RollbackSchemaRequest, metadata: Sequence[Tuple[str, str]] 

298 ) -> Tuple[schema.RollbackSchemaRequest, Sequence[Tuple[str, str]]]: 

299 """Pre-rpc interceptor for rollback_schema 

300 

301 Override in a subclass to manipulate the request or metadata 

302 before they are sent to the SchemaService server. 

303 """ 

304 return request, metadata 

305 

306 def post_rollback_schema(self, response: schema.Schema) -> schema.Schema: 

307 """Post-rpc interceptor for rollback_schema 

308 

309 Override in a subclass to manipulate the response 

310 after it is returned by the SchemaService server but before 

311 it is returned to user code. 

312 """ 

313 return response 

314 

315 def pre_validate_message( 

316 self, 

317 request: schema.ValidateMessageRequest, 

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

319 ) -> Tuple[schema.ValidateMessageRequest, Sequence[Tuple[str, str]]]: 

320 """Pre-rpc interceptor for validate_message 

321 

322 Override in a subclass to manipulate the request or metadata 

323 before they are sent to the SchemaService server. 

324 """ 

325 return request, metadata 

326 

327 def post_validate_message( 

328 self, response: schema.ValidateMessageResponse 

329 ) -> schema.ValidateMessageResponse: 

330 """Post-rpc interceptor for validate_message 

331 

332 Override in a subclass to manipulate the response 

333 after it is returned by the SchemaService server but before 

334 it is returned to user code. 

335 """ 

336 return response 

337 

338 def pre_validate_schema( 

339 self, 

340 request: gp_schema.ValidateSchemaRequest, 

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

342 ) -> Tuple[gp_schema.ValidateSchemaRequest, Sequence[Tuple[str, str]]]: 

343 """Pre-rpc interceptor for validate_schema 

344 

345 Override in a subclass to manipulate the request or metadata 

346 before they are sent to the SchemaService server. 

347 """ 

348 return request, metadata 

349 

350 def post_validate_schema( 

351 self, response: gp_schema.ValidateSchemaResponse 

352 ) -> gp_schema.ValidateSchemaResponse: 

353 """Post-rpc interceptor for validate_schema 

354 

355 Override in a subclass to manipulate the response 

356 after it is returned by the SchemaService server but before 

357 it is returned to user code. 

358 """ 

359 return response 

360 

361 def pre_get_iam_policy( 

362 self, 

363 request: iam_policy_pb2.GetIamPolicyRequest, 

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

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

366 """Pre-rpc interceptor for get_iam_policy 

367 

368 Override in a subclass to manipulate the request or metadata 

369 before they are sent to the SchemaService server. 

370 """ 

371 return request, metadata 

372 

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

374 """Post-rpc interceptor for get_iam_policy 

375 

376 Override in a subclass to manipulate the response 

377 after it is returned by the SchemaService server but before 

378 it is returned to user code. 

379 """ 

380 return response 

381 

382 def pre_set_iam_policy( 

383 self, 

384 request: iam_policy_pb2.SetIamPolicyRequest, 

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

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

387 """Pre-rpc interceptor for set_iam_policy 

388 

389 Override in a subclass to manipulate the request or metadata 

390 before they are sent to the SchemaService server. 

391 """ 

392 return request, metadata 

393 

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

395 """Post-rpc interceptor for set_iam_policy 

396 

397 Override in a subclass to manipulate the response 

398 after it is returned by the SchemaService server but before 

399 it is returned to user code. 

400 """ 

401 return response 

402 

403 def pre_test_iam_permissions( 

404 self, 

405 request: iam_policy_pb2.TestIamPermissionsRequest, 

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

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

408 """Pre-rpc interceptor for test_iam_permissions 

409 

410 Override in a subclass to manipulate the request or metadata 

411 before they are sent to the SchemaService server. 

412 """ 

413 return request, metadata 

414 

415 def post_test_iam_permissions( 

416 self, response: iam_policy_pb2.TestIamPermissionsResponse 

417 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

418 """Post-rpc interceptor for test_iam_permissions 

419 

420 Override in a subclass to manipulate the response 

421 after it is returned by the SchemaService server but before 

422 it is returned to user code. 

423 """ 

424 return response 

425 

426 

427@dataclasses.dataclass 

428class SchemaServiceRestStub: 

429 _session: AuthorizedSession 

430 _host: str 

431 _interceptor: SchemaServiceRestInterceptor 

432 

433 

434class SchemaServiceRestTransport(SchemaServiceTransport): 

435 """REST backend transport for SchemaService. 

436 

437 Service for doing schema-related operations. 

438 

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

440 primary client can load the underlying transport implementation 

441 and call it. 

442 

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

444 

445 """ 

446 

447 def __init__( 

448 self, 

449 *, 

450 host: str = "pubsub.googleapis.com", 

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

452 credentials_file: Optional[str] = None, 

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

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

455 quota_project_id: Optional[str] = None, 

456 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

457 always_use_jwt_access: Optional[bool] = False, 

458 url_scheme: str = "https", 

459 interceptor: Optional[SchemaServiceRestInterceptor] = None, 

460 api_audience: Optional[str] = None, 

461 ) -> None: 

462 """Instantiate the transport. 

463 

464 Args: 

465 host (Optional[str]): 

466 The hostname to connect to. 

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

468 authorization credentials to attach to requests. These 

469 credentials identify the application to the service; if none 

470 are specified, the client will attempt to ascertain the 

471 credentials from the environment. 

472 

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

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

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

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

477 ignored if ``channel`` is provided. 

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

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

480 if ``channel`` is provided. 

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

482 and quota. 

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

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

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

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

487 your own client library. 

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

489 be used for service account credentials. 

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

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

492 "http" can be specified. 

493 """ 

494 # Run the base constructor 

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

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

497 # credentials object 

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

499 if maybe_url_match is None: 

500 raise ValueError( 

501 f"Unexpected hostname structure: {host}" 

502 ) # pragma: NO COVER 

503 

504 url_match_items = maybe_url_match.groupdict() 

505 

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

507 

508 super().__init__( 

509 host=host, 

510 credentials=credentials, 

511 client_info=client_info, 

512 always_use_jwt_access=always_use_jwt_access, 

513 api_audience=api_audience, 

514 ) 

515 self._session = AuthorizedSession( 

516 self._credentials, default_host=self.DEFAULT_HOST 

517 ) 

518 if client_cert_source_for_mtls: 

519 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

520 self._interceptor = interceptor or SchemaServiceRestInterceptor() 

521 self._prep_wrapped_messages(client_info) 

522 

523 class _CommitSchema(SchemaServiceRestStub): 

524 def __hash__(self): 

525 return hash("CommitSchema") 

526 

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

528 

529 @classmethod 

530 def _get_unset_required_fields(cls, message_dict): 

531 return { 

532 k: v 

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

534 if k not in message_dict 

535 } 

536 

537 def __call__( 

538 self, 

539 request: gp_schema.CommitSchemaRequest, 

540 *, 

541 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

542 timeout: Optional[float] = None, 

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

544 ) -> gp_schema.Schema: 

545 r"""Call the commit schema method over HTTP. 

546 

547 Args: 

548 request (~.gp_schema.CommitSchemaRequest): 

549 The request object. Request for CommitSchema method. 

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

551 should be retried. 

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

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

554 sent along with the request as metadata. 

555 

556 Returns: 

557 ~.gp_schema.Schema: 

558 A schema resource. 

559 """ 

560 

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

562 { 

563 "method": "post", 

564 "uri": "/v1/{name=projects/*/schemas/*}:commit", 

565 "body": "*", 

566 }, 

567 ] 

568 request, metadata = self._interceptor.pre_commit_schema(request, metadata) 

569 pb_request = gp_schema.CommitSchemaRequest.pb(request) 

570 transcoded_request = path_template.transcode(http_options, pb_request) 

571 

572 # Jsonify the request body 

573 

574 body = json_format.MessageToJson( 

575 transcoded_request["body"], 

576 including_default_value_fields=False, 

577 use_integers_for_enums=True, 

578 ) 

579 uri = transcoded_request["uri"] 

580 method = transcoded_request["method"] 

581 

582 # Jsonify the query params 

583 query_params = json.loads( 

584 json_format.MessageToJson( 

585 transcoded_request["query_params"], 

586 including_default_value_fields=False, 

587 use_integers_for_enums=True, 

588 ) 

589 ) 

590 query_params.update(self._get_unset_required_fields(query_params)) 

591 

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

593 

594 # Send the request 

595 headers = dict(metadata) 

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

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

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

599 timeout=timeout, 

600 headers=headers, 

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

602 data=body, 

603 ) 

604 

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

606 # subclass. 

607 if response.status_code >= 400: 

608 raise core_exceptions.from_http_response(response) 

609 

610 # Return the response 

611 resp = gp_schema.Schema() 

612 pb_resp = gp_schema.Schema.pb(resp) 

613 

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

615 resp = self._interceptor.post_commit_schema(resp) 

616 return resp 

617 

618 class _CreateSchema(SchemaServiceRestStub): 

619 def __hash__(self): 

620 return hash("CreateSchema") 

621 

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

623 

624 @classmethod 

625 def _get_unset_required_fields(cls, message_dict): 

626 return { 

627 k: v 

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

629 if k not in message_dict 

630 } 

631 

632 def __call__( 

633 self, 

634 request: gp_schema.CreateSchemaRequest, 

635 *, 

636 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

637 timeout: Optional[float] = None, 

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

639 ) -> gp_schema.Schema: 

640 r"""Call the create schema method over HTTP. 

641 

642 Args: 

643 request (~.gp_schema.CreateSchemaRequest): 

644 The request object. Request for the CreateSchema method. 

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

646 should be retried. 

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

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

649 sent along with the request as metadata. 

650 

651 Returns: 

652 ~.gp_schema.Schema: 

653 A schema resource. 

654 """ 

655 

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

657 { 

658 "method": "post", 

659 "uri": "/v1/{parent=projects/*}/schemas", 

660 "body": "schema", 

661 }, 

662 ] 

663 request, metadata = self._interceptor.pre_create_schema(request, metadata) 

664 pb_request = gp_schema.CreateSchemaRequest.pb(request) 

665 transcoded_request = path_template.transcode(http_options, pb_request) 

666 

667 # Jsonify the request body 

668 

669 body = json_format.MessageToJson( 

670 transcoded_request["body"], 

671 including_default_value_fields=False, 

672 use_integers_for_enums=True, 

673 ) 

674 uri = transcoded_request["uri"] 

675 method = transcoded_request["method"] 

676 

677 # Jsonify the query params 

678 query_params = json.loads( 

679 json_format.MessageToJson( 

680 transcoded_request["query_params"], 

681 including_default_value_fields=False, 

682 use_integers_for_enums=True, 

683 ) 

684 ) 

685 query_params.update(self._get_unset_required_fields(query_params)) 

686 

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

688 

689 # Send the request 

690 headers = dict(metadata) 

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

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

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

694 timeout=timeout, 

695 headers=headers, 

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

697 data=body, 

698 ) 

699 

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

701 # subclass. 

702 if response.status_code >= 400: 

703 raise core_exceptions.from_http_response(response) 

704 

705 # Return the response 

706 resp = gp_schema.Schema() 

707 pb_resp = gp_schema.Schema.pb(resp) 

708 

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

710 resp = self._interceptor.post_create_schema(resp) 

711 return resp 

712 

713 class _DeleteSchema(SchemaServiceRestStub): 

714 def __hash__(self): 

715 return hash("DeleteSchema") 

716 

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

718 

719 @classmethod 

720 def _get_unset_required_fields(cls, message_dict): 

721 return { 

722 k: v 

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

724 if k not in message_dict 

725 } 

726 

727 def __call__( 

728 self, 

729 request: schema.DeleteSchemaRequest, 

730 *, 

731 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

732 timeout: Optional[float] = None, 

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

734 ): 

735 r"""Call the delete schema method over HTTP. 

736 

737 Args: 

738 request (~.schema.DeleteSchemaRequest): 

739 The request object. Request for the ``DeleteSchema`` method. 

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

741 should be retried. 

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

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

744 sent along with the request as metadata. 

745 """ 

746 

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

748 { 

749 "method": "delete", 

750 "uri": "/v1/{name=projects/*/schemas/*}", 

751 }, 

752 ] 

753 request, metadata = self._interceptor.pre_delete_schema(request, metadata) 

754 pb_request = schema.DeleteSchemaRequest.pb(request) 

755 transcoded_request = path_template.transcode(http_options, pb_request) 

756 

757 uri = transcoded_request["uri"] 

758 method = transcoded_request["method"] 

759 

760 # Jsonify the query params 

761 query_params = json.loads( 

762 json_format.MessageToJson( 

763 transcoded_request["query_params"], 

764 including_default_value_fields=False, 

765 use_integers_for_enums=True, 

766 ) 

767 ) 

768 query_params.update(self._get_unset_required_fields(query_params)) 

769 

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

771 

772 # Send the request 

773 headers = dict(metadata) 

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

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

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

777 timeout=timeout, 

778 headers=headers, 

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

780 ) 

781 

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

783 # subclass. 

784 if response.status_code >= 400: 

785 raise core_exceptions.from_http_response(response) 

786 

787 class _DeleteSchemaRevision(SchemaServiceRestStub): 

788 def __hash__(self): 

789 return hash("DeleteSchemaRevision") 

790 

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

792 

793 @classmethod 

794 def _get_unset_required_fields(cls, message_dict): 

795 return { 

796 k: v 

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

798 if k not in message_dict 

799 } 

800 

801 def __call__( 

802 self, 

803 request: schema.DeleteSchemaRevisionRequest, 

804 *, 

805 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

806 timeout: Optional[float] = None, 

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

808 ) -> schema.Schema: 

809 r"""Call the delete schema revision method over HTTP. 

810 

811 Args: 

812 request (~.schema.DeleteSchemaRevisionRequest): 

813 The request object. Request for the ``DeleteSchemaRevision`` method. 

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

815 should be retried. 

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

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

818 sent along with the request as metadata. 

819 

820 Returns: 

821 ~.schema.Schema: 

822 A schema resource. 

823 """ 

824 

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

826 { 

827 "method": "delete", 

828 "uri": "/v1/{name=projects/*/schemas/*}:deleteRevision", 

829 }, 

830 ] 

831 request, metadata = self._interceptor.pre_delete_schema_revision( 

832 request, metadata 

833 ) 

834 pb_request = schema.DeleteSchemaRevisionRequest.pb(request) 

835 transcoded_request = path_template.transcode(http_options, pb_request) 

836 

837 uri = transcoded_request["uri"] 

838 method = transcoded_request["method"] 

839 

840 # Jsonify the query params 

841 query_params = json.loads( 

842 json_format.MessageToJson( 

843 transcoded_request["query_params"], 

844 including_default_value_fields=False, 

845 use_integers_for_enums=True, 

846 ) 

847 ) 

848 query_params.update(self._get_unset_required_fields(query_params)) 

849 

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

851 

852 # Send the request 

853 headers = dict(metadata) 

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

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

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

857 timeout=timeout, 

858 headers=headers, 

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

860 ) 

861 

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

863 # subclass. 

864 if response.status_code >= 400: 

865 raise core_exceptions.from_http_response(response) 

866 

867 # Return the response 

868 resp = schema.Schema() 

869 pb_resp = schema.Schema.pb(resp) 

870 

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

872 resp = self._interceptor.post_delete_schema_revision(resp) 

873 return resp 

874 

875 class _GetSchema(SchemaServiceRestStub): 

876 def __hash__(self): 

877 return hash("GetSchema") 

878 

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

880 

881 @classmethod 

882 def _get_unset_required_fields(cls, message_dict): 

883 return { 

884 k: v 

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

886 if k not in message_dict 

887 } 

888 

889 def __call__( 

890 self, 

891 request: schema.GetSchemaRequest, 

892 *, 

893 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

894 timeout: Optional[float] = None, 

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

896 ) -> schema.Schema: 

897 r"""Call the get schema method over HTTP. 

898 

899 Args: 

900 request (~.schema.GetSchemaRequest): 

901 The request object. Request for the GetSchema method. 

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

903 should be retried. 

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

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

906 sent along with the request as metadata. 

907 

908 Returns: 

909 ~.schema.Schema: 

910 A schema resource. 

911 """ 

912 

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

914 { 

915 "method": "get", 

916 "uri": "/v1/{name=projects/*/schemas/*}", 

917 }, 

918 ] 

919 request, metadata = self._interceptor.pre_get_schema(request, metadata) 

920 pb_request = schema.GetSchemaRequest.pb(request) 

921 transcoded_request = path_template.transcode(http_options, pb_request) 

922 

923 uri = transcoded_request["uri"] 

924 method = transcoded_request["method"] 

925 

926 # Jsonify the query params 

927 query_params = json.loads( 

928 json_format.MessageToJson( 

929 transcoded_request["query_params"], 

930 including_default_value_fields=False, 

931 use_integers_for_enums=True, 

932 ) 

933 ) 

934 query_params.update(self._get_unset_required_fields(query_params)) 

935 

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

937 

938 # Send the request 

939 headers = dict(metadata) 

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

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

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

943 timeout=timeout, 

944 headers=headers, 

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

946 ) 

947 

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

949 # subclass. 

950 if response.status_code >= 400: 

951 raise core_exceptions.from_http_response(response) 

952 

953 # Return the response 

954 resp = schema.Schema() 

955 pb_resp = schema.Schema.pb(resp) 

956 

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

958 resp = self._interceptor.post_get_schema(resp) 

959 return resp 

960 

961 class _ListSchemaRevisions(SchemaServiceRestStub): 

962 def __hash__(self): 

963 return hash("ListSchemaRevisions") 

964 

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

966 

967 @classmethod 

968 def _get_unset_required_fields(cls, message_dict): 

969 return { 

970 k: v 

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

972 if k not in message_dict 

973 } 

974 

975 def __call__( 

976 self, 

977 request: schema.ListSchemaRevisionsRequest, 

978 *, 

979 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

980 timeout: Optional[float] = None, 

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

982 ) -> schema.ListSchemaRevisionsResponse: 

983 r"""Call the list schema revisions method over HTTP. 

984 

985 Args: 

986 request (~.schema.ListSchemaRevisionsRequest): 

987 The request object. Request for the ``ListSchemaRevisions`` method. 

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

989 should be retried. 

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

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

992 sent along with the request as metadata. 

993 

994 Returns: 

995 ~.schema.ListSchemaRevisionsResponse: 

996 Response for the ``ListSchemaRevisions`` method. 

997 """ 

998 

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

1000 { 

1001 "method": "get", 

1002 "uri": "/v1/{name=projects/*/schemas/*}:listRevisions", 

1003 }, 

1004 ] 

1005 request, metadata = self._interceptor.pre_list_schema_revisions( 

1006 request, metadata 

1007 ) 

1008 pb_request = schema.ListSchemaRevisionsRequest.pb(request) 

1009 transcoded_request = path_template.transcode(http_options, pb_request) 

1010 

1011 uri = transcoded_request["uri"] 

1012 method = transcoded_request["method"] 

1013 

1014 # Jsonify the query params 

1015 query_params = json.loads( 

1016 json_format.MessageToJson( 

1017 transcoded_request["query_params"], 

1018 including_default_value_fields=False, 

1019 use_integers_for_enums=True, 

1020 ) 

1021 ) 

1022 query_params.update(self._get_unset_required_fields(query_params)) 

1023 

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

1025 

1026 # Send the request 

1027 headers = dict(metadata) 

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

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

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

1031 timeout=timeout, 

1032 headers=headers, 

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

1034 ) 

1035 

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

1037 # subclass. 

1038 if response.status_code >= 400: 

1039 raise core_exceptions.from_http_response(response) 

1040 

1041 # Return the response 

1042 resp = schema.ListSchemaRevisionsResponse() 

1043 pb_resp = schema.ListSchemaRevisionsResponse.pb(resp) 

1044 

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

1046 resp = self._interceptor.post_list_schema_revisions(resp) 

1047 return resp 

1048 

1049 class _ListSchemas(SchemaServiceRestStub): 

1050 def __hash__(self): 

1051 return hash("ListSchemas") 

1052 

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

1054 

1055 @classmethod 

1056 def _get_unset_required_fields(cls, message_dict): 

1057 return { 

1058 k: v 

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

1060 if k not in message_dict 

1061 } 

1062 

1063 def __call__( 

1064 self, 

1065 request: schema.ListSchemasRequest, 

1066 *, 

1067 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1068 timeout: Optional[float] = None, 

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

1070 ) -> schema.ListSchemasResponse: 

1071 r"""Call the list schemas method over HTTP. 

1072 

1073 Args: 

1074 request (~.schema.ListSchemasRequest): 

1075 The request object. Request for the ``ListSchemas`` method. 

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

1077 should be retried. 

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

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

1080 sent along with the request as metadata. 

1081 

1082 Returns: 

1083 ~.schema.ListSchemasResponse: 

1084 Response for the ``ListSchemas`` method. 

1085 """ 

1086 

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

1088 { 

1089 "method": "get", 

1090 "uri": "/v1/{parent=projects/*}/schemas", 

1091 }, 

1092 ] 

1093 request, metadata = self._interceptor.pre_list_schemas(request, metadata) 

1094 pb_request = schema.ListSchemasRequest.pb(request) 

1095 transcoded_request = path_template.transcode(http_options, pb_request) 

1096 

1097 uri = transcoded_request["uri"] 

1098 method = transcoded_request["method"] 

1099 

1100 # Jsonify the query params 

1101 query_params = json.loads( 

1102 json_format.MessageToJson( 

1103 transcoded_request["query_params"], 

1104 including_default_value_fields=False, 

1105 use_integers_for_enums=True, 

1106 ) 

1107 ) 

1108 query_params.update(self._get_unset_required_fields(query_params)) 

1109 

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

1111 

1112 # Send the request 

1113 headers = dict(metadata) 

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

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

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

1117 timeout=timeout, 

1118 headers=headers, 

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

1120 ) 

1121 

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

1123 # subclass. 

1124 if response.status_code >= 400: 

1125 raise core_exceptions.from_http_response(response) 

1126 

1127 # Return the response 

1128 resp = schema.ListSchemasResponse() 

1129 pb_resp = schema.ListSchemasResponse.pb(resp) 

1130 

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

1132 resp = self._interceptor.post_list_schemas(resp) 

1133 return resp 

1134 

1135 class _RollbackSchema(SchemaServiceRestStub): 

1136 def __hash__(self): 

1137 return hash("RollbackSchema") 

1138 

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

1140 

1141 @classmethod 

1142 def _get_unset_required_fields(cls, message_dict): 

1143 return { 

1144 k: v 

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

1146 if k not in message_dict 

1147 } 

1148 

1149 def __call__( 

1150 self, 

1151 request: schema.RollbackSchemaRequest, 

1152 *, 

1153 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1154 timeout: Optional[float] = None, 

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

1156 ) -> schema.Schema: 

1157 r"""Call the rollback schema method over HTTP. 

1158 

1159 Args: 

1160 request (~.schema.RollbackSchemaRequest): 

1161 The request object. Request for the ``RollbackSchema`` method. 

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

1163 should be retried. 

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

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

1166 sent along with the request as metadata. 

1167 

1168 Returns: 

1169 ~.schema.Schema: 

1170 A schema resource. 

1171 """ 

1172 

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

1174 { 

1175 "method": "post", 

1176 "uri": "/v1/{name=projects/*/schemas/*}:rollback", 

1177 "body": "*", 

1178 }, 

1179 ] 

1180 request, metadata = self._interceptor.pre_rollback_schema(request, metadata) 

1181 pb_request = schema.RollbackSchemaRequest.pb(request) 

1182 transcoded_request = path_template.transcode(http_options, pb_request) 

1183 

1184 # Jsonify the request body 

1185 

1186 body = json_format.MessageToJson( 

1187 transcoded_request["body"], 

1188 including_default_value_fields=False, 

1189 use_integers_for_enums=True, 

1190 ) 

1191 uri = transcoded_request["uri"] 

1192 method = transcoded_request["method"] 

1193 

1194 # Jsonify the query params 

1195 query_params = json.loads( 

1196 json_format.MessageToJson( 

1197 transcoded_request["query_params"], 

1198 including_default_value_fields=False, 

1199 use_integers_for_enums=True, 

1200 ) 

1201 ) 

1202 query_params.update(self._get_unset_required_fields(query_params)) 

1203 

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

1205 

1206 # Send the request 

1207 headers = dict(metadata) 

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

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

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

1211 timeout=timeout, 

1212 headers=headers, 

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

1214 data=body, 

1215 ) 

1216 

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

1218 # subclass. 

1219 if response.status_code >= 400: 

1220 raise core_exceptions.from_http_response(response) 

1221 

1222 # Return the response 

1223 resp = schema.Schema() 

1224 pb_resp = schema.Schema.pb(resp) 

1225 

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

1227 resp = self._interceptor.post_rollback_schema(resp) 

1228 return resp 

1229 

1230 class _ValidateMessage(SchemaServiceRestStub): 

1231 def __hash__(self): 

1232 return hash("ValidateMessage") 

1233 

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

1235 

1236 @classmethod 

1237 def _get_unset_required_fields(cls, message_dict): 

1238 return { 

1239 k: v 

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

1241 if k not in message_dict 

1242 } 

1243 

1244 def __call__( 

1245 self, 

1246 request: schema.ValidateMessageRequest, 

1247 *, 

1248 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1249 timeout: Optional[float] = None, 

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

1251 ) -> schema.ValidateMessageResponse: 

1252 r"""Call the validate message method over HTTP. 

1253 

1254 Args: 

1255 request (~.schema.ValidateMessageRequest): 

1256 The request object. Request for the ``ValidateMessage`` method. 

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

1258 should be retried. 

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

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

1261 sent along with the request as metadata. 

1262 

1263 Returns: 

1264 ~.schema.ValidateMessageResponse: 

1265 Response for the ``ValidateMessage`` method. Empty for 

1266 now. 

1267 

1268 """ 

1269 

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

1271 { 

1272 "method": "post", 

1273 "uri": "/v1/{parent=projects/*}/schemas:validateMessage", 

1274 "body": "*", 

1275 }, 

1276 ] 

1277 request, metadata = self._interceptor.pre_validate_message( 

1278 request, metadata 

1279 ) 

1280 pb_request = schema.ValidateMessageRequest.pb(request) 

1281 transcoded_request = path_template.transcode(http_options, pb_request) 

1282 

1283 # Jsonify the request body 

1284 

1285 body = json_format.MessageToJson( 

1286 transcoded_request["body"], 

1287 including_default_value_fields=False, 

1288 use_integers_for_enums=True, 

1289 ) 

1290 uri = transcoded_request["uri"] 

1291 method = transcoded_request["method"] 

1292 

1293 # Jsonify the query params 

1294 query_params = json.loads( 

1295 json_format.MessageToJson( 

1296 transcoded_request["query_params"], 

1297 including_default_value_fields=False, 

1298 use_integers_for_enums=True, 

1299 ) 

1300 ) 

1301 query_params.update(self._get_unset_required_fields(query_params)) 

1302 

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

1304 

1305 # Send the request 

1306 headers = dict(metadata) 

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

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

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

1310 timeout=timeout, 

1311 headers=headers, 

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

1313 data=body, 

1314 ) 

1315 

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

1317 # subclass. 

1318 if response.status_code >= 400: 

1319 raise core_exceptions.from_http_response(response) 

1320 

1321 # Return the response 

1322 resp = schema.ValidateMessageResponse() 

1323 pb_resp = schema.ValidateMessageResponse.pb(resp) 

1324 

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

1326 resp = self._interceptor.post_validate_message(resp) 

1327 return resp 

1328 

1329 class _ValidateSchema(SchemaServiceRestStub): 

1330 def __hash__(self): 

1331 return hash("ValidateSchema") 

1332 

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

1334 

1335 @classmethod 

1336 def _get_unset_required_fields(cls, message_dict): 

1337 return { 

1338 k: v 

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

1340 if k not in message_dict 

1341 } 

1342 

1343 def __call__( 

1344 self, 

1345 request: gp_schema.ValidateSchemaRequest, 

1346 *, 

1347 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1348 timeout: Optional[float] = None, 

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

1350 ) -> gp_schema.ValidateSchemaResponse: 

1351 r"""Call the validate schema method over HTTP. 

1352 

1353 Args: 

1354 request (~.gp_schema.ValidateSchemaRequest): 

1355 The request object. Request for the ``ValidateSchema`` method. 

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

1357 should be retried. 

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

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

1360 sent along with the request as metadata. 

1361 

1362 Returns: 

1363 ~.gp_schema.ValidateSchemaResponse: 

1364 Response for the ``ValidateSchema`` method. Empty for 

1365 now. 

1366 

1367 """ 

1368 

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

1370 { 

1371 "method": "post", 

1372 "uri": "/v1/{parent=projects/*}/schemas:validate", 

1373 "body": "*", 

1374 }, 

1375 ] 

1376 request, metadata = self._interceptor.pre_validate_schema(request, metadata) 

1377 pb_request = gp_schema.ValidateSchemaRequest.pb(request) 

1378 transcoded_request = path_template.transcode(http_options, pb_request) 

1379 

1380 # Jsonify the request body 

1381 

1382 body = json_format.MessageToJson( 

1383 transcoded_request["body"], 

1384 including_default_value_fields=False, 

1385 use_integers_for_enums=True, 

1386 ) 

1387 uri = transcoded_request["uri"] 

1388 method = transcoded_request["method"] 

1389 

1390 # Jsonify the query params 

1391 query_params = json.loads( 

1392 json_format.MessageToJson( 

1393 transcoded_request["query_params"], 

1394 including_default_value_fields=False, 

1395 use_integers_for_enums=True, 

1396 ) 

1397 ) 

1398 query_params.update(self._get_unset_required_fields(query_params)) 

1399 

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

1401 

1402 # Send the request 

1403 headers = dict(metadata) 

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

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

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

1407 timeout=timeout, 

1408 headers=headers, 

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

1410 data=body, 

1411 ) 

1412 

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

1414 # subclass. 

1415 if response.status_code >= 400: 

1416 raise core_exceptions.from_http_response(response) 

1417 

1418 # Return the response 

1419 resp = gp_schema.ValidateSchemaResponse() 

1420 pb_resp = gp_schema.ValidateSchemaResponse.pb(resp) 

1421 

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

1423 resp = self._interceptor.post_validate_schema(resp) 

1424 return resp 

1425 

1426 @property 

1427 def commit_schema( 

1428 self, 

1429 ) -> Callable[[gp_schema.CommitSchemaRequest], gp_schema.Schema]: 

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

1431 # In C++ this would require a dynamic_cast 

1432 return self._CommitSchema(self._session, self._host, self._interceptor) # type: ignore 

1433 

1434 @property 

1435 def create_schema( 

1436 self, 

1437 ) -> Callable[[gp_schema.CreateSchemaRequest], gp_schema.Schema]: 

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

1439 # In C++ this would require a dynamic_cast 

1440 return self._CreateSchema(self._session, self._host, self._interceptor) # type: ignore 

1441 

1442 @property 

1443 def delete_schema(self) -> Callable[[schema.DeleteSchemaRequest], empty_pb2.Empty]: 

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

1445 # In C++ this would require a dynamic_cast 

1446 return self._DeleteSchema(self._session, self._host, self._interceptor) # type: ignore 

1447 

1448 @property 

1449 def delete_schema_revision( 

1450 self, 

1451 ) -> Callable[[schema.DeleteSchemaRevisionRequest], schema.Schema]: 

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

1453 # In C++ this would require a dynamic_cast 

1454 return self._DeleteSchemaRevision(self._session, self._host, self._interceptor) # type: ignore 

1455 

1456 @property 

1457 def get_schema(self) -> Callable[[schema.GetSchemaRequest], schema.Schema]: 

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

1459 # In C++ this would require a dynamic_cast 

1460 return self._GetSchema(self._session, self._host, self._interceptor) # type: ignore 

1461 

1462 @property 

1463 def list_schema_revisions( 

1464 self, 

1465 ) -> Callable[ 

1466 [schema.ListSchemaRevisionsRequest], schema.ListSchemaRevisionsResponse 

1467 ]: 

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

1469 # In C++ this would require a dynamic_cast 

1470 return self._ListSchemaRevisions(self._session, self._host, self._interceptor) # type: ignore 

1471 

1472 @property 

1473 def list_schemas( 

1474 self, 

1475 ) -> Callable[[schema.ListSchemasRequest], schema.ListSchemasResponse]: 

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

1477 # In C++ this would require a dynamic_cast 

1478 return self._ListSchemas(self._session, self._host, self._interceptor) # type: ignore 

1479 

1480 @property 

1481 def rollback_schema( 

1482 self, 

1483 ) -> Callable[[schema.RollbackSchemaRequest], schema.Schema]: 

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

1485 # In C++ this would require a dynamic_cast 

1486 return self._RollbackSchema(self._session, self._host, self._interceptor) # type: ignore 

1487 

1488 @property 

1489 def validate_message( 

1490 self, 

1491 ) -> Callable[[schema.ValidateMessageRequest], schema.ValidateMessageResponse]: 

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

1493 # In C++ this would require a dynamic_cast 

1494 return self._ValidateMessage(self._session, self._host, self._interceptor) # type: ignore 

1495 

1496 @property 

1497 def validate_schema( 

1498 self, 

1499 ) -> Callable[[gp_schema.ValidateSchemaRequest], gp_schema.ValidateSchemaResponse]: 

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

1501 # In C++ this would require a dynamic_cast 

1502 return self._ValidateSchema(self._session, self._host, self._interceptor) # type: ignore 

1503 

1504 @property 

1505 def get_iam_policy(self): 

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

1507 

1508 class _GetIamPolicy(SchemaServiceRestStub): 

1509 def __call__( 

1510 self, 

1511 request: iam_policy_pb2.GetIamPolicyRequest, 

1512 *, 

1513 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1514 timeout: Optional[float] = None, 

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

1516 ) -> policy_pb2.Policy: 

1517 

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

1519 

1520 Args: 

1521 request (iam_policy_pb2.GetIamPolicyRequest): 

1522 The request object for GetIamPolicy method. 

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

1524 should be retried. 

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

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

1527 sent along with the request as metadata. 

1528 

1529 Returns: 

1530 policy_pb2.Policy: Response from GetIamPolicy method. 

1531 """ 

1532 

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

1534 { 

1535 "method": "get", 

1536 "uri": "/v1/{resource=projects/*/topics/*}:getIamPolicy", 

1537 }, 

1538 { 

1539 "method": "get", 

1540 "uri": "/v1/{resource=projects/*/subscriptions/*}:getIamPolicy", 

1541 }, 

1542 { 

1543 "method": "get", 

1544 "uri": "/v1/{resource=projects/*/snapshots/*}:getIamPolicy", 

1545 }, 

1546 { 

1547 "method": "get", 

1548 "uri": "/v1/{resource=projects/*/schemas/*}:getIamPolicy", 

1549 }, 

1550 ] 

1551 

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

1553 request_kwargs = json_format.MessageToDict(request) 

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

1555 

1556 uri = transcoded_request["uri"] 

1557 method = transcoded_request["method"] 

1558 

1559 # Jsonify the query params 

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

1561 

1562 # Send the request 

1563 headers = dict(metadata) 

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

1565 

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

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

1568 timeout=timeout, 

1569 headers=headers, 

1570 params=rest_helpers.flatten_query_params(query_params), 

1571 ) 

1572 

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

1574 # subclass. 

1575 if response.status_code >= 400: 

1576 raise core_exceptions.from_http_response(response) 

1577 

1578 resp = policy_pb2.Policy() 

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

1580 resp = self._interceptor.post_get_iam_policy(resp) 

1581 return resp 

1582 

1583 @property 

1584 def set_iam_policy(self): 

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

1586 

1587 class _SetIamPolicy(SchemaServiceRestStub): 

1588 def __call__( 

1589 self, 

1590 request: iam_policy_pb2.SetIamPolicyRequest, 

1591 *, 

1592 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1593 timeout: Optional[float] = None, 

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

1595 ) -> policy_pb2.Policy: 

1596 

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

1598 

1599 Args: 

1600 request (iam_policy_pb2.SetIamPolicyRequest): 

1601 The request object for SetIamPolicy method. 

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

1603 should be retried. 

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

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

1606 sent along with the request as metadata. 

1607 

1608 Returns: 

1609 policy_pb2.Policy: Response from SetIamPolicy method. 

1610 """ 

1611 

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

1613 { 

1614 "method": "post", 

1615 "uri": "/v1/{resource=projects/*/topics/*}:setIamPolicy", 

1616 "body": "*", 

1617 }, 

1618 { 

1619 "method": "post", 

1620 "uri": "/v1/{resource=projects/*/subscriptions/*}:setIamPolicy", 

1621 "body": "*", 

1622 }, 

1623 { 

1624 "method": "post", 

1625 "uri": "/v1/{resource=projects/*/snapshots/*}:setIamPolicy", 

1626 "body": "*", 

1627 }, 

1628 { 

1629 "method": "post", 

1630 "uri": "/v1/{resource=projects/*/schemas/*}:setIamPolicy", 

1631 "body": "*", 

1632 }, 

1633 ] 

1634 

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

1636 request_kwargs = json_format.MessageToDict(request) 

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

1638 

1639 body = json.loads(json.dumps(transcoded_request["body"])) 

1640 uri = transcoded_request["uri"] 

1641 method = transcoded_request["method"] 

1642 

1643 # Jsonify the query params 

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

1645 

1646 # Send the request 

1647 headers = dict(metadata) 

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

1649 

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

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

1652 timeout=timeout, 

1653 headers=headers, 

1654 params=rest_helpers.flatten_query_params(query_params), 

1655 data=body, 

1656 ) 

1657 

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

1659 # subclass. 

1660 if response.status_code >= 400: 

1661 raise core_exceptions.from_http_response(response) 

1662 

1663 resp = policy_pb2.Policy() 

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

1665 resp = self._interceptor.post_set_iam_policy(resp) 

1666 return resp 

1667 

1668 @property 

1669 def test_iam_permissions(self): 

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

1671 

1672 class _TestIamPermissions(SchemaServiceRestStub): 

1673 def __call__( 

1674 self, 

1675 request: iam_policy_pb2.TestIamPermissionsRequest, 

1676 *, 

1677 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1678 timeout: Optional[float] = None, 

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

1680 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1681 

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

1683 

1684 Args: 

1685 request (iam_policy_pb2.TestIamPermissionsRequest): 

1686 The request object for TestIamPermissions method. 

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

1688 should be retried. 

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

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

1691 sent along with the request as metadata. 

1692 

1693 Returns: 

1694 iam_policy_pb2.TestIamPermissionsResponse: Response from TestIamPermissions method. 

1695 """ 

1696 

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

1698 { 

1699 "method": "post", 

1700 "uri": "/v1/{resource=projects/*/subscriptions/*}:testIamPermissions", 

1701 "body": "*", 

1702 }, 

1703 { 

1704 "method": "post", 

1705 "uri": "/v1/{resource=projects/*/topics/*}:testIamPermissions", 

1706 "body": "*", 

1707 }, 

1708 { 

1709 "method": "post", 

1710 "uri": "/v1/{resource=projects/*/snapshots/*}:testIamPermissions", 

1711 "body": "*", 

1712 }, 

1713 { 

1714 "method": "post", 

1715 "uri": "/v1/{resource=projects/*/schemas/*}:testIamPermissions", 

1716 "body": "*", 

1717 }, 

1718 ] 

1719 

1720 request, metadata = self._interceptor.pre_test_iam_permissions( 

1721 request, metadata 

1722 ) 

1723 request_kwargs = json_format.MessageToDict(request) 

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

1725 

1726 body = json.loads(json.dumps(transcoded_request["body"])) 

1727 uri = transcoded_request["uri"] 

1728 method = transcoded_request["method"] 

1729 

1730 # Jsonify the query params 

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

1732 

1733 # Send the request 

1734 headers = dict(metadata) 

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

1736 

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

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

1739 timeout=timeout, 

1740 headers=headers, 

1741 params=rest_helpers.flatten_query_params(query_params), 

1742 data=body, 

1743 ) 

1744 

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

1746 # subclass. 

1747 if response.status_code >= 400: 

1748 raise core_exceptions.from_http_response(response) 

1749 

1750 resp = iam_policy_pb2.TestIamPermissionsResponse() 

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

1752 resp = self._interceptor.post_test_iam_permissions(resp) 

1753 return resp 

1754 

1755 @property 

1756 def kind(self) -> str: 

1757 return "rest" 

1758 

1759 def close(self): 

1760 self._session.close() 

1761 

1762 

1763__all__ = ("SchemaServiceRestTransport",)