1# -*- coding: utf-8 -*-
2# Copyright 2025 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 inspect
17import json
18import pickle
19import logging as std_logging
20import warnings
21from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
22
23from google.api_core import gapic_v1
24from google.api_core import grpc_helpers_async
25from google.api_core import exceptions as core_exceptions
26from google.api_core import retry_async as retries
27from google.auth import credentials as ga_credentials # type: ignore
28from google.auth.transport.grpc import SslCredentials # type: ignore
29from google.protobuf.json_format import MessageToJson
30import google.protobuf.message
31
32import grpc # type: ignore
33import proto # type: ignore
34from grpc.experimental import aio # type: ignore
35
36from google.iam.v1 import iam_policy_pb2 # type: ignore
37from google.iam.v1 import policy_pb2 # type: ignore
38from google.protobuf import empty_pb2 # type: ignore
39from google.pubsub_v1.types import schema
40from google.pubsub_v1.types import schema as gp_schema
41from .base import SchemaServiceTransport, DEFAULT_CLIENT_INFO
42from .grpc import SchemaServiceGrpcTransport
43
44try:
45 from google.api_core import client_logging # type: ignore
46
47 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
48except ImportError: # pragma: NO COVER
49 CLIENT_LOGGING_SUPPORTED = False
50
51_LOGGER = std_logging.getLogger(__name__)
52
53
54class _LoggingClientAIOInterceptor(
55 grpc.aio.UnaryUnaryClientInterceptor
56): # pragma: NO COVER
57 async def intercept_unary_unary(self, continuation, client_call_details, request):
58 logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
59 std_logging.DEBUG
60 )
61 if logging_enabled: # pragma: NO COVER
62 request_metadata = client_call_details.metadata
63 if isinstance(request, proto.Message):
64 request_payload = type(request).to_json(request)
65 elif isinstance(request, google.protobuf.message.Message):
66 request_payload = MessageToJson(request)
67 else:
68 request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
69
70 request_metadata = {
71 key: value.decode("utf-8") if isinstance(value, bytes) else value
72 for key, value in request_metadata
73 }
74 grpc_request = {
75 "payload": request_payload,
76 "requestMethod": "grpc",
77 "metadata": dict(request_metadata),
78 }
79 _LOGGER.debug(
80 f"Sending request for {client_call_details.method}",
81 extra={
82 "serviceName": "google.pubsub.v1.SchemaService",
83 "rpcName": str(client_call_details.method),
84 "request": grpc_request,
85 "metadata": grpc_request["metadata"],
86 },
87 )
88 response = await continuation(client_call_details, request)
89 if logging_enabled: # pragma: NO COVER
90 response_metadata = await response.trailing_metadata()
91 # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
92 metadata = (
93 dict([(k, str(v)) for k, v in response_metadata])
94 if response_metadata
95 else None
96 )
97 result = await response
98 if isinstance(result, proto.Message):
99 response_payload = type(result).to_json(result)
100 elif isinstance(result, google.protobuf.message.Message):
101 response_payload = MessageToJson(result)
102 else:
103 response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
104 grpc_response = {
105 "payload": response_payload,
106 "metadata": metadata,
107 "status": "OK",
108 }
109 _LOGGER.debug(
110 f"Received response to rpc {client_call_details.method}.",
111 extra={
112 "serviceName": "google.pubsub.v1.SchemaService",
113 "rpcName": str(client_call_details.method),
114 "response": grpc_response,
115 "metadata": grpc_response["metadata"],
116 },
117 )
118 return response
119
120
121class SchemaServiceGrpcAsyncIOTransport(SchemaServiceTransport):
122 """gRPC AsyncIO backend transport for SchemaService.
123
124 Service for doing schema-related operations.
125
126 This class defines the same methods as the primary client, so the
127 primary client can load the underlying transport implementation
128 and call it.
129
130 It sends protocol buffers over the wire using gRPC (which is built on
131 top of HTTP/2); the ``grpcio`` package must be installed.
132 """
133
134 _grpc_channel: aio.Channel
135 _stubs: Dict[str, Callable] = {}
136
137 @classmethod
138 def create_channel(
139 cls,
140 host: str = "pubsub.googleapis.com",
141 credentials: Optional[ga_credentials.Credentials] = None,
142 credentials_file: Optional[str] = None,
143 scopes: Optional[Sequence[str]] = None,
144 quota_project_id: Optional[str] = None,
145 **kwargs,
146 ) -> aio.Channel:
147 """Create and return a gRPC AsyncIO channel object.
148 Args:
149 host (Optional[str]): The host for the channel to use.
150 credentials (Optional[~.Credentials]): The
151 authorization credentials to attach to requests. These
152 credentials identify this application to the service. If
153 none are specified, the client will attempt to ascertain
154 the credentials from the environment.
155 credentials_file (Optional[str]): A file with credentials that can
156 be loaded with :func:`google.auth.load_credentials_from_file`.
157 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
158 service. These are only used when credentials are not specified and
159 are passed to :func:`google.auth.default`.
160 quota_project_id (Optional[str]): An optional project to use for billing
161 and quota.
162 kwargs (Optional[dict]): Keyword arguments, which are passed to the
163 channel creation.
164 Returns:
165 aio.Channel: A gRPC AsyncIO channel object.
166 """
167
168 return grpc_helpers_async.create_channel(
169 host,
170 credentials=credentials,
171 credentials_file=credentials_file,
172 quota_project_id=quota_project_id,
173 default_scopes=cls.AUTH_SCOPES,
174 scopes=scopes,
175 default_host=cls.DEFAULT_HOST,
176 **kwargs,
177 )
178
179 def __init__(
180 self,
181 *,
182 host: str = "pubsub.googleapis.com",
183 credentials: Optional[ga_credentials.Credentials] = None,
184 credentials_file: Optional[str] = None,
185 scopes: Optional[Sequence[str]] = None,
186 channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None,
187 api_mtls_endpoint: Optional[str] = None,
188 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
189 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
190 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
191 quota_project_id: Optional[str] = None,
192 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
193 always_use_jwt_access: Optional[bool] = False,
194 api_audience: Optional[str] = None,
195 ) -> None:
196 """Instantiate the transport.
197
198 Args:
199 host (Optional[str]):
200 The hostname to connect to (default: 'pubsub.googleapis.com').
201 credentials (Optional[google.auth.credentials.Credentials]): The
202 authorization credentials to attach to requests. These
203 credentials identify the application to the service; if none
204 are specified, the client will attempt to ascertain the
205 credentials from the environment.
206 This argument is ignored if a ``channel`` instance is provided.
207 credentials_file (Optional[str]): A file with credentials that can
208 be loaded with :func:`google.auth.load_credentials_from_file`.
209 This argument is ignored if a ``channel`` instance is provided.
210 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
211 service. These are only used when credentials are not specified and
212 are passed to :func:`google.auth.default`.
213 channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]):
214 A ``Channel`` instance through which to make calls, or a Callable
215 that constructs and returns one. If set to None, ``self.create_channel``
216 is used to create the channel. If a Callable is given, it will be called
217 with the same arguments as used in ``self.create_channel``.
218 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
219 If provided, it overrides the ``host`` argument and tries to create
220 a mutual TLS channel with client SSL credentials from
221 ``client_cert_source`` or application default SSL credentials.
222 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
223 Deprecated. A callback to provide client SSL certificate bytes and
224 private key bytes, both in PEM format. It is ignored if
225 ``api_mtls_endpoint`` is None.
226 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
227 for the grpc channel. It is ignored if a ``channel`` instance is provided.
228 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
229 A callback to provide client certificate bytes and private key bytes,
230 both in PEM format. It is used to configure a mutual TLS channel. It is
231 ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
232 quota_project_id (Optional[str]): An optional project to use for billing
233 and quota.
234 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
235 The client info used to send a user-agent string along with
236 API requests. If ``None``, then default info will be used.
237 Generally, you only need to set this if you're developing
238 your own client library.
239 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
240 be used for service account credentials.
241
242 Raises:
243 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
244 creation failed for any reason.
245 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
246 and ``credentials_file`` are passed.
247 """
248 self._grpc_channel = None
249 self._ssl_channel_credentials = ssl_channel_credentials
250 self._stubs: Dict[str, Callable] = {}
251
252 if api_mtls_endpoint:
253 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
254 if client_cert_source:
255 warnings.warn("client_cert_source is deprecated", DeprecationWarning)
256
257 if isinstance(channel, aio.Channel):
258 # Ignore credentials if a channel was passed.
259 credentials = None
260 self._ignore_credentials = True
261 # If a channel was explicitly provided, set it.
262 self._grpc_channel = channel
263 self._ssl_channel_credentials = None
264 else:
265 if api_mtls_endpoint:
266 host = api_mtls_endpoint
267
268 # Create SSL credentials with client_cert_source or application
269 # default SSL credentials.
270 if client_cert_source:
271 cert, key = client_cert_source()
272 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
273 certificate_chain=cert, private_key=key
274 )
275 else:
276 self._ssl_channel_credentials = SslCredentials().ssl_credentials
277
278 else:
279 if client_cert_source_for_mtls and not ssl_channel_credentials:
280 cert, key = client_cert_source_for_mtls()
281 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
282 certificate_chain=cert, private_key=key
283 )
284
285 # The base transport sets the host, credentials and scopes
286 super().__init__(
287 host=host,
288 credentials=credentials,
289 credentials_file=credentials_file,
290 scopes=scopes,
291 quota_project_id=quota_project_id,
292 client_info=client_info,
293 always_use_jwt_access=always_use_jwt_access,
294 api_audience=api_audience,
295 )
296
297 if not self._grpc_channel:
298 # initialize with the provided callable or the default channel
299 channel_init = channel or type(self).create_channel
300 self._grpc_channel = channel_init(
301 self._host,
302 # use the credentials which are saved
303 credentials=self._credentials,
304 # Set ``credentials_file`` to ``None`` here as
305 # the credentials that we saved earlier should be used.
306 credentials_file=None,
307 scopes=self._scopes,
308 ssl_credentials=self._ssl_channel_credentials,
309 quota_project_id=quota_project_id,
310 options=[
311 ("grpc.max_send_message_length", -1),
312 ("grpc.max_receive_message_length", -1),
313 ("grpc.max_metadata_size", 4 * 1024 * 1024),
314 ("grpc.keepalive_time_ms", 30000),
315 ],
316 )
317
318 self._interceptor = _LoggingClientAIOInterceptor()
319 self._grpc_channel._unary_unary_interceptors.append(self._interceptor)
320 self._logged_channel = self._grpc_channel
321 self._wrap_with_kind = (
322 "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters
323 )
324 # Wrap messages. This must be done after self._logged_channel exists
325 self._prep_wrapped_messages(client_info)
326
327 @property
328 def grpc_channel(self) -> aio.Channel:
329 """Create the channel designed to connect to this service.
330
331 This property caches on the instance; repeated calls return
332 the same channel.
333 """
334 # Return the channel from cache.
335 return self._grpc_channel
336
337 @property
338 def create_schema(
339 self,
340 ) -> Callable[[gp_schema.CreateSchemaRequest], Awaitable[gp_schema.Schema]]:
341 r"""Return a callable for the create schema method over gRPC.
342
343 Creates a schema.
344
345 Returns:
346 Callable[[~.CreateSchemaRequest],
347 Awaitable[~.Schema]]:
348 A function that, when called, will call the underlying RPC
349 on the server.
350 """
351 # Generate a "stub function" on-the-fly which will actually make
352 # the request.
353 # gRPC handles serialization and deserialization, so we just need
354 # to pass in the functions for each.
355 if "create_schema" not in self._stubs:
356 self._stubs["create_schema"] = self._logged_channel.unary_unary(
357 "/google.pubsub.v1.SchemaService/CreateSchema",
358 request_serializer=gp_schema.CreateSchemaRequest.serialize,
359 response_deserializer=gp_schema.Schema.deserialize,
360 )
361 return self._stubs["create_schema"]
362
363 @property
364 def get_schema(
365 self,
366 ) -> Callable[[schema.GetSchemaRequest], Awaitable[schema.Schema]]:
367 r"""Return a callable for the get schema method over gRPC.
368
369 Gets a schema.
370
371 Returns:
372 Callable[[~.GetSchemaRequest],
373 Awaitable[~.Schema]]:
374 A function that, when called, will call the underlying RPC
375 on the server.
376 """
377 # Generate a "stub function" on-the-fly which will actually make
378 # the request.
379 # gRPC handles serialization and deserialization, so we just need
380 # to pass in the functions for each.
381 if "get_schema" not in self._stubs:
382 self._stubs["get_schema"] = self._logged_channel.unary_unary(
383 "/google.pubsub.v1.SchemaService/GetSchema",
384 request_serializer=schema.GetSchemaRequest.serialize,
385 response_deserializer=schema.Schema.deserialize,
386 )
387 return self._stubs["get_schema"]
388
389 @property
390 def list_schemas(
391 self,
392 ) -> Callable[[schema.ListSchemasRequest], Awaitable[schema.ListSchemasResponse]]:
393 r"""Return a callable for the list schemas method over gRPC.
394
395 Lists schemas in a project.
396
397 Returns:
398 Callable[[~.ListSchemasRequest],
399 Awaitable[~.ListSchemasResponse]]:
400 A function that, when called, will call the underlying RPC
401 on the server.
402 """
403 # Generate a "stub function" on-the-fly which will actually make
404 # the request.
405 # gRPC handles serialization and deserialization, so we just need
406 # to pass in the functions for each.
407 if "list_schemas" not in self._stubs:
408 self._stubs["list_schemas"] = self._logged_channel.unary_unary(
409 "/google.pubsub.v1.SchemaService/ListSchemas",
410 request_serializer=schema.ListSchemasRequest.serialize,
411 response_deserializer=schema.ListSchemasResponse.deserialize,
412 )
413 return self._stubs["list_schemas"]
414
415 @property
416 def list_schema_revisions(
417 self,
418 ) -> Callable[
419 [schema.ListSchemaRevisionsRequest],
420 Awaitable[schema.ListSchemaRevisionsResponse],
421 ]:
422 r"""Return a callable for the list schema revisions method over gRPC.
423
424 Lists all schema revisions for the named schema.
425
426 Returns:
427 Callable[[~.ListSchemaRevisionsRequest],
428 Awaitable[~.ListSchemaRevisionsResponse]]:
429 A function that, when called, will call the underlying RPC
430 on the server.
431 """
432 # Generate a "stub function" on-the-fly which will actually make
433 # the request.
434 # gRPC handles serialization and deserialization, so we just need
435 # to pass in the functions for each.
436 if "list_schema_revisions" not in self._stubs:
437 self._stubs["list_schema_revisions"] = self._logged_channel.unary_unary(
438 "/google.pubsub.v1.SchemaService/ListSchemaRevisions",
439 request_serializer=schema.ListSchemaRevisionsRequest.serialize,
440 response_deserializer=schema.ListSchemaRevisionsResponse.deserialize,
441 )
442 return self._stubs["list_schema_revisions"]
443
444 @property
445 def commit_schema(
446 self,
447 ) -> Callable[[gp_schema.CommitSchemaRequest], Awaitable[gp_schema.Schema]]:
448 r"""Return a callable for the commit schema method over gRPC.
449
450 Commits a new schema revision to an existing schema.
451
452 Returns:
453 Callable[[~.CommitSchemaRequest],
454 Awaitable[~.Schema]]:
455 A function that, when called, will call the underlying RPC
456 on the server.
457 """
458 # Generate a "stub function" on-the-fly which will actually make
459 # the request.
460 # gRPC handles serialization and deserialization, so we just need
461 # to pass in the functions for each.
462 if "commit_schema" not in self._stubs:
463 self._stubs["commit_schema"] = self._logged_channel.unary_unary(
464 "/google.pubsub.v1.SchemaService/CommitSchema",
465 request_serializer=gp_schema.CommitSchemaRequest.serialize,
466 response_deserializer=gp_schema.Schema.deserialize,
467 )
468 return self._stubs["commit_schema"]
469
470 @property
471 def rollback_schema(
472 self,
473 ) -> Callable[[schema.RollbackSchemaRequest], Awaitable[schema.Schema]]:
474 r"""Return a callable for the rollback schema method over gRPC.
475
476 Creates a new schema revision that is a copy of the provided
477 revision_id.
478
479 Returns:
480 Callable[[~.RollbackSchemaRequest],
481 Awaitable[~.Schema]]:
482 A function that, when called, will call the underlying RPC
483 on the server.
484 """
485 # Generate a "stub function" on-the-fly which will actually make
486 # the request.
487 # gRPC handles serialization and deserialization, so we just need
488 # to pass in the functions for each.
489 if "rollback_schema" not in self._stubs:
490 self._stubs["rollback_schema"] = self._logged_channel.unary_unary(
491 "/google.pubsub.v1.SchemaService/RollbackSchema",
492 request_serializer=schema.RollbackSchemaRequest.serialize,
493 response_deserializer=schema.Schema.deserialize,
494 )
495 return self._stubs["rollback_schema"]
496
497 @property
498 def delete_schema_revision(
499 self,
500 ) -> Callable[[schema.DeleteSchemaRevisionRequest], Awaitable[schema.Schema]]:
501 r"""Return a callable for the delete schema revision method over gRPC.
502
503 Deletes a specific schema revision.
504
505 Returns:
506 Callable[[~.DeleteSchemaRevisionRequest],
507 Awaitable[~.Schema]]:
508 A function that, when called, will call the underlying RPC
509 on the server.
510 """
511 # Generate a "stub function" on-the-fly which will actually make
512 # the request.
513 # gRPC handles serialization and deserialization, so we just need
514 # to pass in the functions for each.
515 if "delete_schema_revision" not in self._stubs:
516 self._stubs["delete_schema_revision"] = self._logged_channel.unary_unary(
517 "/google.pubsub.v1.SchemaService/DeleteSchemaRevision",
518 request_serializer=schema.DeleteSchemaRevisionRequest.serialize,
519 response_deserializer=schema.Schema.deserialize,
520 )
521 return self._stubs["delete_schema_revision"]
522
523 @property
524 def delete_schema(
525 self,
526 ) -> Callable[[schema.DeleteSchemaRequest], Awaitable[empty_pb2.Empty]]:
527 r"""Return a callable for the delete schema method over gRPC.
528
529 Deletes a schema.
530
531 Returns:
532 Callable[[~.DeleteSchemaRequest],
533 Awaitable[~.Empty]]:
534 A function that, when called, will call the underlying RPC
535 on the server.
536 """
537 # Generate a "stub function" on-the-fly which will actually make
538 # the request.
539 # gRPC handles serialization and deserialization, so we just need
540 # to pass in the functions for each.
541 if "delete_schema" not in self._stubs:
542 self._stubs["delete_schema"] = self._logged_channel.unary_unary(
543 "/google.pubsub.v1.SchemaService/DeleteSchema",
544 request_serializer=schema.DeleteSchemaRequest.serialize,
545 response_deserializer=empty_pb2.Empty.FromString,
546 )
547 return self._stubs["delete_schema"]
548
549 @property
550 def validate_schema(
551 self,
552 ) -> Callable[
553 [gp_schema.ValidateSchemaRequest], Awaitable[gp_schema.ValidateSchemaResponse]
554 ]:
555 r"""Return a callable for the validate schema method over gRPC.
556
557 Validates a schema.
558
559 Returns:
560 Callable[[~.ValidateSchemaRequest],
561 Awaitable[~.ValidateSchemaResponse]]:
562 A function that, when called, will call the underlying RPC
563 on the server.
564 """
565 # Generate a "stub function" on-the-fly which will actually make
566 # the request.
567 # gRPC handles serialization and deserialization, so we just need
568 # to pass in the functions for each.
569 if "validate_schema" not in self._stubs:
570 self._stubs["validate_schema"] = self._logged_channel.unary_unary(
571 "/google.pubsub.v1.SchemaService/ValidateSchema",
572 request_serializer=gp_schema.ValidateSchemaRequest.serialize,
573 response_deserializer=gp_schema.ValidateSchemaResponse.deserialize,
574 )
575 return self._stubs["validate_schema"]
576
577 @property
578 def validate_message(
579 self,
580 ) -> Callable[
581 [schema.ValidateMessageRequest], Awaitable[schema.ValidateMessageResponse]
582 ]:
583 r"""Return a callable for the validate message method over gRPC.
584
585 Validates a message against a schema.
586
587 Returns:
588 Callable[[~.ValidateMessageRequest],
589 Awaitable[~.ValidateMessageResponse]]:
590 A function that, when called, will call the underlying RPC
591 on the server.
592 """
593 # Generate a "stub function" on-the-fly which will actually make
594 # the request.
595 # gRPC handles serialization and deserialization, so we just need
596 # to pass in the functions for each.
597 if "validate_message" not in self._stubs:
598 self._stubs["validate_message"] = self._logged_channel.unary_unary(
599 "/google.pubsub.v1.SchemaService/ValidateMessage",
600 request_serializer=schema.ValidateMessageRequest.serialize,
601 response_deserializer=schema.ValidateMessageResponse.deserialize,
602 )
603 return self._stubs["validate_message"]
604
605 def _prep_wrapped_messages(self, client_info):
606 """Precompute the wrapped methods, overriding the base class method to use async wrappers."""
607 self._wrapped_methods = {
608 self.create_schema: self._wrap_method(
609 self.create_schema,
610 default_retry=retries.AsyncRetry(
611 initial=0.1,
612 maximum=60.0,
613 multiplier=1.3,
614 predicate=retries.if_exception_type(
615 core_exceptions.ServiceUnavailable,
616 ),
617 deadline=60.0,
618 ),
619 default_timeout=60.0,
620 client_info=client_info,
621 ),
622 self.get_schema: self._wrap_method(
623 self.get_schema,
624 default_retry=retries.AsyncRetry(
625 initial=0.1,
626 maximum=60.0,
627 multiplier=1.3,
628 predicate=retries.if_exception_type(
629 core_exceptions.ServiceUnavailable,
630 ),
631 deadline=60.0,
632 ),
633 default_timeout=60.0,
634 client_info=client_info,
635 ),
636 self.list_schemas: self._wrap_method(
637 self.list_schemas,
638 default_retry=retries.AsyncRetry(
639 initial=0.1,
640 maximum=60.0,
641 multiplier=1.3,
642 predicate=retries.if_exception_type(
643 core_exceptions.ServiceUnavailable,
644 ),
645 deadline=60.0,
646 ),
647 default_timeout=60.0,
648 client_info=client_info,
649 ),
650 self.list_schema_revisions: self._wrap_method(
651 self.list_schema_revisions,
652 default_retry=retries.AsyncRetry(
653 initial=0.1,
654 maximum=60.0,
655 multiplier=1.3,
656 predicate=retries.if_exception_type(
657 core_exceptions.ServiceUnavailable,
658 ),
659 deadline=60.0,
660 ),
661 default_timeout=60.0,
662 client_info=client_info,
663 ),
664 self.commit_schema: self._wrap_method(
665 self.commit_schema,
666 default_retry=retries.AsyncRetry(
667 initial=0.1,
668 maximum=60.0,
669 multiplier=1.3,
670 predicate=retries.if_exception_type(
671 core_exceptions.ServiceUnavailable,
672 ),
673 deadline=60.0,
674 ),
675 default_timeout=60.0,
676 client_info=client_info,
677 ),
678 self.rollback_schema: self._wrap_method(
679 self.rollback_schema,
680 default_retry=retries.AsyncRetry(
681 initial=0.1,
682 maximum=60.0,
683 multiplier=1.3,
684 predicate=retries.if_exception_type(
685 core_exceptions.ServiceUnavailable,
686 ),
687 deadline=60.0,
688 ),
689 default_timeout=60.0,
690 client_info=client_info,
691 ),
692 self.delete_schema_revision: self._wrap_method(
693 self.delete_schema_revision,
694 default_retry=retries.AsyncRetry(
695 initial=0.1,
696 maximum=60.0,
697 multiplier=1.3,
698 predicate=retries.if_exception_type(
699 core_exceptions.ServiceUnavailable,
700 ),
701 deadline=60.0,
702 ),
703 default_timeout=60.0,
704 client_info=client_info,
705 ),
706 self.delete_schema: self._wrap_method(
707 self.delete_schema,
708 default_retry=retries.AsyncRetry(
709 initial=0.1,
710 maximum=60.0,
711 multiplier=1.3,
712 predicate=retries.if_exception_type(
713 core_exceptions.ServiceUnavailable,
714 ),
715 deadline=60.0,
716 ),
717 default_timeout=60.0,
718 client_info=client_info,
719 ),
720 self.validate_schema: self._wrap_method(
721 self.validate_schema,
722 default_retry=retries.AsyncRetry(
723 initial=0.1,
724 maximum=60.0,
725 multiplier=1.3,
726 predicate=retries.if_exception_type(
727 core_exceptions.ServiceUnavailable,
728 ),
729 deadline=60.0,
730 ),
731 default_timeout=60.0,
732 client_info=client_info,
733 ),
734 self.validate_message: self._wrap_method(
735 self.validate_message,
736 default_retry=retries.AsyncRetry(
737 initial=0.1,
738 maximum=60.0,
739 multiplier=1.3,
740 predicate=retries.if_exception_type(
741 core_exceptions.ServiceUnavailable,
742 ),
743 deadline=60.0,
744 ),
745 default_timeout=60.0,
746 client_info=client_info,
747 ),
748 self.get_iam_policy: self._wrap_method(
749 self.get_iam_policy,
750 default_timeout=None,
751 client_info=client_info,
752 ),
753 self.set_iam_policy: self._wrap_method(
754 self.set_iam_policy,
755 default_timeout=None,
756 client_info=client_info,
757 ),
758 self.test_iam_permissions: self._wrap_method(
759 self.test_iam_permissions,
760 default_timeout=None,
761 client_info=client_info,
762 ),
763 }
764
765 def _wrap_method(self, func, *args, **kwargs):
766 if self._wrap_with_kind: # pragma: NO COVER
767 kwargs["kind"] = self.kind
768 return gapic_v1.method_async.wrap_method(func, *args, **kwargs)
769
770 def close(self):
771 return self._logged_channel.close()
772
773 @property
774 def kind(self) -> str:
775 return "grpc_asyncio"
776
777 @property
778 def set_iam_policy(
779 self,
780 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]:
781 r"""Return a callable for the set iam policy method over gRPC.
782 Sets the IAM access control policy on the specified
783 function. Replaces any existing policy.
784 Returns:
785 Callable[[~.SetIamPolicyRequest],
786 ~.Policy]:
787 A function that, when called, will call the underlying RPC
788 on the server.
789 """
790 # Generate a "stub function" on-the-fly which will actually make
791 # the request.
792 # gRPC handles serialization and deserialization, so we just need
793 # to pass in the functions for each.
794 if "set_iam_policy" not in self._stubs:
795 self._stubs["set_iam_policy"] = self._logged_channel.unary_unary(
796 "/google.iam.v1.IAMPolicy/SetIamPolicy",
797 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString,
798 response_deserializer=policy_pb2.Policy.FromString,
799 )
800 return self._stubs["set_iam_policy"]
801
802 @property
803 def get_iam_policy(
804 self,
805 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]:
806 r"""Return a callable for the get iam policy method over gRPC.
807 Gets the IAM access control policy for a function.
808 Returns an empty policy if the function exists and does
809 not have a policy set.
810 Returns:
811 Callable[[~.GetIamPolicyRequest],
812 ~.Policy]:
813 A function that, when called, will call the underlying RPC
814 on the server.
815 """
816 # Generate a "stub function" on-the-fly which will actually make
817 # the request.
818 # gRPC handles serialization and deserialization, so we just need
819 # to pass in the functions for each.
820 if "get_iam_policy" not in self._stubs:
821 self._stubs["get_iam_policy"] = self._logged_channel.unary_unary(
822 "/google.iam.v1.IAMPolicy/GetIamPolicy",
823 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString,
824 response_deserializer=policy_pb2.Policy.FromString,
825 )
826 return self._stubs["get_iam_policy"]
827
828 @property
829 def test_iam_permissions(
830 self,
831 ) -> Callable[
832 [iam_policy_pb2.TestIamPermissionsRequest],
833 iam_policy_pb2.TestIamPermissionsResponse,
834 ]:
835 r"""Return a callable for the test iam permissions method over gRPC.
836 Tests the specified permissions against the IAM access control
837 policy for a function. If the function does not exist, this will
838 return an empty set of permissions, not a NOT_FOUND error.
839 Returns:
840 Callable[[~.TestIamPermissionsRequest],
841 ~.TestIamPermissionsResponse]:
842 A function that, when called, will call the underlying RPC
843 on the server.
844 """
845 # Generate a "stub function" on-the-fly which will actually make
846 # the request.
847 # gRPC handles serialization and deserialization, so we just need
848 # to pass in the functions for each.
849 if "test_iam_permissions" not in self._stubs:
850 self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary(
851 "/google.iam.v1.IAMPolicy/TestIamPermissions",
852 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString,
853 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString,
854 )
855 return self._stubs["test_iam_permissions"]
856
857
858__all__ = ("SchemaServiceGrpcAsyncIOTransport",)