1# -*- coding: utf-8 -*-
2# Copyright 2024 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#
16import logging as std_logging
17from collections import OrderedDict
18import re
19from typing import (
20 Dict,
21 Callable,
22 Mapping,
23 MutableMapping,
24 MutableSequence,
25 Optional,
26 Sequence,
27 Tuple,
28 Type,
29 Union,
30)
31
32from google.pubsub_v1 import gapic_version as package_version
33
34from google.api_core.client_options import ClientOptions
35from google.api_core import exceptions as core_exceptions
36from google.api_core import gapic_v1
37from google.api_core import retry_async as retries
38from google.auth import credentials as ga_credentials # type: ignore
39from google.oauth2 import service_account # type: ignore
40
41
42try:
43 OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
44except AttributeError: # pragma: NO COVER
45 OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
46
47from google.iam.v1 import iam_policy_pb2 # type: ignore
48from google.iam.v1 import policy_pb2 # type: ignore
49from google.protobuf import timestamp_pb2 # type: ignore
50from google.pubsub_v1.services.schema_service import pagers
51from google.pubsub_v1.types import schema
52from google.pubsub_v1.types import schema as gp_schema
53from .transports.base import SchemaServiceTransport, DEFAULT_CLIENT_INFO
54from .transports.grpc_asyncio import SchemaServiceGrpcAsyncIOTransport
55from .client import SchemaServiceClient
56
57try:
58 from google.api_core import client_logging # type: ignore
59
60 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
61except ImportError: # pragma: NO COVER
62 CLIENT_LOGGING_SUPPORTED = False
63
64_LOGGER = std_logging.getLogger(__name__)
65
66
67class SchemaServiceAsyncClient:
68 """Service for doing schema-related operations."""
69
70 _client: SchemaServiceClient
71
72 # Copy defaults from the synchronous client for use here.
73 # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
74 DEFAULT_ENDPOINT = SchemaServiceClient.DEFAULT_ENDPOINT
75 DEFAULT_MTLS_ENDPOINT = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT
76 _DEFAULT_ENDPOINT_TEMPLATE = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE
77 _DEFAULT_UNIVERSE = SchemaServiceClient._DEFAULT_UNIVERSE
78
79 schema_path = staticmethod(SchemaServiceClient.schema_path)
80 parse_schema_path = staticmethod(SchemaServiceClient.parse_schema_path)
81 common_billing_account_path = staticmethod(
82 SchemaServiceClient.common_billing_account_path
83 )
84 parse_common_billing_account_path = staticmethod(
85 SchemaServiceClient.parse_common_billing_account_path
86 )
87 common_folder_path = staticmethod(SchemaServiceClient.common_folder_path)
88 parse_common_folder_path = staticmethod(
89 SchemaServiceClient.parse_common_folder_path
90 )
91 common_organization_path = staticmethod(
92 SchemaServiceClient.common_organization_path
93 )
94 parse_common_organization_path = staticmethod(
95 SchemaServiceClient.parse_common_organization_path
96 )
97 common_project_path = staticmethod(SchemaServiceClient.common_project_path)
98 parse_common_project_path = staticmethod(
99 SchemaServiceClient.parse_common_project_path
100 )
101 common_location_path = staticmethod(SchemaServiceClient.common_location_path)
102 parse_common_location_path = staticmethod(
103 SchemaServiceClient.parse_common_location_path
104 )
105
106 @classmethod
107 def from_service_account_info(cls, info: dict, *args, **kwargs):
108 """Creates an instance of this client using the provided credentials
109 info.
110
111 Args:
112 info (dict): The service account private key info.
113 args: Additional arguments to pass to the constructor.
114 kwargs: Additional arguments to pass to the constructor.
115
116 Returns:
117 SchemaServiceAsyncClient: The constructed client.
118 """
119 return SchemaServiceClient.from_service_account_info.__func__(SchemaServiceAsyncClient, info, *args, **kwargs) # type: ignore
120
121 @classmethod
122 def from_service_account_file(cls, filename: str, *args, **kwargs):
123 """Creates an instance of this client using the provided credentials
124 file.
125
126 Args:
127 filename (str): The path to the service account private key json
128 file.
129 args: Additional arguments to pass to the constructor.
130 kwargs: Additional arguments to pass to the constructor.
131
132 Returns:
133 SchemaServiceAsyncClient: The constructed client.
134 """
135 return SchemaServiceClient.from_service_account_file.__func__(SchemaServiceAsyncClient, filename, *args, **kwargs) # type: ignore
136
137 from_service_account_json = from_service_account_file
138
139 @classmethod
140 def get_mtls_endpoint_and_cert_source(
141 cls, client_options: Optional[ClientOptions] = None
142 ):
143 """Return the API endpoint and client cert source for mutual TLS.
144
145 The client cert source is determined in the following order:
146 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
147 client cert source is None.
148 (2) if `client_options.client_cert_source` is provided, use the provided one; if the
149 default client cert source exists, use the default one; otherwise the client cert
150 source is None.
151
152 The API endpoint is determined in the following order:
153 (1) if `client_options.api_endpoint` if provided, use the provided one.
154 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
155 default mTLS endpoint; if the environment variable is "never", use the default API
156 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
157 use the default API endpoint.
158
159 More details can be found at https://google.aip.dev/auth/4114.
160
161 Args:
162 client_options (google.api_core.client_options.ClientOptions): Custom options for the
163 client. Only the `api_endpoint` and `client_cert_source` properties may be used
164 in this method.
165
166 Returns:
167 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
168 client cert source to use.
169
170 Raises:
171 google.auth.exceptions.MutualTLSChannelError: If any errors happen.
172 """
173 return SchemaServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
174
175 @property
176 def transport(self) -> SchemaServiceTransport:
177 """Returns the transport used by the client instance.
178
179 Returns:
180 SchemaServiceTransport: The transport used by the client instance.
181 """
182 return self._client.transport
183
184 @property
185 def api_endpoint(self):
186 """Return the API endpoint used by the client instance.
187
188 Returns:
189 str: The API endpoint used by the client instance.
190 """
191 return self._client._api_endpoint
192
193 @property
194 def universe_domain(self) -> str:
195 """Return the universe domain used by the client instance.
196
197 Returns:
198 str: The universe domain used
199 by the client instance.
200 """
201 return self._client._universe_domain
202
203 get_transport_class = SchemaServiceClient.get_transport_class
204
205 def __init__(
206 self,
207 *,
208 credentials: Optional[ga_credentials.Credentials] = None,
209 transport: Optional[
210 Union[str, SchemaServiceTransport, Callable[..., SchemaServiceTransport]]
211 ] = "grpc_asyncio",
212 client_options: Optional[ClientOptions] = None,
213 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
214 ) -> None:
215 """Instantiates the schema service async client.
216
217 Args:
218 credentials (Optional[google.auth.credentials.Credentials]): The
219 authorization credentials to attach to requests. These
220 credentials identify the application to the service; if none
221 are specified, the client will attempt to ascertain the
222 credentials from the environment.
223 transport (Optional[Union[str,SchemaServiceTransport,Callable[..., SchemaServiceTransport]]]):
224 The transport to use, or a Callable that constructs and returns a new transport to use.
225 If a Callable is given, it will be called with the same set of initialization
226 arguments as used in the SchemaServiceTransport constructor.
227 If set to None, a transport is chosen automatically.
228 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
229 Custom options for the client.
230
231 1. The ``api_endpoint`` property can be used to override the
232 default endpoint provided by the client when ``transport`` is
233 not explicitly provided. Only if this property is not set and
234 ``transport`` was not explicitly provided, the endpoint is
235 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
236 variable, which have one of the following values:
237 "always" (always use the default mTLS endpoint), "never" (always
238 use the default regular endpoint) and "auto" (auto-switch to the
239 default mTLS endpoint if client certificate is present; this is
240 the default value).
241
242 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
243 is "true", then the ``client_cert_source`` property can be used
244 to provide a client certificate for mTLS transport. If
245 not provided, the default SSL client certificate will be used if
246 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
247 set, no client certificate will be used.
248
249 3. The ``universe_domain`` property can be used to override the
250 default "googleapis.com" universe. Note that ``api_endpoint``
251 property still takes precedence; and ``universe_domain`` is
252 currently not supported for mTLS.
253
254 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
255 The client info used to send a user-agent string along with
256 API requests. If ``None``, then default info will be used.
257 Generally, you only need to set this if you're developing
258 your own client library.
259
260 Raises:
261 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
262 creation failed for any reason.
263 """
264 self._client = SchemaServiceClient(
265 credentials=credentials,
266 transport=transport,
267 client_options=client_options,
268 client_info=client_info,
269 )
270
271 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
272 std_logging.DEBUG
273 ): # pragma: NO COVER
274 _LOGGER.debug(
275 "Created client `google.pubsub_v1.SchemaServiceAsyncClient`.",
276 extra={
277 "serviceName": "google.pubsub.v1.SchemaService",
278 "universeDomain": getattr(
279 self._client._transport._credentials, "universe_domain", ""
280 ),
281 "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
282 "credentialsInfo": getattr(
283 self.transport._credentials, "get_cred_info", lambda: None
284 )(),
285 }
286 if hasattr(self._client._transport, "_credentials")
287 else {
288 "serviceName": "google.pubsub.v1.SchemaService",
289 "credentialsType": None,
290 },
291 )
292
293 async def create_schema(
294 self,
295 request: Optional[Union[gp_schema.CreateSchemaRequest, dict]] = None,
296 *,
297 parent: Optional[str] = None,
298 schema: Optional[gp_schema.Schema] = None,
299 schema_id: Optional[str] = None,
300 retry: OptionalRetry = gapic_v1.method.DEFAULT,
301 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
302 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
303 ) -> gp_schema.Schema:
304 r"""Creates a schema.
305
306 .. code-block:: python
307
308 # This snippet has been automatically generated and should be regarded as a
309 # code template only.
310 # It will require modifications to work:
311 # - It may require correct/in-range values for request initialization.
312 # - It may require specifying regional endpoints when creating the service
313 # client as shown in:
314 # https://googleapis.dev/python/google-api-core/latest/client_options.html
315 from google import pubsub_v1
316
317 async def sample_create_schema():
318 # Create a client
319 client = pubsub_v1.SchemaServiceAsyncClient()
320
321 # Initialize request argument(s)
322 schema = pubsub_v1.Schema()
323 schema.name = "name_value"
324
325 request = pubsub_v1.CreateSchemaRequest(
326 parent="parent_value",
327 schema=schema,
328 )
329
330 # Make the request
331 response = await client.create_schema(request=request)
332
333 # Handle the response
334 print(response)
335
336 Args:
337 request (Optional[Union[google.pubsub_v1.types.CreateSchemaRequest, dict]]):
338 The request object. Request for the CreateSchema method.
339 parent (:class:`str`):
340 Required. The name of the project in which to create the
341 schema. Format is ``projects/{project-id}``.
342
343 This corresponds to the ``parent`` field
344 on the ``request`` instance; if ``request`` is provided, this
345 should not be set.
346 schema (:class:`google.pubsub_v1.types.Schema`):
347 Required. The schema object to create.
348
349 This schema's ``name`` parameter is ignored. The schema
350 object returned by CreateSchema will have a ``name``
351 made using the given ``parent`` and ``schema_id``.
352
353 This corresponds to the ``schema`` field
354 on the ``request`` instance; if ``request`` is provided, this
355 should not be set.
356 schema_id (:class:`str`):
357 The ID to use for the schema, which will become the
358 final component of the schema's resource name.
359
360 See
361 https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names
362 for resource name constraints.
363
364 This corresponds to the ``schema_id`` field
365 on the ``request`` instance; if ``request`` is provided, this
366 should not be set.
367 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
368 should be retried.
369 timeout (float): The timeout for this request.
370 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
371 sent along with the request as metadata. Normally, each value must be of type `str`,
372 but for metadata keys ending with the suffix `-bin`, the corresponding values must
373 be of type `bytes`.
374
375 Returns:
376 google.pubsub_v1.types.Schema:
377 A schema resource.
378 """
379 # Create or coerce a protobuf request object.
380 # - Quick check: If we got a request object, we should *not* have
381 # gotten any keyword arguments that map to the request.
382 flattened_params = [parent, schema, schema_id]
383 has_flattened_params = (
384 len([param for param in flattened_params if param is not None]) > 0
385 )
386 if request is not None and has_flattened_params:
387 raise ValueError(
388 "If the `request` argument is set, then none of "
389 "the individual field arguments should be set."
390 )
391
392 # - Use the request object if provided (there's no risk of modifying the input as
393 # there are no flattened fields), or create one.
394 if not isinstance(request, gp_schema.CreateSchemaRequest):
395 request = gp_schema.CreateSchemaRequest(request)
396
397 # If we have keyword arguments corresponding to fields on the
398 # request, apply these.
399 if parent is not None:
400 request.parent = parent
401 if schema is not None:
402 request.schema = schema
403 if schema_id is not None:
404 request.schema_id = schema_id
405
406 # Wrap the RPC method; this adds retry and timeout information,
407 # and friendly error handling.
408 rpc = self._client._transport._wrapped_methods[
409 self._client._transport.create_schema
410 ]
411
412 # Certain fields should be provided within the metadata header;
413 # add these here.
414 metadata = tuple(metadata) + (
415 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
416 )
417
418 # Validate the universe domain.
419 self._client._validate_universe_domain()
420
421 # Send the request.
422 response = await rpc(
423 request,
424 retry=retry,
425 timeout=timeout,
426 metadata=metadata,
427 )
428
429 # Done; return the response.
430 return response
431
432 async def get_schema(
433 self,
434 request: Optional[Union[schema.GetSchemaRequest, dict]] = None,
435 *,
436 name: Optional[str] = None,
437 retry: OptionalRetry = gapic_v1.method.DEFAULT,
438 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
439 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
440 ) -> schema.Schema:
441 r"""Gets a schema.
442
443 .. code-block:: python
444
445 # This snippet has been automatically generated and should be regarded as a
446 # code template only.
447 # It will require modifications to work:
448 # - It may require correct/in-range values for request initialization.
449 # - It may require specifying regional endpoints when creating the service
450 # client as shown in:
451 # https://googleapis.dev/python/google-api-core/latest/client_options.html
452 from google import pubsub_v1
453
454 async def sample_get_schema():
455 # Create a client
456 client = pubsub_v1.SchemaServiceAsyncClient()
457
458 # Initialize request argument(s)
459 request = pubsub_v1.GetSchemaRequest(
460 name="name_value",
461 )
462
463 # Make the request
464 response = await client.get_schema(request=request)
465
466 # Handle the response
467 print(response)
468
469 Args:
470 request (Optional[Union[google.pubsub_v1.types.GetSchemaRequest, dict]]):
471 The request object. Request for the GetSchema method.
472 name (:class:`str`):
473 Required. The name of the schema to get. Format is
474 ``projects/{project}/schemas/{schema}``.
475
476 This corresponds to the ``name`` field
477 on the ``request`` instance; if ``request`` is provided, this
478 should not be set.
479 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
480 should be retried.
481 timeout (float): The timeout for this request.
482 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
483 sent along with the request as metadata. Normally, each value must be of type `str`,
484 but for metadata keys ending with the suffix `-bin`, the corresponding values must
485 be of type `bytes`.
486
487 Returns:
488 google.pubsub_v1.types.Schema:
489 A schema resource.
490 """
491 # Create or coerce a protobuf request object.
492 # - Quick check: If we got a request object, we should *not* have
493 # gotten any keyword arguments that map to the request.
494 flattened_params = [name]
495 has_flattened_params = (
496 len([param for param in flattened_params if param is not None]) > 0
497 )
498 if request is not None and has_flattened_params:
499 raise ValueError(
500 "If the `request` argument is set, then none of "
501 "the individual field arguments should be set."
502 )
503
504 # - Use the request object if provided (there's no risk of modifying the input as
505 # there are no flattened fields), or create one.
506 if not isinstance(request, schema.GetSchemaRequest):
507 request = schema.GetSchemaRequest(request)
508
509 # If we have keyword arguments corresponding to fields on the
510 # request, apply these.
511 if name is not None:
512 request.name = name
513
514 # Wrap the RPC method; this adds retry and timeout information,
515 # and friendly error handling.
516 rpc = self._client._transport._wrapped_methods[
517 self._client._transport.get_schema
518 ]
519
520 # Certain fields should be provided within the metadata header;
521 # add these here.
522 metadata = tuple(metadata) + (
523 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
524 )
525
526 # Validate the universe domain.
527 self._client._validate_universe_domain()
528
529 # Send the request.
530 response = await rpc(
531 request,
532 retry=retry,
533 timeout=timeout,
534 metadata=metadata,
535 )
536
537 # Done; return the response.
538 return response
539
540 async def list_schemas(
541 self,
542 request: Optional[Union[schema.ListSchemasRequest, dict]] = None,
543 *,
544 parent: Optional[str] = None,
545 retry: OptionalRetry = gapic_v1.method.DEFAULT,
546 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
547 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
548 ) -> pagers.ListSchemasAsyncPager:
549 r"""Lists schemas in a project.
550
551 .. code-block:: python
552
553 # This snippet has been automatically generated and should be regarded as a
554 # code template only.
555 # It will require modifications to work:
556 # - It may require correct/in-range values for request initialization.
557 # - It may require specifying regional endpoints when creating the service
558 # client as shown in:
559 # https://googleapis.dev/python/google-api-core/latest/client_options.html
560 from google import pubsub_v1
561
562 async def sample_list_schemas():
563 # Create a client
564 client = pubsub_v1.SchemaServiceAsyncClient()
565
566 # Initialize request argument(s)
567 request = pubsub_v1.ListSchemasRequest(
568 parent="parent_value",
569 )
570
571 # Make the request
572 page_result = client.list_schemas(request=request)
573
574 # Handle the response
575 async for response in page_result:
576 print(response)
577
578 Args:
579 request (Optional[Union[google.pubsub_v1.types.ListSchemasRequest, dict]]):
580 The request object. Request for the ``ListSchemas`` method.
581 parent (:class:`str`):
582 Required. The name of the project in which to list
583 schemas. Format is ``projects/{project-id}``.
584
585 This corresponds to the ``parent`` field
586 on the ``request`` instance; if ``request`` is provided, this
587 should not be set.
588 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
589 should be retried.
590 timeout (float): The timeout for this request.
591 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
592 sent along with the request as metadata. Normally, each value must be of type `str`,
593 but for metadata keys ending with the suffix `-bin`, the corresponding values must
594 be of type `bytes`.
595
596 Returns:
597 google.pubsub_v1.services.schema_service.pagers.ListSchemasAsyncPager:
598 Response for the ListSchemas method.
599
600 Iterating over this object will yield results and
601 resolve additional pages automatically.
602
603 """
604 # Create or coerce a protobuf request object.
605 # - Quick check: If we got a request object, we should *not* have
606 # gotten any keyword arguments that map to the request.
607 flattened_params = [parent]
608 has_flattened_params = (
609 len([param for param in flattened_params if param is not None]) > 0
610 )
611 if request is not None and has_flattened_params:
612 raise ValueError(
613 "If the `request` argument is set, then none of "
614 "the individual field arguments should be set."
615 )
616
617 # - Use the request object if provided (there's no risk of modifying the input as
618 # there are no flattened fields), or create one.
619 if not isinstance(request, schema.ListSchemasRequest):
620 request = schema.ListSchemasRequest(request)
621
622 # If we have keyword arguments corresponding to fields on the
623 # request, apply these.
624 if parent is not None:
625 request.parent = parent
626
627 # Wrap the RPC method; this adds retry and timeout information,
628 # and friendly error handling.
629 rpc = self._client._transport._wrapped_methods[
630 self._client._transport.list_schemas
631 ]
632
633 # Certain fields should be provided within the metadata header;
634 # add these here.
635 metadata = tuple(metadata) + (
636 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
637 )
638
639 # Validate the universe domain.
640 self._client._validate_universe_domain()
641
642 # Send the request.
643 response = await rpc(
644 request,
645 retry=retry,
646 timeout=timeout,
647 metadata=metadata,
648 )
649
650 # This method is paged; wrap the response in a pager, which provides
651 # an `__aiter__` convenience method.
652 response = pagers.ListSchemasAsyncPager(
653 method=rpc,
654 request=request,
655 response=response,
656 retry=retry,
657 timeout=timeout,
658 metadata=metadata,
659 )
660
661 # Done; return the response.
662 return response
663
664 async def list_schema_revisions(
665 self,
666 request: Optional[Union[schema.ListSchemaRevisionsRequest, dict]] = None,
667 *,
668 name: Optional[str] = None,
669 retry: OptionalRetry = gapic_v1.method.DEFAULT,
670 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
671 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
672 ) -> pagers.ListSchemaRevisionsAsyncPager:
673 r"""Lists all schema revisions for the named schema.
674
675 .. code-block:: python
676
677 # This snippet has been automatically generated and should be regarded as a
678 # code template only.
679 # It will require modifications to work:
680 # - It may require correct/in-range values for request initialization.
681 # - It may require specifying regional endpoints when creating the service
682 # client as shown in:
683 # https://googleapis.dev/python/google-api-core/latest/client_options.html
684 from google import pubsub_v1
685
686 async def sample_list_schema_revisions():
687 # Create a client
688 client = pubsub_v1.SchemaServiceAsyncClient()
689
690 # Initialize request argument(s)
691 request = pubsub_v1.ListSchemaRevisionsRequest(
692 name="name_value",
693 )
694
695 # Make the request
696 page_result = client.list_schema_revisions(request=request)
697
698 # Handle the response
699 async for response in page_result:
700 print(response)
701
702 Args:
703 request (Optional[Union[google.pubsub_v1.types.ListSchemaRevisionsRequest, dict]]):
704 The request object. Request for the ``ListSchemaRevisions`` method.
705 name (:class:`str`):
706 Required. The name of the schema to
707 list revisions for.
708
709 This corresponds to the ``name`` field
710 on the ``request`` instance; if ``request`` is provided, this
711 should not be set.
712 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
713 should be retried.
714 timeout (float): The timeout for this request.
715 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
716 sent along with the request as metadata. Normally, each value must be of type `str`,
717 but for metadata keys ending with the suffix `-bin`, the corresponding values must
718 be of type `bytes`.
719
720 Returns:
721 google.pubsub_v1.services.schema_service.pagers.ListSchemaRevisionsAsyncPager:
722 Response for the ListSchemaRevisions method.
723
724 Iterating over this object will yield results and
725 resolve additional pages automatically.
726
727 """
728 # Create or coerce a protobuf request object.
729 # - Quick check: If we got a request object, we should *not* have
730 # gotten any keyword arguments that map to the request.
731 flattened_params = [name]
732 has_flattened_params = (
733 len([param for param in flattened_params if param is not None]) > 0
734 )
735 if request is not None and has_flattened_params:
736 raise ValueError(
737 "If the `request` argument is set, then none of "
738 "the individual field arguments should be set."
739 )
740
741 # - Use the request object if provided (there's no risk of modifying the input as
742 # there are no flattened fields), or create one.
743 if not isinstance(request, schema.ListSchemaRevisionsRequest):
744 request = schema.ListSchemaRevisionsRequest(request)
745
746 # If we have keyword arguments corresponding to fields on the
747 # request, apply these.
748 if name is not None:
749 request.name = name
750
751 # Wrap the RPC method; this adds retry and timeout information,
752 # and friendly error handling.
753 rpc = self._client._transport._wrapped_methods[
754 self._client._transport.list_schema_revisions
755 ]
756
757 # Certain fields should be provided within the metadata header;
758 # add these here.
759 metadata = tuple(metadata) + (
760 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
761 )
762
763 # Validate the universe domain.
764 self._client._validate_universe_domain()
765
766 # Send the request.
767 response = await rpc(
768 request,
769 retry=retry,
770 timeout=timeout,
771 metadata=metadata,
772 )
773
774 # This method is paged; wrap the response in a pager, which provides
775 # an `__aiter__` convenience method.
776 response = pagers.ListSchemaRevisionsAsyncPager(
777 method=rpc,
778 request=request,
779 response=response,
780 retry=retry,
781 timeout=timeout,
782 metadata=metadata,
783 )
784
785 # Done; return the response.
786 return response
787
788 async def commit_schema(
789 self,
790 request: Optional[Union[gp_schema.CommitSchemaRequest, dict]] = None,
791 *,
792 name: Optional[str] = None,
793 schema: Optional[gp_schema.Schema] = None,
794 retry: OptionalRetry = gapic_v1.method.DEFAULT,
795 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
796 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
797 ) -> gp_schema.Schema:
798 r"""Commits a new schema revision to an existing schema.
799
800 .. code-block:: python
801
802 # This snippet has been automatically generated and should be regarded as a
803 # code template only.
804 # It will require modifications to work:
805 # - It may require correct/in-range values for request initialization.
806 # - It may require specifying regional endpoints when creating the service
807 # client as shown in:
808 # https://googleapis.dev/python/google-api-core/latest/client_options.html
809 from google import pubsub_v1
810
811 async def sample_commit_schema():
812 # Create a client
813 client = pubsub_v1.SchemaServiceAsyncClient()
814
815 # Initialize request argument(s)
816 schema = pubsub_v1.Schema()
817 schema.name = "name_value"
818
819 request = pubsub_v1.CommitSchemaRequest(
820 name="name_value",
821 schema=schema,
822 )
823
824 # Make the request
825 response = await client.commit_schema(request=request)
826
827 # Handle the response
828 print(response)
829
830 Args:
831 request (Optional[Union[google.pubsub_v1.types.CommitSchemaRequest, dict]]):
832 The request object. Request for CommitSchema method.
833 name (:class:`str`):
834 Required. The name of the schema we are revising. Format
835 is ``projects/{project}/schemas/{schema}``.
836
837 This corresponds to the ``name`` field
838 on the ``request`` instance; if ``request`` is provided, this
839 should not be set.
840 schema (:class:`google.pubsub_v1.types.Schema`):
841 Required. The schema revision to
842 commit.
843
844 This corresponds to the ``schema`` field
845 on the ``request`` instance; if ``request`` is provided, this
846 should not be set.
847 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
848 should be retried.
849 timeout (float): The timeout for this request.
850 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
851 sent along with the request as metadata. Normally, each value must be of type `str`,
852 but for metadata keys ending with the suffix `-bin`, the corresponding values must
853 be of type `bytes`.
854
855 Returns:
856 google.pubsub_v1.types.Schema:
857 A schema resource.
858 """
859 # Create or coerce a protobuf request object.
860 # - Quick check: If we got a request object, we should *not* have
861 # gotten any keyword arguments that map to the request.
862 flattened_params = [name, schema]
863 has_flattened_params = (
864 len([param for param in flattened_params if param is not None]) > 0
865 )
866 if request is not None and has_flattened_params:
867 raise ValueError(
868 "If the `request` argument is set, then none of "
869 "the individual field arguments should be set."
870 )
871
872 # - Use the request object if provided (there's no risk of modifying the input as
873 # there are no flattened fields), or create one.
874 if not isinstance(request, gp_schema.CommitSchemaRequest):
875 request = gp_schema.CommitSchemaRequest(request)
876
877 # If we have keyword arguments corresponding to fields on the
878 # request, apply these.
879 if name is not None:
880 request.name = name
881 if schema is not None:
882 request.schema = schema
883
884 # Wrap the RPC method; this adds retry and timeout information,
885 # and friendly error handling.
886 rpc = self._client._transport._wrapped_methods[
887 self._client._transport.commit_schema
888 ]
889
890 # Certain fields should be provided within the metadata header;
891 # add these here.
892 metadata = tuple(metadata) + (
893 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
894 )
895
896 # Validate the universe domain.
897 self._client._validate_universe_domain()
898
899 # Send the request.
900 response = await rpc(
901 request,
902 retry=retry,
903 timeout=timeout,
904 metadata=metadata,
905 )
906
907 # Done; return the response.
908 return response
909
910 async def rollback_schema(
911 self,
912 request: Optional[Union[schema.RollbackSchemaRequest, dict]] = None,
913 *,
914 name: Optional[str] = None,
915 revision_id: Optional[str] = None,
916 retry: OptionalRetry = gapic_v1.method.DEFAULT,
917 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
918 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
919 ) -> schema.Schema:
920 r"""Creates a new schema revision that is a copy of the provided
921 revision_id.
922
923 .. code-block:: python
924
925 # This snippet has been automatically generated and should be regarded as a
926 # code template only.
927 # It will require modifications to work:
928 # - It may require correct/in-range values for request initialization.
929 # - It may require specifying regional endpoints when creating the service
930 # client as shown in:
931 # https://googleapis.dev/python/google-api-core/latest/client_options.html
932 from google import pubsub_v1
933
934 async def sample_rollback_schema():
935 # Create a client
936 client = pubsub_v1.SchemaServiceAsyncClient()
937
938 # Initialize request argument(s)
939 request = pubsub_v1.RollbackSchemaRequest(
940 name="name_value",
941 revision_id="revision_id_value",
942 )
943
944 # Make the request
945 response = await client.rollback_schema(request=request)
946
947 # Handle the response
948 print(response)
949
950 Args:
951 request (Optional[Union[google.pubsub_v1.types.RollbackSchemaRequest, dict]]):
952 The request object. Request for the ``RollbackSchema`` method.
953 name (:class:`str`):
954 Required. The schema being rolled
955 back with revision id.
956
957 This corresponds to the ``name`` field
958 on the ``request`` instance; if ``request`` is provided, this
959 should not be set.
960 revision_id (:class:`str`):
961 Required. The revision ID to roll
962 back to. It must be a revision of the
963 same schema.
964
965 Example: c7cfa2a8
966
967 This corresponds to the ``revision_id`` field
968 on the ``request`` instance; if ``request`` is provided, this
969 should not be set.
970 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
971 should be retried.
972 timeout (float): The timeout for this request.
973 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
974 sent along with the request as metadata. Normally, each value must be of type `str`,
975 but for metadata keys ending with the suffix `-bin`, the corresponding values must
976 be of type `bytes`.
977
978 Returns:
979 google.pubsub_v1.types.Schema:
980 A schema resource.
981 """
982 # Create or coerce a protobuf request object.
983 # - Quick check: If we got a request object, we should *not* have
984 # gotten any keyword arguments that map to the request.
985 flattened_params = [name, revision_id]
986 has_flattened_params = (
987 len([param for param in flattened_params if param is not None]) > 0
988 )
989 if request is not None and has_flattened_params:
990 raise ValueError(
991 "If the `request` argument is set, then none of "
992 "the individual field arguments should be set."
993 )
994
995 # - Use the request object if provided (there's no risk of modifying the input as
996 # there are no flattened fields), or create one.
997 if not isinstance(request, schema.RollbackSchemaRequest):
998 request = schema.RollbackSchemaRequest(request)
999
1000 # If we have keyword arguments corresponding to fields on the
1001 # request, apply these.
1002 if name is not None:
1003 request.name = name
1004 if revision_id is not None:
1005 request.revision_id = revision_id
1006
1007 # Wrap the RPC method; this adds retry and timeout information,
1008 # and friendly error handling.
1009 rpc = self._client._transport._wrapped_methods[
1010 self._client._transport.rollback_schema
1011 ]
1012
1013 # Certain fields should be provided within the metadata header;
1014 # add these here.
1015 metadata = tuple(metadata) + (
1016 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1017 )
1018
1019 # Validate the universe domain.
1020 self._client._validate_universe_domain()
1021
1022 # Send the request.
1023 response = await rpc(
1024 request,
1025 retry=retry,
1026 timeout=timeout,
1027 metadata=metadata,
1028 )
1029
1030 # Done; return the response.
1031 return response
1032
1033 async def delete_schema_revision(
1034 self,
1035 request: Optional[Union[schema.DeleteSchemaRevisionRequest, dict]] = None,
1036 *,
1037 name: Optional[str] = None,
1038 revision_id: Optional[str] = None,
1039 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1040 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1041 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1042 ) -> schema.Schema:
1043 r"""Deletes a specific schema revision.
1044
1045 .. code-block:: python
1046
1047 # This snippet has been automatically generated and should be regarded as a
1048 # code template only.
1049 # It will require modifications to work:
1050 # - It may require correct/in-range values for request initialization.
1051 # - It may require specifying regional endpoints when creating the service
1052 # client as shown in:
1053 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1054 from google import pubsub_v1
1055
1056 async def sample_delete_schema_revision():
1057 # Create a client
1058 client = pubsub_v1.SchemaServiceAsyncClient()
1059
1060 # Initialize request argument(s)
1061 request = pubsub_v1.DeleteSchemaRevisionRequest(
1062 name="name_value",
1063 )
1064
1065 # Make the request
1066 response = await client.delete_schema_revision(request=request)
1067
1068 # Handle the response
1069 print(response)
1070
1071 Args:
1072 request (Optional[Union[google.pubsub_v1.types.DeleteSchemaRevisionRequest, dict]]):
1073 The request object. Request for the ``DeleteSchemaRevision`` method.
1074 name (:class:`str`):
1075 Required. The name of the schema revision to be deleted,
1076 with a revision ID explicitly included.
1077
1078 Example: ``projects/123/schemas/my-schema@c7cfa2a8``
1079
1080 This corresponds to the ``name`` field
1081 on the ``request`` instance; if ``request`` is provided, this
1082 should not be set.
1083 revision_id (:class:`str`):
1084 Optional. This field is deprecated and should not be
1085 used for specifying the revision ID. The revision ID
1086 should be specified via the ``name`` parameter.
1087
1088 This corresponds to the ``revision_id`` field
1089 on the ``request`` instance; if ``request`` is provided, this
1090 should not be set.
1091 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1092 should be retried.
1093 timeout (float): The timeout for this request.
1094 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1095 sent along with the request as metadata. Normally, each value must be of type `str`,
1096 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1097 be of type `bytes`.
1098
1099 Returns:
1100 google.pubsub_v1.types.Schema:
1101 A schema resource.
1102 """
1103 # Create or coerce a protobuf request object.
1104 # - Quick check: If we got a request object, we should *not* have
1105 # gotten any keyword arguments that map to the request.
1106 flattened_params = [name, revision_id]
1107 has_flattened_params = (
1108 len([param for param in flattened_params if param is not None]) > 0
1109 )
1110 if request is not None and has_flattened_params:
1111 raise ValueError(
1112 "If the `request` argument is set, then none of "
1113 "the individual field arguments should be set."
1114 )
1115
1116 # - Use the request object if provided (there's no risk of modifying the input as
1117 # there are no flattened fields), or create one.
1118 if not isinstance(request, schema.DeleteSchemaRevisionRequest):
1119 request = schema.DeleteSchemaRevisionRequest(request)
1120
1121 # If we have keyword arguments corresponding to fields on the
1122 # request, apply these.
1123 if name is not None:
1124 request.name = name
1125 if revision_id is not None:
1126 request.revision_id = revision_id
1127
1128 # Wrap the RPC method; this adds retry and timeout information,
1129 # and friendly error handling.
1130 rpc = self._client._transport._wrapped_methods[
1131 self._client._transport.delete_schema_revision
1132 ]
1133
1134 # Certain fields should be provided within the metadata header;
1135 # add these here.
1136 metadata = tuple(metadata) + (
1137 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1138 )
1139
1140 # Validate the universe domain.
1141 self._client._validate_universe_domain()
1142
1143 # Send the request.
1144 response = await rpc(
1145 request,
1146 retry=retry,
1147 timeout=timeout,
1148 metadata=metadata,
1149 )
1150
1151 # Done; return the response.
1152 return response
1153
1154 async def delete_schema(
1155 self,
1156 request: Optional[Union[schema.DeleteSchemaRequest, dict]] = None,
1157 *,
1158 name: Optional[str] = None,
1159 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1160 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1161 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1162 ) -> None:
1163 r"""Deletes a schema.
1164
1165 .. code-block:: python
1166
1167 # This snippet has been automatically generated and should be regarded as a
1168 # code template only.
1169 # It will require modifications to work:
1170 # - It may require correct/in-range values for request initialization.
1171 # - It may require specifying regional endpoints when creating the service
1172 # client as shown in:
1173 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1174 from google import pubsub_v1
1175
1176 async def sample_delete_schema():
1177 # Create a client
1178 client = pubsub_v1.SchemaServiceAsyncClient()
1179
1180 # Initialize request argument(s)
1181 request = pubsub_v1.DeleteSchemaRequest(
1182 name="name_value",
1183 )
1184
1185 # Make the request
1186 await client.delete_schema(request=request)
1187
1188 Args:
1189 request (Optional[Union[google.pubsub_v1.types.DeleteSchemaRequest, dict]]):
1190 The request object. Request for the ``DeleteSchema`` method.
1191 name (:class:`str`):
1192 Required. Name of the schema to delete. Format is
1193 ``projects/{project}/schemas/{schema}``.
1194
1195 This corresponds to the ``name`` field
1196 on the ``request`` instance; if ``request`` is provided, this
1197 should not be set.
1198 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1199 should be retried.
1200 timeout (float): The timeout for this request.
1201 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1202 sent along with the request as metadata. Normally, each value must be of type `str`,
1203 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1204 be of type `bytes`.
1205 """
1206 # Create or coerce a protobuf request object.
1207 # - Quick check: If we got a request object, we should *not* have
1208 # gotten any keyword arguments that map to the request.
1209 flattened_params = [name]
1210 has_flattened_params = (
1211 len([param for param in flattened_params if param is not None]) > 0
1212 )
1213 if request is not None and has_flattened_params:
1214 raise ValueError(
1215 "If the `request` argument is set, then none of "
1216 "the individual field arguments should be set."
1217 )
1218
1219 # - Use the request object if provided (there's no risk of modifying the input as
1220 # there are no flattened fields), or create one.
1221 if not isinstance(request, schema.DeleteSchemaRequest):
1222 request = schema.DeleteSchemaRequest(request)
1223
1224 # If we have keyword arguments corresponding to fields on the
1225 # request, apply these.
1226 if name is not None:
1227 request.name = name
1228
1229 # Wrap the RPC method; this adds retry and timeout information,
1230 # and friendly error handling.
1231 rpc = self._client._transport._wrapped_methods[
1232 self._client._transport.delete_schema
1233 ]
1234
1235 # Certain fields should be provided within the metadata header;
1236 # add these here.
1237 metadata = tuple(metadata) + (
1238 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1239 )
1240
1241 # Validate the universe domain.
1242 self._client._validate_universe_domain()
1243
1244 # Send the request.
1245 await rpc(
1246 request,
1247 retry=retry,
1248 timeout=timeout,
1249 metadata=metadata,
1250 )
1251
1252 async def validate_schema(
1253 self,
1254 request: Optional[Union[gp_schema.ValidateSchemaRequest, dict]] = None,
1255 *,
1256 parent: Optional[str] = None,
1257 schema: Optional[gp_schema.Schema] = None,
1258 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1259 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1260 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1261 ) -> gp_schema.ValidateSchemaResponse:
1262 r"""Validates a schema.
1263
1264 .. code-block:: python
1265
1266 # This snippet has been automatically generated and should be regarded as a
1267 # code template only.
1268 # It will require modifications to work:
1269 # - It may require correct/in-range values for request initialization.
1270 # - It may require specifying regional endpoints when creating the service
1271 # client as shown in:
1272 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1273 from google import pubsub_v1
1274
1275 async def sample_validate_schema():
1276 # Create a client
1277 client = pubsub_v1.SchemaServiceAsyncClient()
1278
1279 # Initialize request argument(s)
1280 schema = pubsub_v1.Schema()
1281 schema.name = "name_value"
1282
1283 request = pubsub_v1.ValidateSchemaRequest(
1284 parent="parent_value",
1285 schema=schema,
1286 )
1287
1288 # Make the request
1289 response = await client.validate_schema(request=request)
1290
1291 # Handle the response
1292 print(response)
1293
1294 Args:
1295 request (Optional[Union[google.pubsub_v1.types.ValidateSchemaRequest, dict]]):
1296 The request object. Request for the ``ValidateSchema`` method.
1297 parent (:class:`str`):
1298 Required. The name of the project in which to validate
1299 schemas. Format is ``projects/{project-id}``.
1300
1301 This corresponds to the ``parent`` field
1302 on the ``request`` instance; if ``request`` is provided, this
1303 should not be set.
1304 schema (:class:`google.pubsub_v1.types.Schema`):
1305 Required. The schema object to
1306 validate.
1307
1308 This corresponds to the ``schema`` field
1309 on the ``request`` instance; if ``request`` is provided, this
1310 should not be set.
1311 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1312 should be retried.
1313 timeout (float): The timeout for this request.
1314 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1315 sent along with the request as metadata. Normally, each value must be of type `str`,
1316 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1317 be of type `bytes`.
1318
1319 Returns:
1320 google.pubsub_v1.types.ValidateSchemaResponse:
1321 Response for the ValidateSchema method.
1322 Empty for now.
1323
1324 """
1325 # Create or coerce a protobuf request object.
1326 # - Quick check: If we got a request object, we should *not* have
1327 # gotten any keyword arguments that map to the request.
1328 flattened_params = [parent, schema]
1329 has_flattened_params = (
1330 len([param for param in flattened_params if param is not None]) > 0
1331 )
1332 if request is not None and has_flattened_params:
1333 raise ValueError(
1334 "If the `request` argument is set, then none of "
1335 "the individual field arguments should be set."
1336 )
1337
1338 # - Use the request object if provided (there's no risk of modifying the input as
1339 # there are no flattened fields), or create one.
1340 if not isinstance(request, gp_schema.ValidateSchemaRequest):
1341 request = gp_schema.ValidateSchemaRequest(request)
1342
1343 # If we have keyword arguments corresponding to fields on the
1344 # request, apply these.
1345 if parent is not None:
1346 request.parent = parent
1347 if schema is not None:
1348 request.schema = schema
1349
1350 # Wrap the RPC method; this adds retry and timeout information,
1351 # and friendly error handling.
1352 rpc = self._client._transport._wrapped_methods[
1353 self._client._transport.validate_schema
1354 ]
1355
1356 # Certain fields should be provided within the metadata header;
1357 # add these here.
1358 metadata = tuple(metadata) + (
1359 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1360 )
1361
1362 # Validate the universe domain.
1363 self._client._validate_universe_domain()
1364
1365 # Send the request.
1366 response = await rpc(
1367 request,
1368 retry=retry,
1369 timeout=timeout,
1370 metadata=metadata,
1371 )
1372
1373 # Done; return the response.
1374 return response
1375
1376 async def validate_message(
1377 self,
1378 request: Optional[Union[schema.ValidateMessageRequest, dict]] = None,
1379 *,
1380 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1381 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1382 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1383 ) -> schema.ValidateMessageResponse:
1384 r"""Validates a message against a schema.
1385
1386 .. code-block:: python
1387
1388 # This snippet has been automatically generated and should be regarded as a
1389 # code template only.
1390 # It will require modifications to work:
1391 # - It may require correct/in-range values for request initialization.
1392 # - It may require specifying regional endpoints when creating the service
1393 # client as shown in:
1394 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1395 from google import pubsub_v1
1396
1397 async def sample_validate_message():
1398 # Create a client
1399 client = pubsub_v1.SchemaServiceAsyncClient()
1400
1401 # Initialize request argument(s)
1402 request = pubsub_v1.ValidateMessageRequest(
1403 name="name_value",
1404 parent="parent_value",
1405 )
1406
1407 # Make the request
1408 response = await client.validate_message(request=request)
1409
1410 # Handle the response
1411 print(response)
1412
1413 Args:
1414 request (Optional[Union[google.pubsub_v1.types.ValidateMessageRequest, dict]]):
1415 The request object. Request for the ``ValidateMessage`` method.
1416 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1417 should be retried.
1418 timeout (float): The timeout for this request.
1419 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1420 sent along with the request as metadata. Normally, each value must be of type `str`,
1421 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1422 be of type `bytes`.
1423
1424 Returns:
1425 google.pubsub_v1.types.ValidateMessageResponse:
1426 Response for the ValidateMessage method.
1427 Empty for now.
1428
1429 """
1430 # Create or coerce a protobuf request object.
1431 # - Use the request object if provided (there's no risk of modifying the input as
1432 # there are no flattened fields), or create one.
1433 if not isinstance(request, schema.ValidateMessageRequest):
1434 request = schema.ValidateMessageRequest(request)
1435
1436 # Wrap the RPC method; this adds retry and timeout information,
1437 # and friendly error handling.
1438 rpc = self._client._transport._wrapped_methods[
1439 self._client._transport.validate_message
1440 ]
1441
1442 # Certain fields should be provided within the metadata header;
1443 # add these here.
1444 metadata = tuple(metadata) + (
1445 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1446 )
1447
1448 # Validate the universe domain.
1449 self._client._validate_universe_domain()
1450
1451 # Send the request.
1452 response = await rpc(
1453 request,
1454 retry=retry,
1455 timeout=timeout,
1456 metadata=metadata,
1457 )
1458
1459 # Done; return the response.
1460 return response
1461
1462 async def set_iam_policy(
1463 self,
1464 request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
1465 *,
1466 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1467 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1468 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1469 ) -> policy_pb2.Policy:
1470 r"""Sets the IAM access control policy on the specified function.
1471
1472 Replaces any existing policy.
1473
1474 Args:
1475 request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`):
1476 The request object. Request message for `SetIamPolicy`
1477 method.
1478 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1479 should be retried.
1480 timeout (float): The timeout for this request.
1481 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1482 sent along with the request as metadata. Normally, each value must be of type `str`,
1483 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1484 be of type `bytes`.
1485 Returns:
1486 ~.policy_pb2.Policy:
1487 Defines an Identity and Access Management (IAM) policy.
1488 It is used to specify access control policies for Cloud
1489 Platform resources.
1490 A ``Policy`` is a collection of ``bindings``. A
1491 ``binding`` binds one or more ``members`` to a single
1492 ``role``. Members can be user accounts, service
1493 accounts, Google groups, and domains (such as G Suite).
1494 A ``role`` is a named list of permissions (defined by
1495 IAM or configured by users). A ``binding`` can
1496 optionally specify a ``condition``, which is a logic
1497 expression that further constrains the role binding
1498 based on attributes about the request and/or target
1499 resource.
1500
1501 **JSON Example**
1502
1503 ::
1504
1505 {
1506 "bindings": [
1507 {
1508 "role": "roles/resourcemanager.organizationAdmin",
1509 "members": [
1510 "user:mike@example.com",
1511 "group:admins@example.com",
1512 "domain:google.com",
1513 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1514 ]
1515 },
1516 {
1517 "role": "roles/resourcemanager.organizationViewer",
1518 "members": ["user:eve@example.com"],
1519 "condition": {
1520 "title": "expirable access",
1521 "description": "Does not grant access after Sep 2020",
1522 "expression": "request.time <
1523 timestamp('2020-10-01T00:00:00.000Z')",
1524 }
1525 }
1526 ]
1527 }
1528
1529 **YAML Example**
1530
1531 ::
1532
1533 bindings:
1534 - members:
1535 - user:mike@example.com
1536 - group:admins@example.com
1537 - domain:google.com
1538 - serviceAccount:my-project-id@appspot.gserviceaccount.com
1539 role: roles/resourcemanager.organizationAdmin
1540 - members:
1541 - user:eve@example.com
1542 role: roles/resourcemanager.organizationViewer
1543 condition:
1544 title: expirable access
1545 description: Does not grant access after Sep 2020
1546 expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
1547
1548 For a description of IAM and its features, see the `IAM
1549 developer's
1550 guide <https://cloud.google.com/iam/docs>`__.
1551 """
1552 # Create or coerce a protobuf request object.
1553
1554 # The request isn't a proto-plus wrapped type,
1555 # so it must be constructed via keyword expansion.
1556 if isinstance(request, dict):
1557 request = iam_policy_pb2.SetIamPolicyRequest(**request)
1558
1559 # Wrap the RPC method; this adds retry and timeout information,
1560 # and friendly error handling.
1561 rpc = self.transport._wrapped_methods[self._client._transport.set_iam_policy]
1562
1563 # Certain fields should be provided within the metadata header;
1564 # add these here.
1565 metadata = tuple(metadata) + (
1566 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1567 )
1568
1569 # Validate the universe domain.
1570 self._client._validate_universe_domain()
1571
1572 # Send the request.
1573 response = await rpc(
1574 request,
1575 retry=retry,
1576 timeout=timeout,
1577 metadata=metadata,
1578 )
1579
1580 # Done; return the response.
1581 return response
1582
1583 async def get_iam_policy(
1584 self,
1585 request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
1586 *,
1587 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1588 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1589 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1590 ) -> policy_pb2.Policy:
1591 r"""Gets the IAM access control policy for a function.
1592
1593 Returns an empty policy if the function exists and does not have a
1594 policy set.
1595
1596 Args:
1597 request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`):
1598 The request object. Request message for `GetIamPolicy`
1599 method.
1600 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if
1601 any, should be retried.
1602 timeout (float): The timeout for this request.
1603 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1604 sent along with the request as metadata. Normally, each value must be of type `str`,
1605 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1606 be of type `bytes`.
1607 Returns:
1608 ~.policy_pb2.Policy:
1609 Defines an Identity and Access Management (IAM) policy.
1610 It is used to specify access control policies for Cloud
1611 Platform resources.
1612 A ``Policy`` is a collection of ``bindings``. A
1613 ``binding`` binds one or more ``members`` to a single
1614 ``role``. Members can be user accounts, service
1615 accounts, Google groups, and domains (such as G Suite).
1616 A ``role`` is a named list of permissions (defined by
1617 IAM or configured by users). A ``binding`` can
1618 optionally specify a ``condition``, which is a logic
1619 expression that further constrains the role binding
1620 based on attributes about the request and/or target
1621 resource.
1622
1623 **JSON Example**
1624
1625 ::
1626
1627 {
1628 "bindings": [
1629 {
1630 "role": "roles/resourcemanager.organizationAdmin",
1631 "members": [
1632 "user:mike@example.com",
1633 "group:admins@example.com",
1634 "domain:google.com",
1635 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1636 ]
1637 },
1638 {
1639 "role": "roles/resourcemanager.organizationViewer",
1640 "members": ["user:eve@example.com"],
1641 "condition": {
1642 "title": "expirable access",
1643 "description": "Does not grant access after Sep 2020",
1644 "expression": "request.time <
1645 timestamp('2020-10-01T00:00:00.000Z')",
1646 }
1647 }
1648 ]
1649 }
1650
1651 **YAML Example**
1652
1653 ::
1654
1655 bindings:
1656 - members:
1657 - user:mike@example.com
1658 - group:admins@example.com
1659 - domain:google.com
1660 - serviceAccount:my-project-id@appspot.gserviceaccount.com
1661 role: roles/resourcemanager.organizationAdmin
1662 - members:
1663 - user:eve@example.com
1664 role: roles/resourcemanager.organizationViewer
1665 condition:
1666 title: expirable access
1667 description: Does not grant access after Sep 2020
1668 expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
1669
1670 For a description of IAM and its features, see the `IAM
1671 developer's
1672 guide <https://cloud.google.com/iam/docs>`__.
1673 """
1674 # Create or coerce a protobuf request object.
1675
1676 # The request isn't a proto-plus wrapped type,
1677 # so it must be constructed via keyword expansion.
1678 if isinstance(request, dict):
1679 request = iam_policy_pb2.GetIamPolicyRequest(**request)
1680
1681 # Wrap the RPC method; this adds retry and timeout information,
1682 # and friendly error handling.
1683 rpc = self.transport._wrapped_methods[self._client._transport.get_iam_policy]
1684
1685 # Certain fields should be provided within the metadata header;
1686 # add these here.
1687 metadata = tuple(metadata) + (
1688 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1689 )
1690
1691 # Validate the universe domain.
1692 self._client._validate_universe_domain()
1693
1694 # Send the request.
1695 response = await rpc(
1696 request,
1697 retry=retry,
1698 timeout=timeout,
1699 metadata=metadata,
1700 )
1701
1702 # Done; return the response.
1703 return response
1704
1705 async def test_iam_permissions(
1706 self,
1707 request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
1708 *,
1709 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1710 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1711 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1712 ) -> iam_policy_pb2.TestIamPermissionsResponse:
1713 r"""Tests the specified IAM permissions against the IAM access control
1714 policy for a function.
1715
1716 If the function does not exist, this will return an empty set
1717 of permissions, not a NOT_FOUND error.
1718
1719 Args:
1720 request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`):
1721 The request object. Request message for
1722 `TestIamPermissions` method.
1723 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
1724 if any, should be retried.
1725 timeout (float): The timeout for this request.
1726 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1727 sent along with the request as metadata. Normally, each value must be of type `str`,
1728 but for metadata keys ending with the suffix `-bin`, the corresponding values must
1729 be of type `bytes`.
1730 Returns:
1731 ~.iam_policy_pb2.TestIamPermissionsResponse:
1732 Response message for ``TestIamPermissions`` method.
1733 """
1734 # Create or coerce a protobuf request object.
1735
1736 # The request isn't a proto-plus wrapped type,
1737 # so it must be constructed via keyword expansion.
1738 if isinstance(request, dict):
1739 request = iam_policy_pb2.TestIamPermissionsRequest(**request)
1740
1741 # Wrap the RPC method; this adds retry and timeout information,
1742 # and friendly error handling.
1743 rpc = self.transport._wrapped_methods[
1744 self._client._transport.test_iam_permissions
1745 ]
1746
1747 # Certain fields should be provided within the metadata header;
1748 # add these here.
1749 metadata = tuple(metadata) + (
1750 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1751 )
1752
1753 # Validate the universe domain.
1754 self._client._validate_universe_domain()
1755
1756 # Send the request.
1757 response = await rpc(
1758 request,
1759 retry=retry,
1760 timeout=timeout,
1761 metadata=metadata,
1762 )
1763
1764 # Done; return the response.
1765 return response
1766
1767 async def __aenter__(self) -> "SchemaServiceAsyncClient":
1768 return self
1769
1770 async def __aexit__(self, exc_type, exc, tb):
1771 await self.transport.close()
1772
1773
1774DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1775 client_library_version=package_version.__version__
1776)
1777
1778
1779__all__ = ("SchemaServiceAsyncClient",)