Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/pubsub_v1/services/subscriber/transports/grpc.py: 42%

147 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 06:25 +0000

1# -*- coding: utf-8 -*- 

2# Copyright 2022 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16import warnings 

17from typing import Callable, Dict, Optional, Sequence, Tuple, Union 

18 

19from google.api_core import grpc_helpers 

20from google.api_core import gapic_v1 

21import google.auth # type: ignore 

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

23from google.auth.transport.grpc import SslCredentials # type: ignore 

24 

25import grpc # type: ignore 

26 

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

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

29from google.protobuf import empty_pb2 # type: ignore 

30from google.pubsub_v1.types import pubsub 

31from .base import SubscriberTransport, DEFAULT_CLIENT_INFO 

32 

33 

34class SubscriberGrpcTransport(SubscriberTransport): 

35 """gRPC backend transport for Subscriber. 

36 

37 The service that an application uses to manipulate subscriptions and 

38 to consume messages from a subscription via the ``Pull`` method or 

39 by establishing a bi-directional stream using the ``StreamingPull`` 

40 method. 

41 

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

43 primary client can load the underlying transport implementation 

44 and call it. 

45 

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

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

48 """ 

49 

50 _stubs: Dict[str, Callable] 

51 

52 def __init__( 

53 self, 

54 *, 

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

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

57 credentials_file: Optional[str] = None, 

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

59 channel: Optional[grpc.Channel] = None, 

60 api_mtls_endpoint: Optional[str] = None, 

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

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

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

64 quota_project_id: Optional[str] = None, 

65 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

66 always_use_jwt_access: Optional[bool] = False, 

67 api_audience: Optional[str] = None, 

68 ) -> None: 

69 """Instantiate the transport. 

70 

71 Args: 

72 host (Optional[str]): 

73 The hostname to connect to. 

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

75 authorization credentials to attach to requests. These 

76 credentials identify the application to the service; if none 

77 are specified, the client will attempt to ascertain the 

78 credentials from the environment. 

79 This argument is ignored if ``channel`` is provided. 

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

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

82 This argument is ignored if ``channel`` is provided. 

83 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

84 ignored if ``channel`` is provided. 

85 channel (Optional[grpc.Channel]): A ``Channel`` instance through 

86 which to make calls. 

87 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. 

88 If provided, it overrides the ``host`` argument and tries to create 

89 a mutual TLS channel with client SSL credentials from 

90 ``client_cert_source`` or application default SSL credentials. 

91 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): 

92 Deprecated. A callback to provide client SSL certificate bytes and 

93 private key bytes, both in PEM format. It is ignored if 

94 ``api_mtls_endpoint`` is None. 

95 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

96 for the grpc channel. It is ignored if ``channel`` is provided. 

97 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): 

98 A callback to provide client certificate bytes and private key bytes, 

99 both in PEM format. It is used to configure a mutual TLS channel. It is 

100 ignored if ``channel`` or ``ssl_channel_credentials`` is provided. 

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

102 and quota. 

103 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

104 The client info used to send a user-agent string along with 

105 API requests. If ``None``, then default info will be used. 

106 Generally, you only need to set this if you're developing 

107 your own client library. 

108 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

109 be used for service account credentials. 

110 

111 Raises: 

112 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 

113 creation failed for any reason. 

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

115 and ``credentials_file`` are passed. 

116 """ 

117 self._grpc_channel = None 

118 self._ssl_channel_credentials = ssl_channel_credentials 

119 self._stubs: Dict[str, Callable] = {} 

120 

121 if api_mtls_endpoint: 

122 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 

123 if client_cert_source: 

124 warnings.warn("client_cert_source is deprecated", DeprecationWarning) 

125 

126 if channel: 

127 # Ignore credentials if a channel was passed. 

128 credentials = False 

129 # If a channel was explicitly provided, set it. 

130 self._grpc_channel = channel 

131 self._ssl_channel_credentials = None 

132 

133 else: 

134 if api_mtls_endpoint: 

135 host = api_mtls_endpoint 

136 

137 # Create SSL credentials with client_cert_source or application 

138 # default SSL credentials. 

139 if client_cert_source: 

140 cert, key = client_cert_source() 

141 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

142 certificate_chain=cert, private_key=key 

143 ) 

144 else: 

145 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

146 

147 else: 

148 if client_cert_source_for_mtls and not ssl_channel_credentials: 

149 cert, key = client_cert_source_for_mtls() 

150 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

151 certificate_chain=cert, private_key=key 

152 ) 

153 

154 # The base transport sets the host, credentials and scopes 

155 super().__init__( 

156 host=host, 

157 credentials=credentials, 

158 credentials_file=credentials_file, 

159 scopes=scopes, 

160 quota_project_id=quota_project_id, 

161 client_info=client_info, 

162 always_use_jwt_access=always_use_jwt_access, 

163 api_audience=api_audience, 

164 ) 

165 

166 if not self._grpc_channel: 

167 self._grpc_channel = type(self).create_channel( 

168 self._host, 

169 # use the credentials which are saved 

170 credentials=self._credentials, 

171 # Set ``credentials_file`` to ``None`` here as 

172 # the credentials that we saved earlier should be used. 

173 credentials_file=None, 

174 scopes=self._scopes, 

175 ssl_credentials=self._ssl_channel_credentials, 

176 quota_project_id=quota_project_id, 

177 options=[ 

178 ("grpc.max_send_message_length", -1), 

179 ("grpc.max_receive_message_length", -1), 

180 ("grpc.max_metadata_size", 4 * 1024 * 1024), 

181 ("grpc.keepalive_time_ms", 30000), 

182 ], 

183 ) 

184 

185 # Wrap messages. This must be done after self._grpc_channel exists 

186 self._prep_wrapped_messages(client_info) 

187 

188 @classmethod 

189 def create_channel( 

190 cls, 

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

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

193 credentials_file: Optional[str] = None, 

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

195 quota_project_id: Optional[str] = None, 

196 **kwargs, 

197 ) -> grpc.Channel: 

198 """Create and return a gRPC channel object. 

199 Args: 

200 host (Optional[str]): The host for the channel to use. 

201 credentials (Optional[~.Credentials]): The 

202 authorization credentials to attach to requests. These 

203 credentials identify this application to the service. If 

204 none are specified, the client will attempt to ascertain 

205 the credentials from the environment. 

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

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

208 This argument is mutually exclusive with credentials. 

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

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

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

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

213 and quota. 

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

215 channel creation. 

216 Returns: 

217 grpc.Channel: A gRPC channel object. 

218 

219 Raises: 

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

221 and ``credentials_file`` are passed. 

222 """ 

223 

224 return grpc_helpers.create_channel( 

225 host, 

226 credentials=credentials, 

227 credentials_file=credentials_file, 

228 quota_project_id=quota_project_id, 

229 default_scopes=cls.AUTH_SCOPES, 

230 scopes=scopes, 

231 default_host=cls.DEFAULT_HOST, 

232 **kwargs, 

233 ) 

234 

235 @property 

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

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

238 return self._grpc_channel 

239 

240 @property 

241 def create_subscription( 

242 self, 

243 ) -> Callable[[pubsub.Subscription], pubsub.Subscription]: 

244 r"""Return a callable for the create subscription method over gRPC. 

245 

246 Creates a subscription to a given topic. See the [resource name 

247 rules] 

248 (https://cloud.google.com/pubsub/docs/admin#resource_names). If 

249 the subscription already exists, returns ``ALREADY_EXISTS``. If 

250 the corresponding topic doesn't exist, returns ``NOT_FOUND``. 

251 

252 If the name is not provided in the request, the server will 

253 assign a random name for this subscription on the same project 

254 as the topic, conforming to the [resource name format] 

255 (https://cloud.google.com/pubsub/docs/admin#resource_names). The 

256 generated name is populated in the returned Subscription object. 

257 Note that for REST API requests, you must specify a name in the 

258 request. 

259 

260 Returns: 

261 Callable[[~.Subscription], 

262 ~.Subscription]: 

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

264 on the server. 

265 """ 

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

267 # the request. 

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

269 # to pass in the functions for each. 

270 if "create_subscription" not in self._stubs: 

271 self._stubs["create_subscription"] = self.grpc_channel.unary_unary( 

272 "/google.pubsub.v1.Subscriber/CreateSubscription", 

273 request_serializer=pubsub.Subscription.serialize, 

274 response_deserializer=pubsub.Subscription.deserialize, 

275 ) 

276 return self._stubs["create_subscription"] 

277 

278 @property 

279 def get_subscription( 

280 self, 

281 ) -> Callable[[pubsub.GetSubscriptionRequest], pubsub.Subscription]: 

282 r"""Return a callable for the get subscription method over gRPC. 

283 

284 Gets the configuration details of a subscription. 

285 

286 Returns: 

287 Callable[[~.GetSubscriptionRequest], 

288 ~.Subscription]: 

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

290 on the server. 

291 """ 

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

293 # the request. 

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

295 # to pass in the functions for each. 

296 if "get_subscription" not in self._stubs: 

297 self._stubs["get_subscription"] = self.grpc_channel.unary_unary( 

298 "/google.pubsub.v1.Subscriber/GetSubscription", 

299 request_serializer=pubsub.GetSubscriptionRequest.serialize, 

300 response_deserializer=pubsub.Subscription.deserialize, 

301 ) 

302 return self._stubs["get_subscription"] 

303 

304 @property 

305 def update_subscription( 

306 self, 

307 ) -> Callable[[pubsub.UpdateSubscriptionRequest], pubsub.Subscription]: 

308 r"""Return a callable for the update subscription method over gRPC. 

309 

310 Updates an existing subscription. Note that certain 

311 properties of a subscription, such as its topic, are not 

312 modifiable. 

313 

314 Returns: 

315 Callable[[~.UpdateSubscriptionRequest], 

316 ~.Subscription]: 

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

318 on the server. 

319 """ 

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

321 # the request. 

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

323 # to pass in the functions for each. 

324 if "update_subscription" not in self._stubs: 

325 self._stubs["update_subscription"] = self.grpc_channel.unary_unary( 

326 "/google.pubsub.v1.Subscriber/UpdateSubscription", 

327 request_serializer=pubsub.UpdateSubscriptionRequest.serialize, 

328 response_deserializer=pubsub.Subscription.deserialize, 

329 ) 

330 return self._stubs["update_subscription"] 

331 

332 @property 

333 def list_subscriptions( 

334 self, 

335 ) -> Callable[[pubsub.ListSubscriptionsRequest], pubsub.ListSubscriptionsResponse]: 

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

337 

338 Lists matching subscriptions. 

339 

340 Returns: 

341 Callable[[~.ListSubscriptionsRequest], 

342 ~.ListSubscriptionsResponse]: 

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

344 on the server. 

345 """ 

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

347 # the request. 

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

349 # to pass in the functions for each. 

350 if "list_subscriptions" not in self._stubs: 

351 self._stubs["list_subscriptions"] = self.grpc_channel.unary_unary( 

352 "/google.pubsub.v1.Subscriber/ListSubscriptions", 

353 request_serializer=pubsub.ListSubscriptionsRequest.serialize, 

354 response_deserializer=pubsub.ListSubscriptionsResponse.deserialize, 

355 ) 

356 return self._stubs["list_subscriptions"] 

357 

358 @property 

359 def delete_subscription( 

360 self, 

361 ) -> Callable[[pubsub.DeleteSubscriptionRequest], empty_pb2.Empty]: 

362 r"""Return a callable for the delete subscription method over gRPC. 

363 

364 Deletes an existing subscription. All messages retained in the 

365 subscription are immediately dropped. Calls to ``Pull`` after 

366 deletion will return ``NOT_FOUND``. After a subscription is 

367 deleted, a new one may be created with the same name, but the 

368 new one has no association with the old subscription or its 

369 topic unless the same topic is specified. 

370 

371 Returns: 

372 Callable[[~.DeleteSubscriptionRequest], 

373 ~.Empty]: 

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 "delete_subscription" not in self._stubs: 

382 self._stubs["delete_subscription"] = self.grpc_channel.unary_unary( 

383 "/google.pubsub.v1.Subscriber/DeleteSubscription", 

384 request_serializer=pubsub.DeleteSubscriptionRequest.serialize, 

385 response_deserializer=empty_pb2.Empty.FromString, 

386 ) 

387 return self._stubs["delete_subscription"] 

388 

389 @property 

390 def modify_ack_deadline( 

391 self, 

392 ) -> Callable[[pubsub.ModifyAckDeadlineRequest], empty_pb2.Empty]: 

393 r"""Return a callable for the modify ack deadline method over gRPC. 

394 

395 Modifies the ack deadline for a specific message. This method is 

396 useful to indicate that more time is needed to process a message 

397 by the subscriber, or to make the message available for 

398 redelivery if the processing was interrupted. Note that this 

399 does not modify the subscription-level ``ackDeadlineSeconds`` 

400 used for subsequent messages. 

401 

402 Returns: 

403 Callable[[~.ModifyAckDeadlineRequest], 

404 ~.Empty]: 

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

406 on the server. 

407 """ 

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

409 # the request. 

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

411 # to pass in the functions for each. 

412 if "modify_ack_deadline" not in self._stubs: 

413 self._stubs["modify_ack_deadline"] = self.grpc_channel.unary_unary( 

414 "/google.pubsub.v1.Subscriber/ModifyAckDeadline", 

415 request_serializer=pubsub.ModifyAckDeadlineRequest.serialize, 

416 response_deserializer=empty_pb2.Empty.FromString, 

417 ) 

418 return self._stubs["modify_ack_deadline"] 

419 

420 @property 

421 def acknowledge(self) -> Callable[[pubsub.AcknowledgeRequest], empty_pb2.Empty]: 

422 r"""Return a callable for the acknowledge method over gRPC. 

423 

424 Acknowledges the messages associated with the ``ack_ids`` in the 

425 ``AcknowledgeRequest``. The Pub/Sub system can remove the 

426 relevant messages from the subscription. 

427 

428 Acknowledging a message whose ack deadline has expired may 

429 succeed, but such a message may be redelivered later. 

430 Acknowledging a message more than once will not result in an 

431 error. 

432 

433 Returns: 

434 Callable[[~.AcknowledgeRequest], 

435 ~.Empty]: 

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

437 on the server. 

438 """ 

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

440 # the request. 

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

442 # to pass in the functions for each. 

443 if "acknowledge" not in self._stubs: 

444 self._stubs["acknowledge"] = self.grpc_channel.unary_unary( 

445 "/google.pubsub.v1.Subscriber/Acknowledge", 

446 request_serializer=pubsub.AcknowledgeRequest.serialize, 

447 response_deserializer=empty_pb2.Empty.FromString, 

448 ) 

449 return self._stubs["acknowledge"] 

450 

451 @property 

452 def pull(self) -> Callable[[pubsub.PullRequest], pubsub.PullResponse]: 

453 r"""Return a callable for the pull method over gRPC. 

454 

455 Pulls messages from the server. 

456 

457 Returns: 

458 Callable[[~.PullRequest], 

459 ~.PullResponse]: 

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

461 on the server. 

462 """ 

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

464 # the request. 

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

466 # to pass in the functions for each. 

467 if "pull" not in self._stubs: 

468 self._stubs["pull"] = self.grpc_channel.unary_unary( 

469 "/google.pubsub.v1.Subscriber/Pull", 

470 request_serializer=pubsub.PullRequest.serialize, 

471 response_deserializer=pubsub.PullResponse.deserialize, 

472 ) 

473 return self._stubs["pull"] 

474 

475 @property 

476 def streaming_pull( 

477 self, 

478 ) -> Callable[[pubsub.StreamingPullRequest], pubsub.StreamingPullResponse]: 

479 r"""Return a callable for the streaming pull method over gRPC. 

480 

481 Establishes a stream with the server, which sends messages down 

482 to the client. The client streams acknowledgements and ack 

483 deadline modifications back to the server. The server will close 

484 the stream and return the status on any error. The server may 

485 close the stream with status ``UNAVAILABLE`` to reassign 

486 server-side resources, in which case, the client should 

487 re-establish the stream. Flow control can be achieved by 

488 configuring the underlying RPC channel. 

489 

490 Returns: 

491 Callable[[~.StreamingPullRequest], 

492 ~.StreamingPullResponse]: 

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

494 on the server. 

495 """ 

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

497 # the request. 

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

499 # to pass in the functions for each. 

500 if "streaming_pull" not in self._stubs: 

501 self._stubs["streaming_pull"] = self.grpc_channel.stream_stream( 

502 "/google.pubsub.v1.Subscriber/StreamingPull", 

503 request_serializer=pubsub.StreamingPullRequest.serialize, 

504 response_deserializer=pubsub.StreamingPullResponse.deserialize, 

505 ) 

506 return self._stubs["streaming_pull"] 

507 

508 @property 

509 def modify_push_config( 

510 self, 

511 ) -> Callable[[pubsub.ModifyPushConfigRequest], empty_pb2.Empty]: 

512 r"""Return a callable for the modify push config method over gRPC. 

513 

514 Modifies the ``PushConfig`` for a specified subscription. 

515 

516 This may be used to change a push subscription to a pull one 

517 (signified by an empty ``PushConfig``) or vice versa, or change 

518 the endpoint URL and other attributes of a push subscription. 

519 Messages will accumulate for delivery continuously through the 

520 call regardless of changes to the ``PushConfig``. 

521 

522 Returns: 

523 Callable[[~.ModifyPushConfigRequest], 

524 ~.Empty]: 

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

526 on the server. 

527 """ 

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

529 # the request. 

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

531 # to pass in the functions for each. 

532 if "modify_push_config" not in self._stubs: 

533 self._stubs["modify_push_config"] = self.grpc_channel.unary_unary( 

534 "/google.pubsub.v1.Subscriber/ModifyPushConfig", 

535 request_serializer=pubsub.ModifyPushConfigRequest.serialize, 

536 response_deserializer=empty_pb2.Empty.FromString, 

537 ) 

538 return self._stubs["modify_push_config"] 

539 

540 @property 

541 def get_snapshot(self) -> Callable[[pubsub.GetSnapshotRequest], pubsub.Snapshot]: 

542 r"""Return a callable for the get snapshot method over gRPC. 

543 

544 Gets the configuration details of a snapshot. Snapshots are used 

545 in 

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

547 operations, which allow you to manage message acknowledgments in 

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

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

550 

551 Returns: 

552 Callable[[~.GetSnapshotRequest], 

553 ~.Snapshot]: 

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

555 on the server. 

556 """ 

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

558 # the request. 

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

560 # to pass in the functions for each. 

561 if "get_snapshot" not in self._stubs: 

562 self._stubs["get_snapshot"] = self.grpc_channel.unary_unary( 

563 "/google.pubsub.v1.Subscriber/GetSnapshot", 

564 request_serializer=pubsub.GetSnapshotRequest.serialize, 

565 response_deserializer=pubsub.Snapshot.deserialize, 

566 ) 

567 return self._stubs["get_snapshot"] 

568 

569 @property 

570 def list_snapshots( 

571 self, 

572 ) -> Callable[[pubsub.ListSnapshotsRequest], pubsub.ListSnapshotsResponse]: 

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

574 

575 Lists the existing snapshots. Snapshots are used in 

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

577 operations, which allow you to manage message acknowledgments in 

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

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

580 

581 Returns: 

582 Callable[[~.ListSnapshotsRequest], 

583 ~.ListSnapshotsResponse]: 

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

585 on the server. 

586 """ 

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

588 # the request. 

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

590 # to pass in the functions for each. 

591 if "list_snapshots" not in self._stubs: 

592 self._stubs["list_snapshots"] = self.grpc_channel.unary_unary( 

593 "/google.pubsub.v1.Subscriber/ListSnapshots", 

594 request_serializer=pubsub.ListSnapshotsRequest.serialize, 

595 response_deserializer=pubsub.ListSnapshotsResponse.deserialize, 

596 ) 

597 return self._stubs["list_snapshots"] 

598 

599 @property 

600 def create_snapshot( 

601 self, 

602 ) -> Callable[[pubsub.CreateSnapshotRequest], pubsub.Snapshot]: 

603 r"""Return a callable for the create snapshot method over gRPC. 

604 

605 Creates a snapshot from the requested subscription. Snapshots 

606 are used in 

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

608 operations, which allow you to manage message acknowledgments in 

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

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

611 If the snapshot already exists, returns ``ALREADY_EXISTS``. If 

612 the requested subscription doesn't exist, returns ``NOT_FOUND``. 

613 If the backlog in the subscription is too old -- and the 

614 resulting snapshot would expire in less than 1 hour -- then 

615 ``FAILED_PRECONDITION`` is returned. See also the 

616 ``Snapshot.expire_time`` field. If the name is not provided in 

617 the request, the server will assign a random name for this 

618 snapshot on the same project as the subscription, conforming to 

619 the [resource name format] 

620 (https://cloud.google.com/pubsub/docs/admin#resource_names). The 

621 generated name is populated in the returned Snapshot object. 

622 Note that for REST API requests, you must specify a name in the 

623 request. 

624 

625 Returns: 

626 Callable[[~.CreateSnapshotRequest], 

627 ~.Snapshot]: 

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

629 on the server. 

630 """ 

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

632 # the request. 

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

634 # to pass in the functions for each. 

635 if "create_snapshot" not in self._stubs: 

636 self._stubs["create_snapshot"] = self.grpc_channel.unary_unary( 

637 "/google.pubsub.v1.Subscriber/CreateSnapshot", 

638 request_serializer=pubsub.CreateSnapshotRequest.serialize, 

639 response_deserializer=pubsub.Snapshot.deserialize, 

640 ) 

641 return self._stubs["create_snapshot"] 

642 

643 @property 

644 def update_snapshot( 

645 self, 

646 ) -> Callable[[pubsub.UpdateSnapshotRequest], pubsub.Snapshot]: 

647 r"""Return a callable for the update snapshot method over gRPC. 

648 

649 Updates an existing snapshot. Snapshots are used in 

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

651 operations, which allow you to manage message acknowledgments in 

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

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

654 

655 Returns: 

656 Callable[[~.UpdateSnapshotRequest], 

657 ~.Snapshot]: 

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

659 on the server. 

660 """ 

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

662 # the request. 

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

664 # to pass in the functions for each. 

665 if "update_snapshot" not in self._stubs: 

666 self._stubs["update_snapshot"] = self.grpc_channel.unary_unary( 

667 "/google.pubsub.v1.Subscriber/UpdateSnapshot", 

668 request_serializer=pubsub.UpdateSnapshotRequest.serialize, 

669 response_deserializer=pubsub.Snapshot.deserialize, 

670 ) 

671 return self._stubs["update_snapshot"] 

672 

673 @property 

674 def delete_snapshot( 

675 self, 

676 ) -> Callable[[pubsub.DeleteSnapshotRequest], empty_pb2.Empty]: 

677 r"""Return a callable for the delete snapshot method over gRPC. 

678 

679 Removes an existing snapshot. Snapshots are used in [Seek] 

680 (https://cloud.google.com/pubsub/docs/replay-overview) 

681 operations, which allow you to manage message acknowledgments in 

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

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

684 When the snapshot is deleted, all messages retained in the 

685 snapshot are immediately dropped. After a snapshot is deleted, a 

686 new one may be created with the same name, but the new one has 

687 no association with the old snapshot or its subscription, unless 

688 the same subscription is specified. 

689 

690 Returns: 

691 Callable[[~.DeleteSnapshotRequest], 

692 ~.Empty]: 

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

694 on the server. 

695 """ 

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

697 # the request. 

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

699 # to pass in the functions for each. 

700 if "delete_snapshot" not in self._stubs: 

701 self._stubs["delete_snapshot"] = self.grpc_channel.unary_unary( 

702 "/google.pubsub.v1.Subscriber/DeleteSnapshot", 

703 request_serializer=pubsub.DeleteSnapshotRequest.serialize, 

704 response_deserializer=empty_pb2.Empty.FromString, 

705 ) 

706 return self._stubs["delete_snapshot"] 

707 

708 @property 

709 def seek(self) -> Callable[[pubsub.SeekRequest], pubsub.SeekResponse]: 

710 r"""Return a callable for the seek method over gRPC. 

711 

712 Seeks an existing subscription to a point in time or to a given 

713 snapshot, whichever is provided in the request. Snapshots are 

714 used in [Seek] 

715 (https://cloud.google.com/pubsub/docs/replay-overview) 

716 operations, which allow you to manage message acknowledgments in 

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

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

719 Note that both the subscription and the snapshot must be on the 

720 same topic. 

721 

722 Returns: 

723 Callable[[~.SeekRequest], 

724 ~.SeekResponse]: 

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

726 on the server. 

727 """ 

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

729 # the request. 

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

731 # to pass in the functions for each. 

732 if "seek" not in self._stubs: 

733 self._stubs["seek"] = self.grpc_channel.unary_unary( 

734 "/google.pubsub.v1.Subscriber/Seek", 

735 request_serializer=pubsub.SeekRequest.serialize, 

736 response_deserializer=pubsub.SeekResponse.deserialize, 

737 ) 

738 return self._stubs["seek"] 

739 

740 @property 

741 def set_iam_policy( 

742 self, 

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

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

745 Sets the IAM access control policy on the specified 

746 function. Replaces any existing policy. 

747 Returns: 

748 Callable[[~.SetIamPolicyRequest], 

749 ~.Policy]: 

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

751 on the server. 

752 """ 

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

754 # the request. 

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

756 # to pass in the functions for each. 

757 if "set_iam_policy" not in self._stubs: 

758 self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( 

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

760 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

761 response_deserializer=policy_pb2.Policy.FromString, 

762 ) 

763 return self._stubs["set_iam_policy"] 

764 

765 @property 

766 def get_iam_policy( 

767 self, 

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

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

770 Gets the IAM access control policy for a function. 

771 Returns an empty policy if the function exists and does 

772 not have a policy set. 

773 Returns: 

774 Callable[[~.GetIamPolicyRequest], 

775 ~.Policy]: 

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

777 on the server. 

778 """ 

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

780 # the request. 

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

782 # to pass in the functions for each. 

783 if "get_iam_policy" not in self._stubs: 

784 self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( 

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

786 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

787 response_deserializer=policy_pb2.Policy.FromString, 

788 ) 

789 return self._stubs["get_iam_policy"] 

790 

791 @property 

792 def test_iam_permissions( 

793 self, 

794 ) -> Callable[ 

795 [iam_policy_pb2.TestIamPermissionsRequest], 

796 iam_policy_pb2.TestIamPermissionsResponse, 

797 ]: 

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

799 Tests the specified permissions against the IAM access control 

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

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

802 Returns: 

803 Callable[[~.TestIamPermissionsRequest], 

804 ~.TestIamPermissionsResponse]: 

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

806 on the server. 

807 """ 

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

809 # the request. 

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

811 # to pass in the functions for each. 

812 if "test_iam_permissions" not in self._stubs: 

813 self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( 

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

815 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

816 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

817 ) 

818 return self._stubs["test_iam_permissions"] 

819 

820 def close(self): 

821 self.grpc_channel.close() 

822 

823 @property 

824 def kind(self) -> str: 

825 return "grpc" 

826 

827 

828__all__ = ("SubscriberGrpcTransport",)