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 json
17import logging as std_logging
18import pickle
19import warnings
20from typing import Callable, Dict, Optional, Sequence, Tuple, Union
21
22from google.api_core import grpc_helpers
23from google.api_core import gapic_v1
24import google.auth # type: ignore
25from google.auth import credentials as ga_credentials # type: ignore
26from google.auth.transport.grpc import SslCredentials # type: ignore
27from google.protobuf.json_format import MessageToJson
28import google.protobuf.message
29
30import grpc # type: ignore
31import proto # type: ignore
32
33from google.iam.v1 import iam_policy_pb2 # type: ignore
34from google.iam.v1 import policy_pb2 # type: ignore
35from google.protobuf import empty_pb2 # type: ignore
36from google.pubsub_v1.types import pubsub
37from .base import PublisherTransport, DEFAULT_CLIENT_INFO
38
39try:
40 from google.api_core import client_logging # type: ignore
41
42 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
43except ImportError: # pragma: NO COVER
44 CLIENT_LOGGING_SUPPORTED = False
45
46_LOGGER = std_logging.getLogger(__name__)
47
48
49class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER
50 def intercept_unary_unary(self, continuation, client_call_details, request):
51 logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
52 std_logging.DEBUG
53 )
54 if logging_enabled: # pragma: NO COVER
55 request_metadata = client_call_details.metadata
56 if isinstance(request, proto.Message):
57 request_payload = type(request).to_json(request)
58 elif isinstance(request, google.protobuf.message.Message):
59 request_payload = MessageToJson(request)
60 else:
61 request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
62
63 request_metadata = {
64 key: value.decode("utf-8") if isinstance(value, bytes) else value
65 for key, value in request_metadata
66 }
67 grpc_request = {
68 "payload": request_payload,
69 "requestMethod": "grpc",
70 "metadata": dict(request_metadata),
71 }
72 _LOGGER.debug(
73 f"Sending request for {client_call_details.method}",
74 extra={
75 "serviceName": "google.pubsub.v1.Publisher",
76 "rpcName": str(client_call_details.method),
77 "request": grpc_request,
78 "metadata": grpc_request["metadata"],
79 },
80 )
81 response = continuation(client_call_details, request)
82 if logging_enabled: # pragma: NO COVER
83 response_metadata = response.trailing_metadata()
84 # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
85 metadata = (
86 dict([(k, str(v)) for k, v in response_metadata])
87 if response_metadata
88 else None
89 )
90 result = response.result()
91 if isinstance(result, proto.Message):
92 response_payload = type(result).to_json(result)
93 elif isinstance(result, google.protobuf.message.Message):
94 response_payload = MessageToJson(result)
95 else:
96 response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
97 grpc_response = {
98 "payload": response_payload,
99 "metadata": metadata,
100 "status": "OK",
101 }
102 _LOGGER.debug(
103 f"Received response for {client_call_details.method}.",
104 extra={
105 "serviceName": "google.pubsub.v1.Publisher",
106 "rpcName": client_call_details.method,
107 "response": grpc_response,
108 "metadata": grpc_response["metadata"],
109 },
110 )
111 return response
112
113
114class PublisherGrpcTransport(PublisherTransport):
115 """gRPC backend transport for Publisher.
116
117 The service that an application uses to manipulate topics,
118 and to send messages to a topic.
119
120 This class defines the same methods as the primary client, so the
121 primary client can load the underlying transport implementation
122 and call it.
123
124 It sends protocol buffers over the wire using gRPC (which is built on
125 top of HTTP/2); the ``grpcio`` package must be installed.
126 """
127
128 _stubs: Dict[str, Callable]
129
130 def __init__(
131 self,
132 *,
133 host: str = "pubsub.googleapis.com",
134 credentials: Optional[ga_credentials.Credentials] = None,
135 credentials_file: Optional[str] = None,
136 scopes: Optional[Sequence[str]] = None,
137 channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
138 api_mtls_endpoint: Optional[str] = None,
139 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
140 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
141 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
142 quota_project_id: Optional[str] = None,
143 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
144 always_use_jwt_access: Optional[bool] = False,
145 api_audience: Optional[str] = None,
146 ) -> None:
147 """Instantiate the transport.
148
149 Args:
150 host (Optional[str]):
151 The hostname to connect to (default: 'pubsub.googleapis.com').
152 credentials (Optional[google.auth.credentials.Credentials]): The
153 authorization credentials to attach to requests. These
154 credentials identify the application to the service; if none
155 are specified, the client will attempt to ascertain the
156 credentials from the environment.
157 This argument is ignored if a ``channel`` instance is provided.
158 credentials_file (Optional[str]): Deprecated. A file with credentials that can
159 be loaded with :func:`google.auth.load_credentials_from_file`.
160 This argument is ignored if a ``channel`` instance is provided.
161 This argument will be removed in the next major version of this library.
162 scopes (Optional(Sequence[str])): A list of scopes. This argument is
163 ignored if a ``channel`` instance is provided.
164 channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
165 A ``Channel`` instance through which to make calls, or a Callable
166 that constructs and returns one. If set to None, ``self.create_channel``
167 is used to create the channel. If a Callable is given, it will be called
168 with the same arguments as used in ``self.create_channel``.
169 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
170 If provided, it overrides the ``host`` argument and tries to create
171 a mutual TLS channel with client SSL credentials from
172 ``client_cert_source`` or application default SSL credentials.
173 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
174 Deprecated. A callback to provide client SSL certificate bytes and
175 private key bytes, both in PEM format. It is ignored if
176 ``api_mtls_endpoint`` is None.
177 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
178 for the grpc channel. It is ignored if a ``channel`` instance is provided.
179 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
180 A callback to provide client certificate bytes and private key bytes,
181 both in PEM format. It is used to configure a mutual TLS channel. It is
182 ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
183 quota_project_id (Optional[str]): An optional project to use for billing
184 and quota.
185 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
186 The client info used to send a user-agent string along with
187 API requests. If ``None``, then default info will be used.
188 Generally, you only need to set this if you're developing
189 your own client library.
190 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
191 be used for service account credentials.
192
193 Raises:
194 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
195 creation failed for any reason.
196 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
197 and ``credentials_file`` are passed.
198 """
199 self._grpc_channel = None
200 self._ssl_channel_credentials = ssl_channel_credentials
201 self._stubs: Dict[str, Callable] = {}
202
203 if api_mtls_endpoint:
204 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
205 if client_cert_source:
206 warnings.warn("client_cert_source is deprecated", DeprecationWarning)
207
208 if isinstance(channel, grpc.Channel):
209 # Ignore credentials if a channel was passed.
210 credentials = None
211 self._ignore_credentials = True
212 # If a channel was explicitly provided, set it.
213 self._grpc_channel = channel
214 self._ssl_channel_credentials = None
215
216 else:
217 if api_mtls_endpoint:
218 host = api_mtls_endpoint
219
220 # Create SSL credentials with client_cert_source or application
221 # default SSL credentials.
222 if client_cert_source:
223 cert, key = client_cert_source()
224 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
225 certificate_chain=cert, private_key=key
226 )
227 else:
228 self._ssl_channel_credentials = SslCredentials().ssl_credentials
229
230 else:
231 if client_cert_source_for_mtls and not ssl_channel_credentials:
232 cert, key = client_cert_source_for_mtls()
233 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
234 certificate_chain=cert, private_key=key
235 )
236
237 # The base transport sets the host, credentials and scopes
238 super().__init__(
239 host=host,
240 credentials=credentials,
241 credentials_file=credentials_file,
242 scopes=scopes,
243 quota_project_id=quota_project_id,
244 client_info=client_info,
245 always_use_jwt_access=always_use_jwt_access,
246 api_audience=api_audience,
247 )
248
249 if not self._grpc_channel:
250 # initialize with the provided callable or the default channel
251 channel_init = channel or type(self).create_channel
252 self._grpc_channel = channel_init(
253 self._host,
254 # use the credentials which are saved
255 credentials=self._credentials,
256 # Set ``credentials_file`` to ``None`` here as
257 # the credentials that we saved earlier should be used.
258 credentials_file=None,
259 scopes=self._scopes,
260 ssl_credentials=self._ssl_channel_credentials,
261 quota_project_id=quota_project_id,
262 options=[
263 ("grpc.max_send_message_length", -1),
264 ("grpc.max_receive_message_length", -1),
265 ("grpc.max_metadata_size", 4 * 1024 * 1024),
266 ("grpc.keepalive_time_ms", 30000),
267 ],
268 )
269
270 self._interceptor = _LoggingClientInterceptor()
271 self._logged_channel = grpc.intercept_channel(
272 self._grpc_channel, self._interceptor
273 )
274
275 # Wrap messages. This must be done after self._logged_channel exists
276 self._prep_wrapped_messages(client_info)
277
278 @classmethod
279 def create_channel(
280 cls,
281 host: str = "pubsub.googleapis.com",
282 credentials: Optional[ga_credentials.Credentials] = None,
283 credentials_file: Optional[str] = None,
284 scopes: Optional[Sequence[str]] = None,
285 quota_project_id: Optional[str] = None,
286 **kwargs,
287 ) -> grpc.Channel:
288 """Create and return a gRPC channel object.
289 Args:
290 host (Optional[str]): The host for the channel to use.
291 credentials (Optional[~.Credentials]): The
292 authorization credentials to attach to requests. These
293 credentials identify this application to the service. If
294 none are specified, the client will attempt to ascertain
295 the credentials from the environment.
296 credentials_file (Optional[str]): Deprecated. A file with credentials that can
297 be loaded with :func:`google.auth.load_credentials_from_file`.
298 This argument is mutually exclusive with credentials. This argument will be
299 removed in the next major version of this library.
300 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
301 service. These are only used when credentials are not specified and
302 are passed to :func:`google.auth.default`.
303 quota_project_id (Optional[str]): An optional project to use for billing
304 and quota.
305 kwargs (Optional[dict]): Keyword arguments, which are passed to the
306 channel creation.
307 Returns:
308 grpc.Channel: A gRPC channel object.
309
310 Raises:
311 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
312 and ``credentials_file`` are passed.
313 """
314
315 return grpc_helpers.create_channel(
316 host,
317 credentials=credentials,
318 credentials_file=credentials_file,
319 quota_project_id=quota_project_id,
320 default_scopes=cls.AUTH_SCOPES,
321 scopes=scopes,
322 default_host=cls.DEFAULT_HOST,
323 **kwargs,
324 )
325
326 @property
327 def grpc_channel(self) -> grpc.Channel:
328 """Return the channel designed to connect to this service."""
329 return self._grpc_channel
330
331 @property
332 def create_topic(self) -> Callable[[pubsub.Topic], pubsub.Topic]:
333 r"""Return a callable for the create topic method over gRPC.
334
335 Creates the given topic with the given name. See the [resource
336 name rules]
337 (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names).
338
339 Returns:
340 Callable[[~.Topic],
341 ~.Topic]:
342 A function that, when called, will call the underlying RPC
343 on the server.
344 """
345 # Generate a "stub function" on-the-fly which will actually make
346 # the request.
347 # gRPC handles serialization and deserialization, so we just need
348 # to pass in the functions for each.
349 if "create_topic" not in self._stubs:
350 self._stubs["create_topic"] = self._logged_channel.unary_unary(
351 "/google.pubsub.v1.Publisher/CreateTopic",
352 request_serializer=pubsub.Topic.serialize,
353 response_deserializer=pubsub.Topic.deserialize,
354 )
355 return self._stubs["create_topic"]
356
357 @property
358 def update_topic(self) -> Callable[[pubsub.UpdateTopicRequest], pubsub.Topic]:
359 r"""Return a callable for the update topic method over gRPC.
360
361 Updates an existing topic by updating the fields
362 specified in the update mask. Note that certain
363 properties of a topic are not modifiable.
364
365 Returns:
366 Callable[[~.UpdateTopicRequest],
367 ~.Topic]:
368 A function that, when called, will call the underlying RPC
369 on the server.
370 """
371 # Generate a "stub function" on-the-fly which will actually make
372 # the request.
373 # gRPC handles serialization and deserialization, so we just need
374 # to pass in the functions for each.
375 if "update_topic" not in self._stubs:
376 self._stubs["update_topic"] = self._logged_channel.unary_unary(
377 "/google.pubsub.v1.Publisher/UpdateTopic",
378 request_serializer=pubsub.UpdateTopicRequest.serialize,
379 response_deserializer=pubsub.Topic.deserialize,
380 )
381 return self._stubs["update_topic"]
382
383 @property
384 def publish(self) -> Callable[[pubsub.PublishRequest], pubsub.PublishResponse]:
385 r"""Return a callable for the publish method over gRPC.
386
387 Adds one or more messages to the topic. Returns ``NOT_FOUND`` if
388 the topic does not exist.
389
390 Returns:
391 Callable[[~.PublishRequest],
392 ~.PublishResponse]:
393 A function that, when called, will call the underlying RPC
394 on the server.
395 """
396 # Generate a "stub function" on-the-fly which will actually make
397 # the request.
398 # gRPC handles serialization and deserialization, so we just need
399 # to pass in the functions for each.
400 if "publish" not in self._stubs:
401 self._stubs["publish"] = self._logged_channel.unary_unary(
402 "/google.pubsub.v1.Publisher/Publish",
403 request_serializer=pubsub.PublishRequest.serialize,
404 response_deserializer=pubsub.PublishResponse.deserialize,
405 )
406 return self._stubs["publish"]
407
408 @property
409 def get_topic(self) -> Callable[[pubsub.GetTopicRequest], pubsub.Topic]:
410 r"""Return a callable for the get topic method over gRPC.
411
412 Gets the configuration of a topic.
413
414 Returns:
415 Callable[[~.GetTopicRequest],
416 ~.Topic]:
417 A function that, when called, will call the underlying RPC
418 on the server.
419 """
420 # Generate a "stub function" on-the-fly which will actually make
421 # the request.
422 # gRPC handles serialization and deserialization, so we just need
423 # to pass in the functions for each.
424 if "get_topic" not in self._stubs:
425 self._stubs["get_topic"] = self._logged_channel.unary_unary(
426 "/google.pubsub.v1.Publisher/GetTopic",
427 request_serializer=pubsub.GetTopicRequest.serialize,
428 response_deserializer=pubsub.Topic.deserialize,
429 )
430 return self._stubs["get_topic"]
431
432 @property
433 def list_topics(
434 self,
435 ) -> Callable[[pubsub.ListTopicsRequest], pubsub.ListTopicsResponse]:
436 r"""Return a callable for the list topics method over gRPC.
437
438 Lists matching topics.
439
440 Returns:
441 Callable[[~.ListTopicsRequest],
442 ~.ListTopicsResponse]:
443 A function that, when called, will call the underlying RPC
444 on the server.
445 """
446 # Generate a "stub function" on-the-fly which will actually make
447 # the request.
448 # gRPC handles serialization and deserialization, so we just need
449 # to pass in the functions for each.
450 if "list_topics" not in self._stubs:
451 self._stubs["list_topics"] = self._logged_channel.unary_unary(
452 "/google.pubsub.v1.Publisher/ListTopics",
453 request_serializer=pubsub.ListTopicsRequest.serialize,
454 response_deserializer=pubsub.ListTopicsResponse.deserialize,
455 )
456 return self._stubs["list_topics"]
457
458 @property
459 def list_topic_subscriptions(
460 self,
461 ) -> Callable[
462 [pubsub.ListTopicSubscriptionsRequest], pubsub.ListTopicSubscriptionsResponse
463 ]:
464 r"""Return a callable for the list topic subscriptions method over gRPC.
465
466 Lists the names of the attached subscriptions on this
467 topic.
468
469 Returns:
470 Callable[[~.ListTopicSubscriptionsRequest],
471 ~.ListTopicSubscriptionsResponse]:
472 A function that, when called, will call the underlying RPC
473 on the server.
474 """
475 # Generate a "stub function" on-the-fly which will actually make
476 # the request.
477 # gRPC handles serialization and deserialization, so we just need
478 # to pass in the functions for each.
479 if "list_topic_subscriptions" not in self._stubs:
480 self._stubs["list_topic_subscriptions"] = self._logged_channel.unary_unary(
481 "/google.pubsub.v1.Publisher/ListTopicSubscriptions",
482 request_serializer=pubsub.ListTopicSubscriptionsRequest.serialize,
483 response_deserializer=pubsub.ListTopicSubscriptionsResponse.deserialize,
484 )
485 return self._stubs["list_topic_subscriptions"]
486
487 @property
488 def list_topic_snapshots(
489 self,
490 ) -> Callable[
491 [pubsub.ListTopicSnapshotsRequest], pubsub.ListTopicSnapshotsResponse
492 ]:
493 r"""Return a callable for the list topic snapshots method over gRPC.
494
495 Lists the names of the snapshots on this topic. Snapshots are
496 used in
497 `Seek <https://cloud.google.com/pubsub/docs/replay-overview>`__
498 operations, which allow you to manage message acknowledgments in
499 bulk. That is, you can set the acknowledgment state of messages
500 in an existing subscription to the state captured by a snapshot.
501
502 Returns:
503 Callable[[~.ListTopicSnapshotsRequest],
504 ~.ListTopicSnapshotsResponse]:
505 A function that, when called, will call the underlying RPC
506 on the server.
507 """
508 # Generate a "stub function" on-the-fly which will actually make
509 # the request.
510 # gRPC handles serialization and deserialization, so we just need
511 # to pass in the functions for each.
512 if "list_topic_snapshots" not in self._stubs:
513 self._stubs["list_topic_snapshots"] = self._logged_channel.unary_unary(
514 "/google.pubsub.v1.Publisher/ListTopicSnapshots",
515 request_serializer=pubsub.ListTopicSnapshotsRequest.serialize,
516 response_deserializer=pubsub.ListTopicSnapshotsResponse.deserialize,
517 )
518 return self._stubs["list_topic_snapshots"]
519
520 @property
521 def delete_topic(self) -> Callable[[pubsub.DeleteTopicRequest], empty_pb2.Empty]:
522 r"""Return a callable for the delete topic method over gRPC.
523
524 Deletes the topic with the given name. Returns ``NOT_FOUND`` if
525 the topic does not exist. After a topic is deleted, a new topic
526 may be created with the same name; this is an entirely new topic
527 with none of the old configuration or subscriptions. Existing
528 subscriptions to this topic are not deleted, but their ``topic``
529 field is set to ``_deleted-topic_``.
530
531 Returns:
532 Callable[[~.DeleteTopicRequest],
533 ~.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_topic" not in self._stubs:
542 self._stubs["delete_topic"] = self._logged_channel.unary_unary(
543 "/google.pubsub.v1.Publisher/DeleteTopic",
544 request_serializer=pubsub.DeleteTopicRequest.serialize,
545 response_deserializer=empty_pb2.Empty.FromString,
546 )
547 return self._stubs["delete_topic"]
548
549 @property
550 def detach_subscription(
551 self,
552 ) -> Callable[
553 [pubsub.DetachSubscriptionRequest], pubsub.DetachSubscriptionResponse
554 ]:
555 r"""Return a callable for the detach subscription method over gRPC.
556
557 Detaches a subscription from this topic. All messages retained
558 in the subscription are dropped. Subsequent ``Pull`` and
559 ``StreamingPull`` requests will return FAILED_PRECONDITION. If
560 the subscription is a push subscription, pushes to the endpoint
561 will stop.
562
563 Returns:
564 Callable[[~.DetachSubscriptionRequest],
565 ~.DetachSubscriptionResponse]:
566 A function that, when called, will call the underlying RPC
567 on the server.
568 """
569 # Generate a "stub function" on-the-fly which will actually make
570 # the request.
571 # gRPC handles serialization and deserialization, so we just need
572 # to pass in the functions for each.
573 if "detach_subscription" not in self._stubs:
574 self._stubs["detach_subscription"] = self._logged_channel.unary_unary(
575 "/google.pubsub.v1.Publisher/DetachSubscription",
576 request_serializer=pubsub.DetachSubscriptionRequest.serialize,
577 response_deserializer=pubsub.DetachSubscriptionResponse.deserialize,
578 )
579 return self._stubs["detach_subscription"]
580
581 def close(self):
582 self._logged_channel.close()
583
584 @property
585 def set_iam_policy(
586 self,
587 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]:
588 r"""Return a callable for the set iam policy method over gRPC.
589 Sets the IAM access control policy on the specified
590 function. Replaces any existing policy.
591 Returns:
592 Callable[[~.SetIamPolicyRequest],
593 ~.Policy]:
594 A function that, when called, will call the underlying RPC
595 on the server.
596 """
597 # Generate a "stub function" on-the-fly which will actually make
598 # the request.
599 # gRPC handles serialization and deserialization, so we just need
600 # to pass in the functions for each.
601 if "set_iam_policy" not in self._stubs:
602 self._stubs["set_iam_policy"] = self._logged_channel.unary_unary(
603 "/google.iam.v1.IAMPolicy/SetIamPolicy",
604 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString,
605 response_deserializer=policy_pb2.Policy.FromString,
606 )
607 return self._stubs["set_iam_policy"]
608
609 @property
610 def get_iam_policy(
611 self,
612 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]:
613 r"""Return a callable for the get iam policy method over gRPC.
614 Gets the IAM access control policy for a function.
615 Returns an empty policy if the function exists and does
616 not have a policy set.
617 Returns:
618 Callable[[~.GetIamPolicyRequest],
619 ~.Policy]:
620 A function that, when called, will call the underlying RPC
621 on the server.
622 """
623 # Generate a "stub function" on-the-fly which will actually make
624 # the request.
625 # gRPC handles serialization and deserialization, so we just need
626 # to pass in the functions for each.
627 if "get_iam_policy" not in self._stubs:
628 self._stubs["get_iam_policy"] = self._logged_channel.unary_unary(
629 "/google.iam.v1.IAMPolicy/GetIamPolicy",
630 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString,
631 response_deserializer=policy_pb2.Policy.FromString,
632 )
633 return self._stubs["get_iam_policy"]
634
635 @property
636 def test_iam_permissions(
637 self,
638 ) -> Callable[
639 [iam_policy_pb2.TestIamPermissionsRequest],
640 iam_policy_pb2.TestIamPermissionsResponse,
641 ]:
642 r"""Return a callable for the test iam permissions method over gRPC.
643 Tests the specified permissions against the IAM access control
644 policy for a function. If the function does not exist, this will
645 return an empty set of permissions, not a NOT_FOUND error.
646 Returns:
647 Callable[[~.TestIamPermissionsRequest],
648 ~.TestIamPermissionsResponse]:
649 A function that, when called, will call the underlying RPC
650 on the server.
651 """
652 # Generate a "stub function" on-the-fly which will actually make
653 # the request.
654 # gRPC handles serialization and deserialization, so we just need
655 # to pass in the functions for each.
656 if "test_iam_permissions" not in self._stubs:
657 self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary(
658 "/google.iam.v1.IAMPolicy/TestIamPermissions",
659 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString,
660 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString,
661 )
662 return self._stubs["test_iam_permissions"]
663
664 @property
665 def kind(self) -> str:
666 return "grpc"
667
668
669__all__ = ("PublisherGrpcTransport",)