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

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

16from collections import OrderedDict 

17import functools 

18import re 

19from typing import ( 

20 Dict, 

21 Mapping, 

22 MutableMapping, 

23 MutableSequence, 

24 Optional, 

25 Sequence, 

26 Tuple, 

27 Type, 

28 Union, 

29) 

30 

31from google.pubsub_v1 import gapic_version as package_version 

32 

33from google.api_core.client_options import ClientOptions 

34from google.api_core import exceptions as core_exceptions 

35from google.api_core import gapic_v1 

36from google.api_core import retry as retries 

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

38from google.oauth2 import service_account # type: ignore 

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 

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

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

47from google.protobuf import timestamp_pb2 # type: ignore 

48from google.pubsub_v1.services.schema_service import pagers 

49from google.pubsub_v1.types import schema 

50from google.pubsub_v1.types import schema as gp_schema 

51from .transports.base import SchemaServiceTransport, DEFAULT_CLIENT_INFO 

52from .transports.grpc_asyncio import SchemaServiceGrpcAsyncIOTransport 

53from .client import SchemaServiceClient 

54 

55 

56class SchemaServiceAsyncClient: 

57 """Service for doing schema-related operations.""" 

58 

59 _client: SchemaServiceClient 

60 

61 DEFAULT_ENDPOINT = SchemaServiceClient.DEFAULT_ENDPOINT 

62 DEFAULT_MTLS_ENDPOINT = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT 

63 

64 schema_path = staticmethod(SchemaServiceClient.schema_path) 

65 parse_schema_path = staticmethod(SchemaServiceClient.parse_schema_path) 

66 common_billing_account_path = staticmethod( 

67 SchemaServiceClient.common_billing_account_path 

68 ) 

69 parse_common_billing_account_path = staticmethod( 

70 SchemaServiceClient.parse_common_billing_account_path 

71 ) 

72 common_folder_path = staticmethod(SchemaServiceClient.common_folder_path) 

73 parse_common_folder_path = staticmethod( 

74 SchemaServiceClient.parse_common_folder_path 

75 ) 

76 common_organization_path = staticmethod( 

77 SchemaServiceClient.common_organization_path 

78 ) 

79 parse_common_organization_path = staticmethod( 

80 SchemaServiceClient.parse_common_organization_path 

81 ) 

82 common_project_path = staticmethod(SchemaServiceClient.common_project_path) 

83 parse_common_project_path = staticmethod( 

84 SchemaServiceClient.parse_common_project_path 

85 ) 

86 common_location_path = staticmethod(SchemaServiceClient.common_location_path) 

87 parse_common_location_path = staticmethod( 

88 SchemaServiceClient.parse_common_location_path 

89 ) 

90 

91 @classmethod 

92 def from_service_account_info(cls, info: dict, *args, **kwargs): 

93 """Creates an instance of this client using the provided credentials 

94 info. 

95 

96 Args: 

97 info (dict): The service account private key info. 

98 args: Additional arguments to pass to the constructor. 

99 kwargs: Additional arguments to pass to the constructor. 

100 

101 Returns: 

102 SchemaServiceAsyncClient: The constructed client. 

103 """ 

104 return SchemaServiceClient.from_service_account_info.__func__(SchemaServiceAsyncClient, info, *args, **kwargs) # type: ignore 

105 

106 @classmethod 

107 def from_service_account_file(cls, filename: str, *args, **kwargs): 

108 """Creates an instance of this client using the provided credentials 

109 file. 

110 

111 Args: 

112 filename (str): The path to the service account private key json 

113 file. 

114 args: Additional arguments to pass to the constructor. 

115 kwargs: Additional arguments to pass to the constructor. 

116 

117 Returns: 

118 SchemaServiceAsyncClient: The constructed client. 

119 """ 

120 return SchemaServiceClient.from_service_account_file.__func__(SchemaServiceAsyncClient, filename, *args, **kwargs) # type: ignore 

121 

122 from_service_account_json = from_service_account_file 

123 

124 @classmethod 

125 def get_mtls_endpoint_and_cert_source( 

126 cls, client_options: Optional[ClientOptions] = None 

127 ): 

128 """Return the API endpoint and client cert source for mutual TLS. 

129 

130 The client cert source is determined in the following order: 

131 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the 

132 client cert source is None. 

133 (2) if `client_options.client_cert_source` is provided, use the provided one; if the 

134 default client cert source exists, use the default one; otherwise the client cert 

135 source is None. 

136 

137 The API endpoint is determined in the following order: 

138 (1) if `client_options.api_endpoint` if provided, use the provided one. 

139 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the 

140 default mTLS endpoint; if the environment variable is "never", use the default API 

141 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise 

142 use the default API endpoint. 

143 

144 More details can be found at https://google.aip.dev/auth/4114. 

145 

146 Args: 

147 client_options (google.api_core.client_options.ClientOptions): Custom options for the 

148 client. Only the `api_endpoint` and `client_cert_source` properties may be used 

149 in this method. 

150 

151 Returns: 

152 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the 

153 client cert source to use. 

154 

155 Raises: 

156 google.auth.exceptions.MutualTLSChannelError: If any errors happen. 

157 """ 

158 return SchemaServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

159 

160 @property 

161 def transport(self) -> SchemaServiceTransport: 

162 """Returns the transport used by the client instance. 

163 

164 Returns: 

165 SchemaServiceTransport: The transport used by the client instance. 

166 """ 

167 return self._client.transport 

168 

169 get_transport_class = functools.partial( 

170 type(SchemaServiceClient).get_transport_class, type(SchemaServiceClient) 

171 ) 

172 

173 def __init__( 

174 self, 

175 *, 

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

177 transport: Union[str, SchemaServiceTransport] = "grpc_asyncio", 

178 client_options: Optional[ClientOptions] = None, 

179 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

180 ) -> None: 

181 """Instantiates the schema service client. 

182 

183 Args: 

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

185 authorization credentials to attach to requests. These 

186 credentials identify the application to the service; if none 

187 are specified, the client will attempt to ascertain the 

188 credentials from the environment. 

189 transport (Union[str, ~.SchemaServiceTransport]): The 

190 transport to use. If set to None, a transport is chosen 

191 automatically. 

192 client_options (ClientOptions): Custom options for the client. It 

193 won't take effect if a ``transport`` instance is provided. 

194 (1) The ``api_endpoint`` property can be used to override the 

195 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

196 environment variable can also be used to override the endpoint: 

197 "always" (always use the default mTLS endpoint), "never" (always 

198 use the default regular endpoint) and "auto" (auto switch to the 

199 default mTLS endpoint if client certificate is present, this is 

200 the default value). However, the ``api_endpoint`` property takes 

201 precedence if provided. 

202 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

203 is "true", then the ``client_cert_source`` property can be used 

204 to provide client certificate for mutual TLS transport. If 

205 not provided, the default SSL client certificate will be used if 

206 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

207 set, no client certificate will be used. 

208 

209 Raises: 

210 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 

211 creation failed for any reason. 

212 """ 

213 self._client = SchemaServiceClient( 

214 credentials=credentials, 

215 transport=transport, 

216 client_options=client_options, 

217 client_info=client_info, 

218 ) 

219 

220 async def create_schema( 

221 self, 

222 request: Optional[Union[gp_schema.CreateSchemaRequest, dict]] = None, 

223 *, 

224 parent: Optional[str] = None, 

225 schema: Optional[gp_schema.Schema] = None, 

226 schema_id: Optional[str] = None, 

227 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

228 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

230 ) -> gp_schema.Schema: 

231 r"""Creates a schema. 

232 

233 .. code-block:: python 

234 

235 # This snippet has been automatically generated and should be regarded as a 

236 # code template only. 

237 # It will require modifications to work: 

238 # - It may require correct/in-range values for request initialization. 

239 # - It may require specifying regional endpoints when creating the service 

240 # client as shown in: 

241 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

242 from google import pubsub_v1 

243 

244 async def sample_create_schema(): 

245 # Create a client 

246 client = pubsub_v1.SchemaServiceAsyncClient() 

247 

248 # Initialize request argument(s) 

249 schema = pubsub_v1.Schema() 

250 schema.name = "name_value" 

251 

252 request = pubsub_v1.CreateSchemaRequest( 

253 parent="parent_value", 

254 schema=schema, 

255 ) 

256 

257 # Make the request 

258 response = await client.create_schema(request=request) 

259 

260 # Handle the response 

261 print(response) 

262 

263 Args: 

264 request (Optional[Union[google.pubsub_v1.types.CreateSchemaRequest, dict]]): 

265 The request object. Request for the CreateSchema method. 

266 parent (:class:`str`): 

267 Required. The name of the project in which to create the 

268 schema. Format is ``projects/{project-id}``. 

269 

270 This corresponds to the ``parent`` field 

271 on the ``request`` instance; if ``request`` is provided, this 

272 should not be set. 

273 schema (:class:`google.pubsub_v1.types.Schema`): 

274 Required. The schema object to create. 

275 

276 This schema's ``name`` parameter is ignored. The schema 

277 object returned by CreateSchema will have a ``name`` 

278 made using the given ``parent`` and ``schema_id``. 

279 

280 This corresponds to the ``schema`` field 

281 on the ``request`` instance; if ``request`` is provided, this 

282 should not be set. 

283 schema_id (:class:`str`): 

284 The ID to use for the schema, which will become the 

285 final component of the schema's resource name. 

286 

287 See 

288 https://cloud.google.com/pubsub/docs/admin#resource_names 

289 for resource name constraints. 

290 

291 This corresponds to the ``schema_id`` field 

292 on the ``request`` instance; if ``request`` is provided, this 

293 should not be set. 

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

295 should be retried. 

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

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

298 sent along with the request as metadata. 

299 

300 Returns: 

301 google.pubsub_v1.types.Schema: 

302 A schema resource. 

303 """ 

304 # Create or coerce a protobuf request object. 

305 # Quick check: If we got a request object, we should *not* have 

306 # gotten any keyword arguments that map to the request. 

307 has_flattened_params = any([parent, schema, schema_id]) 

308 if request is not None and has_flattened_params: 

309 raise ValueError( 

310 "If the `request` argument is set, then none of " 

311 "the individual field arguments should be set." 

312 ) 

313 

314 request = gp_schema.CreateSchemaRequest(request) 

315 

316 # If we have keyword arguments corresponding to fields on the 

317 # request, apply these. 

318 if parent is not None: 

319 request.parent = parent 

320 if schema is not None: 

321 request.schema = schema 

322 if schema_id is not None: 

323 request.schema_id = schema_id 

324 

325 # Wrap the RPC method; this adds retry and timeout information, 

326 # and friendly error handling. 

327 rpc = gapic_v1.method_async.wrap_method( 

328 self._client._transport.create_schema, 

329 default_retry=retries.Retry( 

330 initial=0.1, 

331 maximum=60.0, 

332 multiplier=1.3, 

333 predicate=retries.if_exception_type( 

334 core_exceptions.ServiceUnavailable, 

335 ), 

336 deadline=60.0, 

337 ), 

338 default_timeout=60.0, 

339 client_info=DEFAULT_CLIENT_INFO, 

340 ) 

341 

342 # Certain fields should be provided within the metadata header; 

343 # add these here. 

344 metadata = tuple(metadata) + ( 

345 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

346 ) 

347 

348 # Send the request. 

349 response = await rpc( 

350 request, 

351 retry=retry, 

352 timeout=timeout, 

353 metadata=metadata, 

354 ) 

355 

356 # Done; return the response. 

357 return response 

358 

359 async def get_schema( 

360 self, 

361 request: Optional[Union[schema.GetSchemaRequest, dict]] = None, 

362 *, 

363 name: Optional[str] = None, 

364 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

365 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

367 ) -> schema.Schema: 

368 r"""Gets a schema. 

369 

370 .. code-block:: python 

371 

372 # This snippet has been automatically generated and should be regarded as a 

373 # code template only. 

374 # It will require modifications to work: 

375 # - It may require correct/in-range values for request initialization. 

376 # - It may require specifying regional endpoints when creating the service 

377 # client as shown in: 

378 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

379 from google import pubsub_v1 

380 

381 async def sample_get_schema(): 

382 # Create a client 

383 client = pubsub_v1.SchemaServiceAsyncClient() 

384 

385 # Initialize request argument(s) 

386 request = pubsub_v1.GetSchemaRequest( 

387 name="name_value", 

388 ) 

389 

390 # Make the request 

391 response = await client.get_schema(request=request) 

392 

393 # Handle the response 

394 print(response) 

395 

396 Args: 

397 request (Optional[Union[google.pubsub_v1.types.GetSchemaRequest, dict]]): 

398 The request object. Request for the GetSchema method. 

399 name (:class:`str`): 

400 Required. The name of the schema to get. Format is 

401 ``projects/{project}/schemas/{schema}``. 

402 

403 This corresponds to the ``name`` field 

404 on the ``request`` instance; if ``request`` is provided, this 

405 should not be set. 

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

407 should be retried. 

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

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

410 sent along with the request as metadata. 

411 

412 Returns: 

413 google.pubsub_v1.types.Schema: 

414 A schema resource. 

415 """ 

416 # Create or coerce a protobuf request object. 

417 # Quick check: If we got a request object, we should *not* have 

418 # gotten any keyword arguments that map to the request. 

419 has_flattened_params = any([name]) 

420 if request is not None and has_flattened_params: 

421 raise ValueError( 

422 "If the `request` argument is set, then none of " 

423 "the individual field arguments should be set." 

424 ) 

425 

426 request = schema.GetSchemaRequest(request) 

427 

428 # If we have keyword arguments corresponding to fields on the 

429 # request, apply these. 

430 if name is not None: 

431 request.name = name 

432 

433 # Wrap the RPC method; this adds retry and timeout information, 

434 # and friendly error handling. 

435 rpc = gapic_v1.method_async.wrap_method( 

436 self._client._transport.get_schema, 

437 default_retry=retries.Retry( 

438 initial=0.1, 

439 maximum=60.0, 

440 multiplier=1.3, 

441 predicate=retries.if_exception_type( 

442 core_exceptions.ServiceUnavailable, 

443 ), 

444 deadline=60.0, 

445 ), 

446 default_timeout=60.0, 

447 client_info=DEFAULT_CLIENT_INFO, 

448 ) 

449 

450 # Certain fields should be provided within the metadata header; 

451 # add these here. 

452 metadata = tuple(metadata) + ( 

453 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

454 ) 

455 

456 # Send the request. 

457 response = await rpc( 

458 request, 

459 retry=retry, 

460 timeout=timeout, 

461 metadata=metadata, 

462 ) 

463 

464 # Done; return the response. 

465 return response 

466 

467 async def list_schemas( 

468 self, 

469 request: Optional[Union[schema.ListSchemasRequest, dict]] = None, 

470 *, 

471 parent: Optional[str] = None, 

472 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

473 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

475 ) -> pagers.ListSchemasAsyncPager: 

476 r"""Lists schemas in a project. 

477 

478 .. code-block:: python 

479 

480 # This snippet has been automatically generated and should be regarded as a 

481 # code template only. 

482 # It will require modifications to work: 

483 # - It may require correct/in-range values for request initialization. 

484 # - It may require specifying regional endpoints when creating the service 

485 # client as shown in: 

486 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

487 from google import pubsub_v1 

488 

489 async def sample_list_schemas(): 

490 # Create a client 

491 client = pubsub_v1.SchemaServiceAsyncClient() 

492 

493 # Initialize request argument(s) 

494 request = pubsub_v1.ListSchemasRequest( 

495 parent="parent_value", 

496 ) 

497 

498 # Make the request 

499 page_result = client.list_schemas(request=request) 

500 

501 # Handle the response 

502 async for response in page_result: 

503 print(response) 

504 

505 Args: 

506 request (Optional[Union[google.pubsub_v1.types.ListSchemasRequest, dict]]): 

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

508 parent (:class:`str`): 

509 Required. The name of the project in which to list 

510 schemas. Format is ``projects/{project-id}``. 

511 

512 This corresponds to the ``parent`` field 

513 on the ``request`` instance; if ``request`` is provided, this 

514 should not be set. 

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

516 should be retried. 

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

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

519 sent along with the request as metadata. 

520 

521 Returns: 

522 google.pubsub_v1.services.schema_service.pagers.ListSchemasAsyncPager: 

523 Response for the ListSchemas method. 

524 

525 Iterating over this object will yield results and 

526 resolve additional pages automatically. 

527 

528 """ 

529 # Create or coerce a protobuf request object. 

530 # Quick check: If we got a request object, we should *not* have 

531 # gotten any keyword arguments that map to the request. 

532 has_flattened_params = any([parent]) 

533 if request is not None and has_flattened_params: 

534 raise ValueError( 

535 "If the `request` argument is set, then none of " 

536 "the individual field arguments should be set." 

537 ) 

538 

539 request = schema.ListSchemasRequest(request) 

540 

541 # If we have keyword arguments corresponding to fields on the 

542 # request, apply these. 

543 if parent is not None: 

544 request.parent = parent 

545 

546 # Wrap the RPC method; this adds retry and timeout information, 

547 # and friendly error handling. 

548 rpc = gapic_v1.method_async.wrap_method( 

549 self._client._transport.list_schemas, 

550 default_retry=retries.Retry( 

551 initial=0.1, 

552 maximum=60.0, 

553 multiplier=1.3, 

554 predicate=retries.if_exception_type( 

555 core_exceptions.ServiceUnavailable, 

556 ), 

557 deadline=60.0, 

558 ), 

559 default_timeout=60.0, 

560 client_info=DEFAULT_CLIENT_INFO, 

561 ) 

562 

563 # Certain fields should be provided within the metadata header; 

564 # add these here. 

565 metadata = tuple(metadata) + ( 

566 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

567 ) 

568 

569 # Send the request. 

570 response = await rpc( 

571 request, 

572 retry=retry, 

573 timeout=timeout, 

574 metadata=metadata, 

575 ) 

576 

577 # This method is paged; wrap the response in a pager, which provides 

578 # an `__aiter__` convenience method. 

579 response = pagers.ListSchemasAsyncPager( 

580 method=rpc, 

581 request=request, 

582 response=response, 

583 metadata=metadata, 

584 ) 

585 

586 # Done; return the response. 

587 return response 

588 

589 async def list_schema_revisions( 

590 self, 

591 request: Optional[Union[schema.ListSchemaRevisionsRequest, dict]] = None, 

592 *, 

593 name: Optional[str] = None, 

594 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

595 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

597 ) -> pagers.ListSchemaRevisionsAsyncPager: 

598 r"""Lists all schema revisions for the named schema. 

599 

600 .. code-block:: python 

601 

602 # This snippet has been automatically generated and should be regarded as a 

603 # code template only. 

604 # It will require modifications to work: 

605 # - It may require correct/in-range values for request initialization. 

606 # - It may require specifying regional endpoints when creating the service 

607 # client as shown in: 

608 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

609 from google import pubsub_v1 

610 

611 async def sample_list_schema_revisions(): 

612 # Create a client 

613 client = pubsub_v1.SchemaServiceAsyncClient() 

614 

615 # Initialize request argument(s) 

616 request = pubsub_v1.ListSchemaRevisionsRequest( 

617 name="name_value", 

618 ) 

619 

620 # Make the request 

621 page_result = client.list_schema_revisions(request=request) 

622 

623 # Handle the response 

624 async for response in page_result: 

625 print(response) 

626 

627 Args: 

628 request (Optional[Union[google.pubsub_v1.types.ListSchemaRevisionsRequest, dict]]): 

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

630 name (:class:`str`): 

631 Required. The name of the schema to 

632 list revisions for. 

633 

634 This corresponds to the ``name`` field 

635 on the ``request`` instance; if ``request`` is provided, this 

636 should not be set. 

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

638 should be retried. 

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

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

641 sent along with the request as metadata. 

642 

643 Returns: 

644 google.pubsub_v1.services.schema_service.pagers.ListSchemaRevisionsAsyncPager: 

645 Response for the ListSchemaRevisions method. 

646 

647 Iterating over this object will yield results and 

648 resolve additional pages automatically. 

649 

650 """ 

651 # Create or coerce a protobuf request object. 

652 # Quick check: If we got a request object, we should *not* have 

653 # gotten any keyword arguments that map to the request. 

654 has_flattened_params = any([name]) 

655 if request is not None and has_flattened_params: 

656 raise ValueError( 

657 "If the `request` argument is set, then none of " 

658 "the individual field arguments should be set." 

659 ) 

660 

661 request = schema.ListSchemaRevisionsRequest(request) 

662 

663 # If we have keyword arguments corresponding to fields on the 

664 # request, apply these. 

665 if name is not None: 

666 request.name = name 

667 

668 # Wrap the RPC method; this adds retry and timeout information, 

669 # and friendly error handling. 

670 rpc = gapic_v1.method_async.wrap_method( 

671 self._client._transport.list_schema_revisions, 

672 default_retry=retries.Retry( 

673 initial=0.1, 

674 maximum=60.0, 

675 multiplier=1.3, 

676 predicate=retries.if_exception_type( 

677 core_exceptions.ServiceUnavailable, 

678 ), 

679 deadline=60.0, 

680 ), 

681 default_timeout=60.0, 

682 client_info=DEFAULT_CLIENT_INFO, 

683 ) 

684 

685 # Certain fields should be provided within the metadata header; 

686 # add these here. 

687 metadata = tuple(metadata) + ( 

688 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

689 ) 

690 

691 # Send the request. 

692 response = await rpc( 

693 request, 

694 retry=retry, 

695 timeout=timeout, 

696 metadata=metadata, 

697 ) 

698 

699 # This method is paged; wrap the response in a pager, which provides 

700 # an `__aiter__` convenience method. 

701 response = pagers.ListSchemaRevisionsAsyncPager( 

702 method=rpc, 

703 request=request, 

704 response=response, 

705 metadata=metadata, 

706 ) 

707 

708 # Done; return the response. 

709 return response 

710 

711 async def commit_schema( 

712 self, 

713 request: Optional[Union[gp_schema.CommitSchemaRequest, dict]] = None, 

714 *, 

715 name: Optional[str] = None, 

716 schema: Optional[gp_schema.Schema] = None, 

717 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

718 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

720 ) -> gp_schema.Schema: 

721 r"""Commits a new schema revision to an existing schema. 

722 

723 .. code-block:: python 

724 

725 # This snippet has been automatically generated and should be regarded as a 

726 # code template only. 

727 # It will require modifications to work: 

728 # - It may require correct/in-range values for request initialization. 

729 # - It may require specifying regional endpoints when creating the service 

730 # client as shown in: 

731 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

732 from google import pubsub_v1 

733 

734 async def sample_commit_schema(): 

735 # Create a client 

736 client = pubsub_v1.SchemaServiceAsyncClient() 

737 

738 # Initialize request argument(s) 

739 schema = pubsub_v1.Schema() 

740 schema.name = "name_value" 

741 

742 request = pubsub_v1.CommitSchemaRequest( 

743 name="name_value", 

744 schema=schema, 

745 ) 

746 

747 # Make the request 

748 response = await client.commit_schema(request=request) 

749 

750 # Handle the response 

751 print(response) 

752 

753 Args: 

754 request (Optional[Union[google.pubsub_v1.types.CommitSchemaRequest, dict]]): 

755 The request object. Request for CommitSchema method. 

756 name (:class:`str`): 

757 Required. The name of the schema we are revising. Format 

758 is ``projects/{project}/schemas/{schema}``. 

759 

760 This corresponds to the ``name`` field 

761 on the ``request`` instance; if ``request`` is provided, this 

762 should not be set. 

763 schema (:class:`google.pubsub_v1.types.Schema`): 

764 Required. The schema revision to 

765 commit. 

766 

767 This corresponds to the ``schema`` field 

768 on the ``request`` instance; if ``request`` is provided, this 

769 should not be set. 

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

771 should be retried. 

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

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

774 sent along with the request as metadata. 

775 

776 Returns: 

777 google.pubsub_v1.types.Schema: 

778 A schema resource. 

779 """ 

780 # Create or coerce a protobuf request object. 

781 # Quick check: If we got a request object, we should *not* have 

782 # gotten any keyword arguments that map to the request. 

783 has_flattened_params = any([name, schema]) 

784 if request is not None and has_flattened_params: 

785 raise ValueError( 

786 "If the `request` argument is set, then none of " 

787 "the individual field arguments should be set." 

788 ) 

789 

790 request = gp_schema.CommitSchemaRequest(request) 

791 

792 # If we have keyword arguments corresponding to fields on the 

793 # request, apply these. 

794 if name is not None: 

795 request.name = name 

796 if schema is not None: 

797 request.schema = schema 

798 

799 # Wrap the RPC method; this adds retry and timeout information, 

800 # and friendly error handling. 

801 rpc = gapic_v1.method_async.wrap_method( 

802 self._client._transport.commit_schema, 

803 default_retry=retries.Retry( 

804 initial=0.1, 

805 maximum=60.0, 

806 multiplier=1.3, 

807 predicate=retries.if_exception_type( 

808 core_exceptions.ServiceUnavailable, 

809 ), 

810 deadline=60.0, 

811 ), 

812 default_timeout=60.0, 

813 client_info=DEFAULT_CLIENT_INFO, 

814 ) 

815 

816 # Certain fields should be provided within the metadata header; 

817 # add these here. 

818 metadata = tuple(metadata) + ( 

819 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

820 ) 

821 

822 # Send the request. 

823 response = await rpc( 

824 request, 

825 retry=retry, 

826 timeout=timeout, 

827 metadata=metadata, 

828 ) 

829 

830 # Done; return the response. 

831 return response 

832 

833 async def rollback_schema( 

834 self, 

835 request: Optional[Union[schema.RollbackSchemaRequest, dict]] = None, 

836 *, 

837 name: Optional[str] = None, 

838 revision_id: Optional[str] = None, 

839 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

840 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

842 ) -> schema.Schema: 

843 r"""Creates a new schema revision that is a copy of the provided 

844 revision_id. 

845 

846 .. code-block:: python 

847 

848 # This snippet has been automatically generated and should be regarded as a 

849 # code template only. 

850 # It will require modifications to work: 

851 # - It may require correct/in-range values for request initialization. 

852 # - It may require specifying regional endpoints when creating the service 

853 # client as shown in: 

854 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

855 from google import pubsub_v1 

856 

857 async def sample_rollback_schema(): 

858 # Create a client 

859 client = pubsub_v1.SchemaServiceAsyncClient() 

860 

861 # Initialize request argument(s) 

862 request = pubsub_v1.RollbackSchemaRequest( 

863 name="name_value", 

864 revision_id="revision_id_value", 

865 ) 

866 

867 # Make the request 

868 response = await client.rollback_schema(request=request) 

869 

870 # Handle the response 

871 print(response) 

872 

873 Args: 

874 request (Optional[Union[google.pubsub_v1.types.RollbackSchemaRequest, dict]]): 

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

876 name (:class:`str`): 

877 Required. The schema being rolled 

878 back with revision id. 

879 

880 This corresponds to the ``name`` field 

881 on the ``request`` instance; if ``request`` is provided, this 

882 should not be set. 

883 revision_id (:class:`str`): 

884 Required. The revision ID to roll 

885 back to. It must be a revision of the 

886 same schema. 

887 Example: c7cfa2a8 

888 

889 This corresponds to the ``revision_id`` field 

890 on the ``request`` instance; if ``request`` is provided, this 

891 should not be set. 

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

893 should be retried. 

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

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

896 sent along with the request as metadata. 

897 

898 Returns: 

899 google.pubsub_v1.types.Schema: 

900 A schema resource. 

901 """ 

902 # Create or coerce a protobuf request object. 

903 # Quick check: If we got a request object, we should *not* have 

904 # gotten any keyword arguments that map to the request. 

905 has_flattened_params = any([name, revision_id]) 

906 if request is not None and has_flattened_params: 

907 raise ValueError( 

908 "If the `request` argument is set, then none of " 

909 "the individual field arguments should be set." 

910 ) 

911 

912 request = schema.RollbackSchemaRequest(request) 

913 

914 # If we have keyword arguments corresponding to fields on the 

915 # request, apply these. 

916 if name is not None: 

917 request.name = name 

918 if revision_id is not None: 

919 request.revision_id = revision_id 

920 

921 # Wrap the RPC method; this adds retry and timeout information, 

922 # and friendly error handling. 

923 rpc = gapic_v1.method_async.wrap_method( 

924 self._client._transport.rollback_schema, 

925 default_retry=retries.Retry( 

926 initial=0.1, 

927 maximum=60.0, 

928 multiplier=1.3, 

929 predicate=retries.if_exception_type( 

930 core_exceptions.ServiceUnavailable, 

931 ), 

932 deadline=60.0, 

933 ), 

934 default_timeout=60.0, 

935 client_info=DEFAULT_CLIENT_INFO, 

936 ) 

937 

938 # Certain fields should be provided within the metadata header; 

939 # add these here. 

940 metadata = tuple(metadata) + ( 

941 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

942 ) 

943 

944 # Send the request. 

945 response = await rpc( 

946 request, 

947 retry=retry, 

948 timeout=timeout, 

949 metadata=metadata, 

950 ) 

951 

952 # Done; return the response. 

953 return response 

954 

955 async def delete_schema_revision( 

956 self, 

957 request: Optional[Union[schema.DeleteSchemaRevisionRequest, dict]] = None, 

958 *, 

959 name: Optional[str] = None, 

960 revision_id: Optional[str] = None, 

961 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

962 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

964 ) -> schema.Schema: 

965 r"""Deletes a specific schema revision. 

966 

967 .. code-block:: python 

968 

969 # This snippet has been automatically generated and should be regarded as a 

970 # code template only. 

971 # It will require modifications to work: 

972 # - It may require correct/in-range values for request initialization. 

973 # - It may require specifying regional endpoints when creating the service 

974 # client as shown in: 

975 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

976 from google import pubsub_v1 

977 

978 async def sample_delete_schema_revision(): 

979 # Create a client 

980 client = pubsub_v1.SchemaServiceAsyncClient() 

981 

982 # Initialize request argument(s) 

983 request = pubsub_v1.DeleteSchemaRevisionRequest( 

984 name="name_value", 

985 ) 

986 

987 # Make the request 

988 response = await client.delete_schema_revision(request=request) 

989 

990 # Handle the response 

991 print(response) 

992 

993 Args: 

994 request (Optional[Union[google.pubsub_v1.types.DeleteSchemaRevisionRequest, dict]]): 

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

996 name (:class:`str`): 

997 Required. The name of the schema revision to be deleted, 

998 with a revision ID explicitly included. 

999 

1000 Example: ``projects/123/schemas/my-schema@c7cfa2a8`` 

1001 

1002 This corresponds to the ``name`` field 

1003 on the ``request`` instance; if ``request`` is provided, this 

1004 should not be set. 

1005 revision_id (:class:`str`): 

1006 Optional. This field is deprecated and should not be 

1007 used for specifying the revision ID. The revision ID 

1008 should be specified via the ``name`` parameter. 

1009 

1010 This corresponds to the ``revision_id`` field 

1011 on the ``request`` instance; if ``request`` is provided, this 

1012 should not be set. 

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

1014 should be retried. 

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

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

1017 sent along with the request as metadata. 

1018 

1019 Returns: 

1020 google.pubsub_v1.types.Schema: 

1021 A schema resource. 

1022 """ 

1023 # Create or coerce a protobuf request object. 

1024 # Quick check: If we got a request object, we should *not* have 

1025 # gotten any keyword arguments that map to the request. 

1026 has_flattened_params = any([name, revision_id]) 

1027 if request is not None and has_flattened_params: 

1028 raise ValueError( 

1029 "If the `request` argument is set, then none of " 

1030 "the individual field arguments should be set." 

1031 ) 

1032 

1033 request = schema.DeleteSchemaRevisionRequest(request) 

1034 

1035 # If we have keyword arguments corresponding to fields on the 

1036 # request, apply these. 

1037 if name is not None: 

1038 request.name = name 

1039 if revision_id is not None: 

1040 request.revision_id = revision_id 

1041 

1042 # Wrap the RPC method; this adds retry and timeout information, 

1043 # and friendly error handling. 

1044 rpc = gapic_v1.method_async.wrap_method( 

1045 self._client._transport.delete_schema_revision, 

1046 default_retry=retries.Retry( 

1047 initial=0.1, 

1048 maximum=60.0, 

1049 multiplier=1.3, 

1050 predicate=retries.if_exception_type( 

1051 core_exceptions.ServiceUnavailable, 

1052 ), 

1053 deadline=60.0, 

1054 ), 

1055 default_timeout=60.0, 

1056 client_info=DEFAULT_CLIENT_INFO, 

1057 ) 

1058 

1059 # Certain fields should be provided within the metadata header; 

1060 # add these here. 

1061 metadata = tuple(metadata) + ( 

1062 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1063 ) 

1064 

1065 # Send the request. 

1066 response = await rpc( 

1067 request, 

1068 retry=retry, 

1069 timeout=timeout, 

1070 metadata=metadata, 

1071 ) 

1072 

1073 # Done; return the response. 

1074 return response 

1075 

1076 async def delete_schema( 

1077 self, 

1078 request: Optional[Union[schema.DeleteSchemaRequest, dict]] = None, 

1079 *, 

1080 name: Optional[str] = None, 

1081 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1082 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

1084 ) -> None: 

1085 r"""Deletes a schema. 

1086 

1087 .. code-block:: python 

1088 

1089 # This snippet has been automatically generated and should be regarded as a 

1090 # code template only. 

1091 # It will require modifications to work: 

1092 # - It may require correct/in-range values for request initialization. 

1093 # - It may require specifying regional endpoints when creating the service 

1094 # client as shown in: 

1095 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1096 from google import pubsub_v1 

1097 

1098 async def sample_delete_schema(): 

1099 # Create a client 

1100 client = pubsub_v1.SchemaServiceAsyncClient() 

1101 

1102 # Initialize request argument(s) 

1103 request = pubsub_v1.DeleteSchemaRequest( 

1104 name="name_value", 

1105 ) 

1106 

1107 # Make the request 

1108 await client.delete_schema(request=request) 

1109 

1110 Args: 

1111 request (Optional[Union[google.pubsub_v1.types.DeleteSchemaRequest, dict]]): 

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

1113 name (:class:`str`): 

1114 Required. Name of the schema to delete. Format is 

1115 ``projects/{project}/schemas/{schema}``. 

1116 

1117 This corresponds to the ``name`` field 

1118 on the ``request`` instance; if ``request`` is provided, this 

1119 should not be set. 

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

1121 should be retried. 

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

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

1124 sent along with the request as metadata. 

1125 """ 

1126 # Create or coerce a protobuf request object. 

1127 # Quick check: If we got a request object, we should *not* have 

1128 # gotten any keyword arguments that map to the request. 

1129 has_flattened_params = any([name]) 

1130 if request is not None and has_flattened_params: 

1131 raise ValueError( 

1132 "If the `request` argument is set, then none of " 

1133 "the individual field arguments should be set." 

1134 ) 

1135 

1136 request = schema.DeleteSchemaRequest(request) 

1137 

1138 # If we have keyword arguments corresponding to fields on the 

1139 # request, apply these. 

1140 if name is not None: 

1141 request.name = name 

1142 

1143 # Wrap the RPC method; this adds retry and timeout information, 

1144 # and friendly error handling. 

1145 rpc = gapic_v1.method_async.wrap_method( 

1146 self._client._transport.delete_schema, 

1147 default_retry=retries.Retry( 

1148 initial=0.1, 

1149 maximum=60.0, 

1150 multiplier=1.3, 

1151 predicate=retries.if_exception_type( 

1152 core_exceptions.ServiceUnavailable, 

1153 ), 

1154 deadline=60.0, 

1155 ), 

1156 default_timeout=60.0, 

1157 client_info=DEFAULT_CLIENT_INFO, 

1158 ) 

1159 

1160 # Certain fields should be provided within the metadata header; 

1161 # add these here. 

1162 metadata = tuple(metadata) + ( 

1163 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1164 ) 

1165 

1166 # Send the request. 

1167 await rpc( 

1168 request, 

1169 retry=retry, 

1170 timeout=timeout, 

1171 metadata=metadata, 

1172 ) 

1173 

1174 async def validate_schema( 

1175 self, 

1176 request: Optional[Union[gp_schema.ValidateSchemaRequest, dict]] = None, 

1177 *, 

1178 parent: Optional[str] = None, 

1179 schema: Optional[gp_schema.Schema] = None, 

1180 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1181 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

1183 ) -> gp_schema.ValidateSchemaResponse: 

1184 r"""Validates a schema. 

1185 

1186 .. code-block:: python 

1187 

1188 # This snippet has been automatically generated and should be regarded as a 

1189 # code template only. 

1190 # It will require modifications to work: 

1191 # - It may require correct/in-range values for request initialization. 

1192 # - It may require specifying regional endpoints when creating the service 

1193 # client as shown in: 

1194 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1195 from google import pubsub_v1 

1196 

1197 async def sample_validate_schema(): 

1198 # Create a client 

1199 client = pubsub_v1.SchemaServiceAsyncClient() 

1200 

1201 # Initialize request argument(s) 

1202 schema = pubsub_v1.Schema() 

1203 schema.name = "name_value" 

1204 

1205 request = pubsub_v1.ValidateSchemaRequest( 

1206 parent="parent_value", 

1207 schema=schema, 

1208 ) 

1209 

1210 # Make the request 

1211 response = await client.validate_schema(request=request) 

1212 

1213 # Handle the response 

1214 print(response) 

1215 

1216 Args: 

1217 request (Optional[Union[google.pubsub_v1.types.ValidateSchemaRequest, dict]]): 

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

1219 parent (:class:`str`): 

1220 Required. The name of the project in which to validate 

1221 schemas. Format is ``projects/{project-id}``. 

1222 

1223 This corresponds to the ``parent`` field 

1224 on the ``request`` instance; if ``request`` is provided, this 

1225 should not be set. 

1226 schema (:class:`google.pubsub_v1.types.Schema`): 

1227 Required. The schema object to 

1228 validate. 

1229 

1230 This corresponds to the ``schema`` field 

1231 on the ``request`` instance; if ``request`` is provided, this 

1232 should not be set. 

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

1234 should be retried. 

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

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

1237 sent along with the request as metadata. 

1238 

1239 Returns: 

1240 google.pubsub_v1.types.ValidateSchemaResponse: 

1241 Response for the ValidateSchema method. 

1242 Empty for now. 

1243 

1244 """ 

1245 # Create or coerce a protobuf request object. 

1246 # Quick check: If we got a request object, we should *not* have 

1247 # gotten any keyword arguments that map to the request. 

1248 has_flattened_params = any([parent, schema]) 

1249 if request is not None and has_flattened_params: 

1250 raise ValueError( 

1251 "If the `request` argument is set, then none of " 

1252 "the individual field arguments should be set." 

1253 ) 

1254 

1255 request = gp_schema.ValidateSchemaRequest(request) 

1256 

1257 # If we have keyword arguments corresponding to fields on the 

1258 # request, apply these. 

1259 if parent is not None: 

1260 request.parent = parent 

1261 if schema is not None: 

1262 request.schema = schema 

1263 

1264 # Wrap the RPC method; this adds retry and timeout information, 

1265 # and friendly error handling. 

1266 rpc = gapic_v1.method_async.wrap_method( 

1267 self._client._transport.validate_schema, 

1268 default_retry=retries.Retry( 

1269 initial=0.1, 

1270 maximum=60.0, 

1271 multiplier=1.3, 

1272 predicate=retries.if_exception_type( 

1273 core_exceptions.ServiceUnavailable, 

1274 ), 

1275 deadline=60.0, 

1276 ), 

1277 default_timeout=60.0, 

1278 client_info=DEFAULT_CLIENT_INFO, 

1279 ) 

1280 

1281 # Certain fields should be provided within the metadata header; 

1282 # add these here. 

1283 metadata = tuple(metadata) + ( 

1284 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

1285 ) 

1286 

1287 # Send the request. 

1288 response = await rpc( 

1289 request, 

1290 retry=retry, 

1291 timeout=timeout, 

1292 metadata=metadata, 

1293 ) 

1294 

1295 # Done; return the response. 

1296 return response 

1297 

1298 async def validate_message( 

1299 self, 

1300 request: Optional[Union[schema.ValidateMessageRequest, dict]] = None, 

1301 *, 

1302 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1303 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

1305 ) -> schema.ValidateMessageResponse: 

1306 r"""Validates a message against a schema. 

1307 

1308 .. code-block:: python 

1309 

1310 # This snippet has been automatically generated and should be regarded as a 

1311 # code template only. 

1312 # It will require modifications to work: 

1313 # - It may require correct/in-range values for request initialization. 

1314 # - It may require specifying regional endpoints when creating the service 

1315 # client as shown in: 

1316 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1317 from google import pubsub_v1 

1318 

1319 async def sample_validate_message(): 

1320 # Create a client 

1321 client = pubsub_v1.SchemaServiceAsyncClient() 

1322 

1323 # Initialize request argument(s) 

1324 request = pubsub_v1.ValidateMessageRequest( 

1325 name="name_value", 

1326 parent="parent_value", 

1327 ) 

1328 

1329 # Make the request 

1330 response = await client.validate_message(request=request) 

1331 

1332 # Handle the response 

1333 print(response) 

1334 

1335 Args: 

1336 request (Optional[Union[google.pubsub_v1.types.ValidateMessageRequest, dict]]): 

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

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

1339 should be retried. 

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

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

1342 sent along with the request as metadata. 

1343 

1344 Returns: 

1345 google.pubsub_v1.types.ValidateMessageResponse: 

1346 Response for the ValidateMessage method. 

1347 Empty for now. 

1348 

1349 """ 

1350 # Create or coerce a protobuf request object. 

1351 request = schema.ValidateMessageRequest(request) 

1352 

1353 # Wrap the RPC method; this adds retry and timeout information, 

1354 # and friendly error handling. 

1355 rpc = gapic_v1.method_async.wrap_method( 

1356 self._client._transport.validate_message, 

1357 default_retry=retries.Retry( 

1358 initial=0.1, 

1359 maximum=60.0, 

1360 multiplier=1.3, 

1361 predicate=retries.if_exception_type( 

1362 core_exceptions.ServiceUnavailable, 

1363 ), 

1364 deadline=60.0, 

1365 ), 

1366 default_timeout=60.0, 

1367 client_info=DEFAULT_CLIENT_INFO, 

1368 ) 

1369 

1370 # Certain fields should be provided within the metadata header; 

1371 # add these here. 

1372 metadata = tuple(metadata) + ( 

1373 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

1374 ) 

1375 

1376 # Send the request. 

1377 response = await rpc( 

1378 request, 

1379 retry=retry, 

1380 timeout=timeout, 

1381 metadata=metadata, 

1382 ) 

1383 

1384 # Done; return the response. 

1385 return response 

1386 

1387 async def set_iam_policy( 

1388 self, 

1389 request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, 

1390 *, 

1391 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1392 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

1394 ) -> policy_pb2.Policy: 

1395 r"""Sets the IAM access control policy on the specified function. 

1396 

1397 Replaces any existing policy. 

1398 

1399 Args: 

1400 request (:class:`~.policy_pb2.SetIamPolicyRequest`): 

1401 The request object. Request message for `SetIamPolicy` 

1402 method. 

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

1404 should be retried. 

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

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

1407 sent along with the request as metadata. 

1408 Returns: 

1409 ~.policy_pb2.Policy: 

1410 Defines an Identity and Access Management (IAM) policy. 

1411 It is used to specify access control policies for Cloud 

1412 Platform resources. 

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

1414 ``binding`` binds one or more ``members`` to a single 

1415 ``role``. Members can be user accounts, service 

1416 accounts, Google groups, and domains (such as G Suite). 

1417 A ``role`` is a named list of permissions (defined by 

1418 IAM or configured by users). A ``binding`` can 

1419 optionally specify a ``condition``, which is a logic 

1420 expression that further constrains the role binding 

1421 based on attributes about the request and/or target 

1422 resource. 

1423 

1424 **JSON Example** 

1425 

1426 :: 

1427 { 

1428 "bindings": [ 

1429 { 

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

1431 "members": [ 

1432 "user:mike@example.com", 

1433 "group:admins@example.com", 

1434 "domain:google.com", 

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

1436 ] 

1437 }, 

1438 { 

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

1440 "members": ["user:eve@example.com"], 

1441 "condition": { 

1442 "title": "expirable access", 

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

1444 "expression": "request.time < 

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

1446 } 

1447 } 

1448 ] 

1449 } 

1450 

1451 **YAML Example** 

1452 

1453 :: 

1454 

1455 bindings: 

1456 - members: 

1457 - user:mike@example.com 

1458 - group:admins@example.com 

1459 - domain:google.com 

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

1461 role: roles/resourcemanager.organizationAdmin 

1462 - members: 

1463 - user:eve@example.com 

1464 role: roles/resourcemanager.organizationViewer 

1465 condition: 

1466 title: expirable access 

1467 description: Does not grant access after Sep 2020 

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

1469 

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

1471 developer's 

1472 guide <https://cloud.google.com/iam/docs>`__. 

1473 """ 

1474 # Create or coerce a protobuf request object. 

1475 

1476 # The request isn't a proto-plus wrapped type, 

1477 # so it must be constructed via keyword expansion. 

1478 if isinstance(request, dict): 

1479 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1480 

1481 # Wrap the RPC method; this adds retry and timeout information, 

1482 # and friendly error handling. 

1483 rpc = gapic_v1.method_async.wrap_method( 

1484 self._client._transport.set_iam_policy, 

1485 default_timeout=None, 

1486 client_info=DEFAULT_CLIENT_INFO, 

1487 ) 

1488 

1489 # Certain fields should be provided within the metadata header; 

1490 # add these here. 

1491 metadata = tuple(metadata) + ( 

1492 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1493 ) 

1494 

1495 # Send the request. 

1496 response = await rpc( 

1497 request, 

1498 retry=retry, 

1499 timeout=timeout, 

1500 metadata=metadata, 

1501 ) 

1502 

1503 # Done; return the response. 

1504 return response 

1505 

1506 async def get_iam_policy( 

1507 self, 

1508 request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, 

1509 *, 

1510 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1511 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

1513 ) -> policy_pb2.Policy: 

1514 r"""Gets the IAM access control policy for a function. 

1515 

1516 Returns an empty policy if the function exists and does 

1517 not have a policy set. 

1518 

1519 Args: 

1520 request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): 

1521 The request object. Request message for `GetIamPolicy` 

1522 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 Returns: 

1529 ~.policy_pb2.Policy: 

1530 Defines an Identity and Access Management (IAM) policy. 

1531 It is used to specify access control policies for Cloud 

1532 Platform resources. 

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

1534 ``binding`` binds one or more ``members`` to a single 

1535 ``role``. Members can be user accounts, service 

1536 accounts, Google groups, and domains (such as G Suite). 

1537 A ``role`` is a named list of permissions (defined by 

1538 IAM or configured by users). A ``binding`` can 

1539 optionally specify a ``condition``, which is a logic 

1540 expression that further constrains the role binding 

1541 based on attributes about the request and/or target 

1542 resource. 

1543 

1544 **JSON Example** 

1545 

1546 :: 

1547 

1548 { 

1549 "bindings": [ 

1550 { 

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

1552 "members": [ 

1553 "user:mike@example.com", 

1554 "group:admins@example.com", 

1555 "domain:google.com", 

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

1557 ] 

1558 }, 

1559 { 

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

1561 "members": ["user:eve@example.com"], 

1562 "condition": { 

1563 "title": "expirable access", 

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

1565 "expression": "request.time < 

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

1567 } 

1568 } 

1569 ] 

1570 } 

1571 

1572 **YAML Example** 

1573 

1574 :: 

1575 

1576 bindings: 

1577 - members: 

1578 - user:mike@example.com 

1579 - group:admins@example.com 

1580 - domain:google.com 

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

1582 role: roles/resourcemanager.organizationAdmin 

1583 - members: 

1584 - user:eve@example.com 

1585 role: roles/resourcemanager.organizationViewer 

1586 condition: 

1587 title: expirable access 

1588 description: Does not grant access after Sep 2020 

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

1590 

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

1592 developer's 

1593 guide <https://cloud.google.com/iam/docs>`__. 

1594 """ 

1595 # Create or coerce a protobuf request object. 

1596 

1597 # The request isn't a proto-plus wrapped type, 

1598 # so it must be constructed via keyword expansion. 

1599 if isinstance(request, dict): 

1600 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1601 

1602 # Wrap the RPC method; this adds retry and timeout information, 

1603 # and friendly error handling. 

1604 rpc = gapic_v1.method_async.wrap_method( 

1605 self._client._transport.get_iam_policy, 

1606 default_timeout=None, 

1607 client_info=DEFAULT_CLIENT_INFO, 

1608 ) 

1609 

1610 # Certain fields should be provided within the metadata header; 

1611 # add these here. 

1612 metadata = tuple(metadata) + ( 

1613 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1614 ) 

1615 

1616 # Send the request. 

1617 response = await rpc( 

1618 request, 

1619 retry=retry, 

1620 timeout=timeout, 

1621 metadata=metadata, 

1622 ) 

1623 

1624 # Done; return the response. 

1625 return response 

1626 

1627 async def test_iam_permissions( 

1628 self, 

1629 request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, 

1630 *, 

1631 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1632 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

1634 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1635 r"""Tests the specified permissions against the IAM access control 

1636 policy for a function. 

1637 

1638 If the function does not exist, this will 

1639 return an empty set of permissions, not a NOT_FOUND error. 

1640 

1641 Args: 

1642 request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): 

1643 The request object. Request message for 

1644 `TestIamPermissions` method. 

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

1646 should be retried. 

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

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

1649 sent along with the request as metadata. 

1650 Returns: 

1651 ~iam_policy_pb2.PolicyTestIamPermissionsResponse: 

1652 Response message for ``TestIamPermissions`` method. 

1653 """ 

1654 # Create or coerce a protobuf request object. 

1655 

1656 # The request isn't a proto-plus wrapped type, 

1657 # so it must be constructed via keyword expansion. 

1658 if isinstance(request, dict): 

1659 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1660 

1661 # Wrap the RPC method; this adds retry and timeout information, 

1662 # and friendly error handling. 

1663 rpc = gapic_v1.method_async.wrap_method( 

1664 self._client._transport.test_iam_permissions, 

1665 default_timeout=None, 

1666 client_info=DEFAULT_CLIENT_INFO, 

1667 ) 

1668 

1669 # Certain fields should be provided within the metadata header; 

1670 # add these here. 

1671 metadata = tuple(metadata) + ( 

1672 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1673 ) 

1674 

1675 # Send the request. 

1676 response = await rpc( 

1677 request, 

1678 retry=retry, 

1679 timeout=timeout, 

1680 metadata=metadata, 

1681 ) 

1682 

1683 # Done; return the response. 

1684 return response 

1685 

1686 async def __aenter__(self): 

1687 return self 

1688 

1689 async def __aexit__(self, exc_type, exc, tb): 

1690 await self.transport.close() 

1691 

1692 

1693DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1694 client_library_version=package_version.__version__ 

1695) 

1696 

1697 

1698__all__ = ("SchemaServiceAsyncClient",)