Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/site-packages/google/pubsub_v1/services/publisher/transports/grpc.py: 46%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

125 statements  

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 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": client_call_details.method, 

77 "request": grpc_request, 

78 "metadata": grpc_request["metadata"], 

79 }, 

80 ) 

81 

82 response = continuation(client_call_details, request) 

83 if logging_enabled: # pragma: NO COVER 

84 response_metadata = response.trailing_metadata() 

85 # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples 

86 metadata = ( 

87 dict([(k, str(v)) for k, v in response_metadata]) 

88 if response_metadata 

89 else None 

90 ) 

91 result = response.result() 

92 if isinstance(result, proto.Message): 

93 response_payload = type(result).to_json(result) 

94 elif isinstance(result, google.protobuf.message.Message): 

95 response_payload = MessageToJson(result) 

96 else: 

97 response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" 

98 grpc_response = { 

99 "payload": response_payload, 

100 "metadata": metadata, 

101 "status": "OK", 

102 } 

103 _LOGGER.debug( 

104 f"Received response for {client_call_details.method}.", 

105 extra={ 

106 "serviceName": "google.pubsub.v1.Publisher", 

107 "rpcName": client_call_details.method, 

108 "response": grpc_response, 

109 "metadata": grpc_response["metadata"], 

110 }, 

111 ) 

112 return response 

113 

114 

115class PublisherGrpcTransport(PublisherTransport): 

116 """gRPC backend transport for Publisher. 

117 

118 The service that an application uses to manipulate topics, 

119 and to send messages to a topic. 

120 

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

122 primary client can load the underlying transport implementation 

123 and call it. 

124 

125 It sends protocol buffers over the wire using gRPC (which is built on 

126 top of HTTP/2); the ``grpcio`` package must be installed. 

127 """ 

128 

129 _stubs: Dict[str, Callable] 

130 

131 def __init__( 

132 self, 

133 *, 

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

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

136 credentials_file: Optional[str] = None, 

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

138 channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, 

139 api_mtls_endpoint: Optional[str] = None, 

140 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

141 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, 

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

143 quota_project_id: Optional[str] = None, 

144 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

145 always_use_jwt_access: Optional[bool] = False, 

146 api_audience: Optional[str] = None, 

147 ) -> None: 

148 """Instantiate the transport. 

149 

150 Args: 

151 host (Optional[str]): 

152 The hostname to connect to (default: 'pubsub.googleapis.com'). 

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

154 authorization credentials to attach to requests. These 

155 credentials identify the application to the service; if none 

156 are specified, the client will attempt to ascertain the 

157 credentials from the environment. 

158 This argument is ignored if a ``channel`` instance is provided. 

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

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

161 This argument is ignored if a ``channel`` instance is provided. 

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]): 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. 

299 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

300 service. These are only used when credentials are not specified and 

301 are passed to :func:`google.auth.default`. 

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

303 and quota. 

304 kwargs (Optional[dict]): Keyword arguments, which are passed to the 

305 channel creation. 

306 Returns: 

307 grpc.Channel: A gRPC channel object. 

308 

309 Raises: 

310 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` 

311 and ``credentials_file`` are passed. 

312 """ 

313 

314 return grpc_helpers.create_channel( 

315 host, 

316 credentials=credentials, 

317 credentials_file=credentials_file, 

318 quota_project_id=quota_project_id, 

319 default_scopes=cls.AUTH_SCOPES, 

320 scopes=scopes, 

321 default_host=cls.DEFAULT_HOST, 

322 **kwargs, 

323 ) 

324 

325 @property 

326 def grpc_channel(self) -> grpc.Channel: 

327 """Return the channel designed to connect to this service.""" 

328 return self._grpc_channel 

329 

330 @property 

331 def create_topic(self) -> Callable[[pubsub.Topic], pubsub.Topic]: 

332 r"""Return a callable for the create topic method over gRPC. 

333 

334 Creates the given topic with the given name. See the [resource 

335 name rules] 

336 (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names). 

337 

338 Returns: 

339 Callable[[~.Topic], 

340 ~.Topic]: 

341 A function that, when called, will call the underlying RPC 

342 on the server. 

343 """ 

344 # Generate a "stub function" on-the-fly which will actually make 

345 # the request. 

346 # gRPC handles serialization and deserialization, so we just need 

347 # to pass in the functions for each. 

348 if "create_topic" not in self._stubs: 

349 self._stubs["create_topic"] = self._logged_channel.unary_unary( 

350 "/google.pubsub.v1.Publisher/CreateTopic", 

351 request_serializer=pubsub.Topic.serialize, 

352 response_deserializer=pubsub.Topic.deserialize, 

353 ) 

354 return self._stubs["create_topic"] 

355 

356 @property 

357 def update_topic(self) -> Callable[[pubsub.UpdateTopicRequest], pubsub.Topic]: 

358 r"""Return a callable for the update topic method over gRPC. 

359 

360 Updates an existing topic by updating the fields 

361 specified in the update mask. Note that certain 

362 properties of a topic are not modifiable. 

363 

364 Returns: 

365 Callable[[~.UpdateTopicRequest], 

366 ~.Topic]: 

367 A function that, when called, will call the underlying RPC 

368 on the server. 

369 """ 

370 # Generate a "stub function" on-the-fly which will actually make 

371 # the request. 

372 # gRPC handles serialization and deserialization, so we just need 

373 # to pass in the functions for each. 

374 if "update_topic" not in self._stubs: 

375 self._stubs["update_topic"] = self._logged_channel.unary_unary( 

376 "/google.pubsub.v1.Publisher/UpdateTopic", 

377 request_serializer=pubsub.UpdateTopicRequest.serialize, 

378 response_deserializer=pubsub.Topic.deserialize, 

379 ) 

380 return self._stubs["update_topic"] 

381 

382 @property 

383 def publish(self) -> Callable[[pubsub.PublishRequest], pubsub.PublishResponse]: 

384 r"""Return a callable for the publish method over gRPC. 

385 

386 Adds one or more messages to the topic. Returns ``NOT_FOUND`` if 

387 the topic does not exist. 

388 

389 Returns: 

390 Callable[[~.PublishRequest], 

391 ~.PublishResponse]: 

392 A function that, when called, will call the underlying RPC 

393 on the server. 

394 """ 

395 # Generate a "stub function" on-the-fly which will actually make 

396 # the request. 

397 # gRPC handles serialization and deserialization, so we just need 

398 # to pass in the functions for each. 

399 if "publish" not in self._stubs: 

400 self._stubs["publish"] = self._logged_channel.unary_unary( 

401 "/google.pubsub.v1.Publisher/Publish", 

402 request_serializer=pubsub.PublishRequest.serialize, 

403 response_deserializer=pubsub.PublishResponse.deserialize, 

404 ) 

405 return self._stubs["publish"] 

406 

407 @property 

408 def get_topic(self) -> Callable[[pubsub.GetTopicRequest], pubsub.Topic]: 

409 r"""Return a callable for the get topic method over gRPC. 

410 

411 Gets the configuration of a topic. 

412 

413 Returns: 

414 Callable[[~.GetTopicRequest], 

415 ~.Topic]: 

416 A function that, when called, will call the underlying RPC 

417 on the server. 

418 """ 

419 # Generate a "stub function" on-the-fly which will actually make 

420 # the request. 

421 # gRPC handles serialization and deserialization, so we just need 

422 # to pass in the functions for each. 

423 if "get_topic" not in self._stubs: 

424 self._stubs["get_topic"] = self._logged_channel.unary_unary( 

425 "/google.pubsub.v1.Publisher/GetTopic", 

426 request_serializer=pubsub.GetTopicRequest.serialize, 

427 response_deserializer=pubsub.Topic.deserialize, 

428 ) 

429 return self._stubs["get_topic"] 

430 

431 @property 

432 def list_topics( 

433 self, 

434 ) -> Callable[[pubsub.ListTopicsRequest], pubsub.ListTopicsResponse]: 

435 r"""Return a callable for the list topics method over gRPC. 

436 

437 Lists matching topics. 

438 

439 Returns: 

440 Callable[[~.ListTopicsRequest], 

441 ~.ListTopicsResponse]: 

442 A function that, when called, will call the underlying RPC 

443 on the server. 

444 """ 

445 # Generate a "stub function" on-the-fly which will actually make 

446 # the request. 

447 # gRPC handles serialization and deserialization, so we just need 

448 # to pass in the functions for each. 

449 if "list_topics" not in self._stubs: 

450 self._stubs["list_topics"] = self._logged_channel.unary_unary( 

451 "/google.pubsub.v1.Publisher/ListTopics", 

452 request_serializer=pubsub.ListTopicsRequest.serialize, 

453 response_deserializer=pubsub.ListTopicsResponse.deserialize, 

454 ) 

455 return self._stubs["list_topics"] 

456 

457 @property 

458 def list_topic_subscriptions( 

459 self, 

460 ) -> Callable[ 

461 [pubsub.ListTopicSubscriptionsRequest], pubsub.ListTopicSubscriptionsResponse 

462 ]: 

463 r"""Return a callable for the list topic subscriptions method over gRPC. 

464 

465 Lists the names of the attached subscriptions on this 

466 topic. 

467 

468 Returns: 

469 Callable[[~.ListTopicSubscriptionsRequest], 

470 ~.ListTopicSubscriptionsResponse]: 

471 A function that, when called, will call the underlying RPC 

472 on the server. 

473 """ 

474 # Generate a "stub function" on-the-fly which will actually make 

475 # the request. 

476 # gRPC handles serialization and deserialization, so we just need 

477 # to pass in the functions for each. 

478 if "list_topic_subscriptions" not in self._stubs: 

479 self._stubs["list_topic_subscriptions"] = self._logged_channel.unary_unary( 

480 "/google.pubsub.v1.Publisher/ListTopicSubscriptions", 

481 request_serializer=pubsub.ListTopicSubscriptionsRequest.serialize, 

482 response_deserializer=pubsub.ListTopicSubscriptionsResponse.deserialize, 

483 ) 

484 return self._stubs["list_topic_subscriptions"] 

485 

486 @property 

487 def list_topic_snapshots( 

488 self, 

489 ) -> Callable[ 

490 [pubsub.ListTopicSnapshotsRequest], pubsub.ListTopicSnapshotsResponse 

491 ]: 

492 r"""Return a callable for the list topic snapshots method over gRPC. 

493 

494 Lists the names of the snapshots on this topic. Snapshots are 

495 used in 

496 `Seek <https://cloud.google.com/pubsub/docs/replay-overview>`__ 

497 operations, which allow you to manage message acknowledgments in 

498 bulk. That is, you can set the acknowledgment state of messages 

499 in an existing subscription to the state captured by a snapshot. 

500 

501 Returns: 

502 Callable[[~.ListTopicSnapshotsRequest], 

503 ~.ListTopicSnapshotsResponse]: 

504 A function that, when called, will call the underlying RPC 

505 on the server. 

506 """ 

507 # Generate a "stub function" on-the-fly which will actually make 

508 # the request. 

509 # gRPC handles serialization and deserialization, so we just need 

510 # to pass in the functions for each. 

511 if "list_topic_snapshots" not in self._stubs: 

512 self._stubs["list_topic_snapshots"] = self._logged_channel.unary_unary( 

513 "/google.pubsub.v1.Publisher/ListTopicSnapshots", 

514 request_serializer=pubsub.ListTopicSnapshotsRequest.serialize, 

515 response_deserializer=pubsub.ListTopicSnapshotsResponse.deserialize, 

516 ) 

517 return self._stubs["list_topic_snapshots"] 

518 

519 @property 

520 def delete_topic(self) -> Callable[[pubsub.DeleteTopicRequest], empty_pb2.Empty]: 

521 r"""Return a callable for the delete topic method over gRPC. 

522 

523 Deletes the topic with the given name. Returns ``NOT_FOUND`` if 

524 the topic does not exist. After a topic is deleted, a new topic 

525 may be created with the same name; this is an entirely new topic 

526 with none of the old configuration or subscriptions. Existing 

527 subscriptions to this topic are not deleted, but their ``topic`` 

528 field is set to ``_deleted-topic_``. 

529 

530 Returns: 

531 Callable[[~.DeleteTopicRequest], 

532 ~.Empty]: 

533 A function that, when called, will call the underlying RPC 

534 on the server. 

535 """ 

536 # Generate a "stub function" on-the-fly which will actually make 

537 # the request. 

538 # gRPC handles serialization and deserialization, so we just need 

539 # to pass in the functions for each. 

540 if "delete_topic" not in self._stubs: 

541 self._stubs["delete_topic"] = self._logged_channel.unary_unary( 

542 "/google.pubsub.v1.Publisher/DeleteTopic", 

543 request_serializer=pubsub.DeleteTopicRequest.serialize, 

544 response_deserializer=empty_pb2.Empty.FromString, 

545 ) 

546 return self._stubs["delete_topic"] 

547 

548 @property 

549 def detach_subscription( 

550 self, 

551 ) -> Callable[ 

552 [pubsub.DetachSubscriptionRequest], pubsub.DetachSubscriptionResponse 

553 ]: 

554 r"""Return a callable for the detach subscription method over gRPC. 

555 

556 Detaches a subscription from this topic. All messages retained 

557 in the subscription are dropped. Subsequent ``Pull`` and 

558 ``StreamingPull`` requests will return FAILED_PRECONDITION. If 

559 the subscription is a push subscription, pushes to the endpoint 

560 will stop. 

561 

562 Returns: 

563 Callable[[~.DetachSubscriptionRequest], 

564 ~.DetachSubscriptionResponse]: 

565 A function that, when called, will call the underlying RPC 

566 on the server. 

567 """ 

568 # Generate a "stub function" on-the-fly which will actually make 

569 # the request. 

570 # gRPC handles serialization and deserialization, so we just need 

571 # to pass in the functions for each. 

572 if "detach_subscription" not in self._stubs: 

573 self._stubs["detach_subscription"] = self._logged_channel.unary_unary( 

574 "/google.pubsub.v1.Publisher/DetachSubscription", 

575 request_serializer=pubsub.DetachSubscriptionRequest.serialize, 

576 response_deserializer=pubsub.DetachSubscriptionResponse.deserialize, 

577 ) 

578 return self._stubs["detach_subscription"] 

579 

580 def close(self): 

581 self._logged_channel.close() 

582 

583 @property 

584 def set_iam_policy( 

585 self, 

586 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: 

587 r"""Return a callable for the set iam policy method over gRPC. 

588 Sets the IAM access control policy on the specified 

589 function. Replaces any existing policy. 

590 Returns: 

591 Callable[[~.SetIamPolicyRequest], 

592 ~.Policy]: 

593 A function that, when called, will call the underlying RPC 

594 on the server. 

595 """ 

596 # Generate a "stub function" on-the-fly which will actually make 

597 # the request. 

598 # gRPC handles serialization and deserialization, so we just need 

599 # to pass in the functions for each. 

600 if "set_iam_policy" not in self._stubs: 

601 self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( 

602 "/google.iam.v1.IAMPolicy/SetIamPolicy", 

603 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

604 response_deserializer=policy_pb2.Policy.FromString, 

605 ) 

606 return self._stubs["set_iam_policy"] 

607 

608 @property 

609 def get_iam_policy( 

610 self, 

611 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: 

612 r"""Return a callable for the get iam policy method over gRPC. 

613 Gets the IAM access control policy for a function. 

614 Returns an empty policy if the function exists and does 

615 not have a policy set. 

616 Returns: 

617 Callable[[~.GetIamPolicyRequest], 

618 ~.Policy]: 

619 A function that, when called, will call the underlying RPC 

620 on the server. 

621 """ 

622 # Generate a "stub function" on-the-fly which will actually make 

623 # the request. 

624 # gRPC handles serialization and deserialization, so we just need 

625 # to pass in the functions for each. 

626 if "get_iam_policy" not in self._stubs: 

627 self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( 

628 "/google.iam.v1.IAMPolicy/GetIamPolicy", 

629 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

630 response_deserializer=policy_pb2.Policy.FromString, 

631 ) 

632 return self._stubs["get_iam_policy"] 

633 

634 @property 

635 def test_iam_permissions( 

636 self, 

637 ) -> Callable[ 

638 [iam_policy_pb2.TestIamPermissionsRequest], 

639 iam_policy_pb2.TestIamPermissionsResponse, 

640 ]: 

641 r"""Return a callable for the test iam permissions method over gRPC. 

642 Tests the specified permissions against the IAM access control 

643 policy for a function. If the function does not exist, this will 

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

645 Returns: 

646 Callable[[~.TestIamPermissionsRequest], 

647 ~.TestIamPermissionsResponse]: 

648 A function that, when called, will call the underlying RPC 

649 on the server. 

650 """ 

651 # Generate a "stub function" on-the-fly which will actually make 

652 # the request. 

653 # gRPC handles serialization and deserialization, so we just need 

654 # to pass in the functions for each. 

655 if "test_iam_permissions" not in self._stubs: 

656 self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( 

657 "/google.iam.v1.IAMPolicy/TestIamPermissions", 

658 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

659 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

660 ) 

661 return self._stubs["test_iam_permissions"] 

662 

663 @property 

664 def kind(self) -> str: 

665 return "grpc" 

666 

667 

668__all__ = ("PublisherGrpcTransport",)