Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/pubsub_v1/services/subscriber/async_client.py: 27%

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

337 statements  

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 logging as std_logging 

17from collections import OrderedDict 

18import re 

19from typing import ( 

20 Dict, 

21 Callable, 

22 Mapping, 

23 MutableMapping, 

24 MutableSequence, 

25 Optional, 

26 AsyncIterable, 

27 Awaitable, 

28 AsyncIterator, 

29 Sequence, 

30 Tuple, 

31 Type, 

32 Union, 

33) 

34 

35import warnings 

36from google.pubsub_v1 import gapic_version as package_version 

37 

38from google.api_core.client_options import ClientOptions 

39from google.api_core import exceptions as core_exceptions 

40from google.api_core import gapic_v1 

41from google.api_core import retry_async as retries 

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

43from google.oauth2 import service_account # type: ignore 

44import google.protobuf 

45 

46 

47try: 

48 OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] 

49except AttributeError: # pragma: NO COVER 

50 OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore 

51 

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

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

54from google.protobuf import duration_pb2 # type: ignore 

55from google.protobuf import field_mask_pb2 # type: ignore 

56from google.protobuf import timestamp_pb2 # type: ignore 

57from google.pubsub_v1.services.subscriber import pagers 

58from google.pubsub_v1.types import pubsub 

59from .transports.base import SubscriberTransport, DEFAULT_CLIENT_INFO 

60from .transports.grpc_asyncio import SubscriberGrpcAsyncIOTransport 

61from .client import SubscriberClient 

62 

63try: 

64 from google.api_core import client_logging # type: ignore 

65 

66 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

67except ImportError: # pragma: NO COVER 

68 CLIENT_LOGGING_SUPPORTED = False 

69 

70_LOGGER = std_logging.getLogger(__name__) 

71 

72 

73class SubscriberAsyncClient: 

74 """The service that an application uses to manipulate subscriptions and 

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

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

77 method. 

78 """ 

79 

80 _client: SubscriberClient 

81 

82 # Copy defaults from the synchronous client for use here. 

83 # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. 

84 DEFAULT_ENDPOINT = SubscriberClient.DEFAULT_ENDPOINT 

85 DEFAULT_MTLS_ENDPOINT = SubscriberClient.DEFAULT_MTLS_ENDPOINT 

86 _DEFAULT_ENDPOINT_TEMPLATE = SubscriberClient._DEFAULT_ENDPOINT_TEMPLATE 

87 _DEFAULT_UNIVERSE = SubscriberClient._DEFAULT_UNIVERSE 

88 

89 listing_path = staticmethod(SubscriberClient.listing_path) 

90 parse_listing_path = staticmethod(SubscriberClient.parse_listing_path) 

91 snapshot_path = staticmethod(SubscriberClient.snapshot_path) 

92 parse_snapshot_path = staticmethod(SubscriberClient.parse_snapshot_path) 

93 subscription_path = staticmethod(SubscriberClient.subscription_path) 

94 parse_subscription_path = staticmethod(SubscriberClient.parse_subscription_path) 

95 topic_path = staticmethod(SubscriberClient.topic_path) 

96 parse_topic_path = staticmethod(SubscriberClient.parse_topic_path) 

97 common_billing_account_path = staticmethod( 

98 SubscriberClient.common_billing_account_path 

99 ) 

100 parse_common_billing_account_path = staticmethod( 

101 SubscriberClient.parse_common_billing_account_path 

102 ) 

103 common_folder_path = staticmethod(SubscriberClient.common_folder_path) 

104 parse_common_folder_path = staticmethod(SubscriberClient.parse_common_folder_path) 

105 common_organization_path = staticmethod(SubscriberClient.common_organization_path) 

106 parse_common_organization_path = staticmethod( 

107 SubscriberClient.parse_common_organization_path 

108 ) 

109 common_project_path = staticmethod(SubscriberClient.common_project_path) 

110 parse_common_project_path = staticmethod(SubscriberClient.parse_common_project_path) 

111 common_location_path = staticmethod(SubscriberClient.common_location_path) 

112 parse_common_location_path = staticmethod( 

113 SubscriberClient.parse_common_location_path 

114 ) 

115 

116 @classmethod 

117 def from_service_account_info(cls, info: dict, *args, **kwargs): 

118 """Creates an instance of this client using the provided credentials 

119 info. 

120 

121 Args: 

122 info (dict): The service account private key info. 

123 args: Additional arguments to pass to the constructor. 

124 kwargs: Additional arguments to pass to the constructor. 

125 

126 Returns: 

127 SubscriberAsyncClient: The constructed client. 

128 """ 

129 return SubscriberClient.from_service_account_info.__func__(SubscriberAsyncClient, info, *args, **kwargs) # type: ignore 

130 

131 @classmethod 

132 def from_service_account_file(cls, filename: str, *args, **kwargs): 

133 """Creates an instance of this client using the provided credentials 

134 file. 

135 

136 Args: 

137 filename (str): The path to the service account private key json 

138 file. 

139 args: Additional arguments to pass to the constructor. 

140 kwargs: Additional arguments to pass to the constructor. 

141 

142 Returns: 

143 SubscriberAsyncClient: The constructed client. 

144 """ 

145 return SubscriberClient.from_service_account_file.__func__(SubscriberAsyncClient, filename, *args, **kwargs) # type: ignore 

146 

147 from_service_account_json = from_service_account_file 

148 

149 @classmethod 

150 def get_mtls_endpoint_and_cert_source( 

151 cls, client_options: Optional[ClientOptions] = None 

152 ): 

153 """Return the API endpoint and client cert source for mutual TLS. 

154 

155 The client cert source is determined in the following order: 

156 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the 

157 client cert source is None. 

158 (2) if `client_options.client_cert_source` is provided, use the provided one; if the 

159 default client cert source exists, use the default one; otherwise the client cert 

160 source is None. 

161 

162 The API endpoint is determined in the following order: 

163 (1) if `client_options.api_endpoint` if provided, use the provided one. 

164 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the 

165 default mTLS endpoint; if the environment variable is "never", use the default API 

166 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise 

167 use the default API endpoint. 

168 

169 More details can be found at https://google.aip.dev/auth/4114. 

170 

171 Args: 

172 client_options (google.api_core.client_options.ClientOptions): Custom options for the 

173 client. Only the `api_endpoint` and `client_cert_source` properties may be used 

174 in this method. 

175 

176 Returns: 

177 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the 

178 client cert source to use. 

179 

180 Raises: 

181 google.auth.exceptions.MutualTLSChannelError: If any errors happen. 

182 """ 

183 return SubscriberClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

184 

185 @property 

186 def transport(self) -> SubscriberTransport: 

187 """Returns the transport used by the client instance. 

188 

189 Returns: 

190 SubscriberTransport: The transport used by the client instance. 

191 """ 

192 return self._client.transport 

193 

194 @property 

195 def api_endpoint(self): 

196 """Return the API endpoint used by the client instance. 

197 

198 Returns: 

199 str: The API endpoint used by the client instance. 

200 """ 

201 return self._client._api_endpoint 

202 

203 @property 

204 def universe_domain(self) -> str: 

205 """Return the universe domain used by the client instance. 

206 

207 Returns: 

208 str: The universe domain used 

209 by the client instance. 

210 """ 

211 return self._client._universe_domain 

212 

213 get_transport_class = SubscriberClient.get_transport_class 

214 

215 def __init__( 

216 self, 

217 *, 

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

219 transport: Optional[ 

220 Union[str, SubscriberTransport, Callable[..., SubscriberTransport]] 

221 ] = "grpc_asyncio", 

222 client_options: Optional[ClientOptions] = None, 

223 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

224 ) -> None: 

225 """Instantiates the subscriber async client. 

226 

227 Args: 

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

229 authorization credentials to attach to requests. These 

230 credentials identify the application to the service; if none 

231 are specified, the client will attempt to ascertain the 

232 credentials from the environment. 

233 transport (Optional[Union[str,SubscriberTransport,Callable[..., SubscriberTransport]]]): 

234 The transport to use, or a Callable that constructs and returns a new transport to use. 

235 If a Callable is given, it will be called with the same set of initialization 

236 arguments as used in the SubscriberTransport constructor. 

237 If set to None, a transport is chosen automatically. 

238 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): 

239 Custom options for the client. 

240 

241 1. The ``api_endpoint`` property can be used to override the 

242 default endpoint provided by the client when ``transport`` is 

243 not explicitly provided. Only if this property is not set and 

244 ``transport`` was not explicitly provided, the endpoint is 

245 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment 

246 variable, which have one of the following values: 

247 "always" (always use the default mTLS endpoint), "never" (always 

248 use the default regular endpoint) and "auto" (auto-switch to the 

249 default mTLS endpoint if client certificate is present; this is 

250 the default value). 

251 

252 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

253 is "true", then the ``client_cert_source`` property can be used 

254 to provide a client certificate for mTLS transport. If 

255 not provided, the default SSL client certificate will be used if 

256 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

257 set, no client certificate will be used. 

258 

259 3. The ``universe_domain`` property can be used to override the 

260 default "googleapis.com" universe. Note that ``api_endpoint`` 

261 property still takes precedence; and ``universe_domain`` is 

262 currently not supported for mTLS. 

263 

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

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

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

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

268 your own client library. 

269 

270 Raises: 

271 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 

272 creation failed for any reason. 

273 """ 

274 self._client = SubscriberClient( 

275 credentials=credentials, 

276 transport=transport, 

277 client_options=client_options, 

278 client_info=client_info, 

279 ) 

280 

281 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

282 std_logging.DEBUG 

283 ): # pragma: NO COVER 

284 _LOGGER.debug( 

285 "Created client `google.pubsub_v1.SubscriberAsyncClient`.", 

286 extra={ 

287 "serviceName": "google.pubsub.v1.Subscriber", 

288 "universeDomain": getattr( 

289 self._client._transport._credentials, "universe_domain", "" 

290 ), 

291 "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", 

292 "credentialsInfo": getattr( 

293 self.transport._credentials, "get_cred_info", lambda: None 

294 )(), 

295 } 

296 if hasattr(self._client._transport, "_credentials") 

297 else { 

298 "serviceName": "google.pubsub.v1.Subscriber", 

299 "credentialsType": None, 

300 }, 

301 ) 

302 

303 async def create_subscription( 

304 self, 

305 request: Optional[Union[pubsub.Subscription, dict]] = None, 

306 *, 

307 name: Optional[str] = None, 

308 topic: Optional[str] = None, 

309 push_config: Optional[pubsub.PushConfig] = None, 

310 ack_deadline_seconds: Optional[int] = None, 

311 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

312 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

313 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

314 ) -> pubsub.Subscription: 

315 r"""Creates a subscription to a given topic. See the [resource name 

316 rules] 

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

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

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

320 

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

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

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

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

325 The generated name is populated in the returned Subscription 

326 object. Note that for REST API requests, you must specify a name 

327 in the request. 

328 

329 .. code-block:: python 

330 

331 # This snippet has been automatically generated and should be regarded as a 

332 # code template only. 

333 # It will require modifications to work: 

334 # - It may require correct/in-range values for request initialization. 

335 # - It may require specifying regional endpoints when creating the service 

336 # client as shown in: 

337 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

338 from google import pubsub_v1 

339 

340 async def sample_create_subscription(): 

341 # Create a client 

342 client = pubsub_v1.SubscriberAsyncClient() 

343 

344 # Initialize request argument(s) 

345 request = pubsub_v1.Subscription( 

346 name="name_value", 

347 topic="topic_value", 

348 ) 

349 

350 # Make the request 

351 response = await client.create_subscription(request=request) 

352 

353 # Handle the response 

354 print(response) 

355 

356 Args: 

357 request (Optional[Union[google.pubsub_v1.types.Subscription, dict]]): 

358 The request object. A subscription resource. If none of ``push_config``, 

359 ``bigquery_config``, or ``cloud_storage_config`` is set, 

360 then the subscriber will pull and ack messages using API 

361 methods. At most one of these fields may be set. 

362 name (:class:`str`): 

363 Required. The name of the subscription. It must have the 

364 format 

365 ``"projects/{project}/subscriptions/{subscription}"``. 

366 ``{subscription}`` must start with a letter, and contain 

367 only letters (``[A-Za-z]``), numbers (``[0-9]``), dashes 

368 (``-``), underscores (``_``), periods (``.``), tildes 

369 (``~``), plus (``+``) or percent signs (``%``). It must 

370 be between 3 and 255 characters in length, and it must 

371 not start with ``"goog"``. 

372 

373 This corresponds to the ``name`` field 

374 on the ``request`` instance; if ``request`` is provided, this 

375 should not be set. 

376 topic (:class:`str`): 

377 Required. The name of the topic from which this 

378 subscription is receiving messages. Format is 

379 ``projects/{project}/topics/{topic}``. The value of this 

380 field will be ``_deleted-topic_`` if the topic has been 

381 deleted. 

382 

383 This corresponds to the ``topic`` field 

384 on the ``request`` instance; if ``request`` is provided, this 

385 should not be set. 

386 push_config (:class:`google.pubsub_v1.types.PushConfig`): 

387 Optional. If push delivery is used 

388 with this subscription, this field is 

389 used to configure it. 

390 

391 This corresponds to the ``push_config`` field 

392 on the ``request`` instance; if ``request`` is provided, this 

393 should not be set. 

394 ack_deadline_seconds (:class:`int`): 

395 Optional. The approximate amount of time (on a 

396 best-effort basis) Pub/Sub waits for the subscriber to 

397 acknowledge receipt before resending the message. In the 

398 interval after the message is delivered and before it is 

399 acknowledged, it is considered to be *outstanding*. 

400 During that time period, the message will not be 

401 redelivered (on a best-effort basis). 

402 

403 For pull subscriptions, this value is used as the 

404 initial value for the ack deadline. To override this 

405 value for a given message, call ``ModifyAckDeadline`` 

406 with the corresponding ``ack_id`` if using non-streaming 

407 pull or send the ``ack_id`` in a 

408 ``StreamingModifyAckDeadlineRequest`` if using streaming 

409 pull. The minimum custom deadline you can specify is 10 

410 seconds. The maximum custom deadline you can specify is 

411 600 seconds (10 minutes). If this parameter is 0, a 

412 default value of 10 seconds is used. 

413 

414 For push delivery, this value is also used to set the 

415 request timeout for the call to the push endpoint. 

416 

417 If the subscriber never acknowledges the message, the 

418 Pub/Sub system will eventually redeliver the message. 

419 

420 This corresponds to the ``ack_deadline_seconds`` field 

421 on the ``request`` instance; if ``request`` is provided, this 

422 should not be set. 

423 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

424 should be retried. 

425 timeout (float): The timeout for this request. 

426 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

427 sent along with the request as metadata. Normally, each value must be of type `str`, 

428 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

429 be of type `bytes`. 

430 

431 Returns: 

432 google.pubsub_v1.types.Subscription: 

433 A subscription resource. If none of push_config, bigquery_config, or 

434 cloud_storage_config is set, then the subscriber will 

435 pull and ack messages using API methods. At most one 

436 of these fields may be set. 

437 

438 """ 

439 # Create or coerce a protobuf request object. 

440 # - Quick check: If we got a request object, we should *not* have 

441 # gotten any keyword arguments that map to the request. 

442 flattened_params = [name, topic, push_config, ack_deadline_seconds] 

443 has_flattened_params = ( 

444 len([param for param in flattened_params if param is not None]) > 0 

445 ) 

446 if request is not None and has_flattened_params: 

447 raise ValueError( 

448 "If the `request` argument is set, then none of " 

449 "the individual field arguments should be set." 

450 ) 

451 

452 # - Use the request object if provided (there's no risk of modifying the input as 

453 # there are no flattened fields), or create one. 

454 if not isinstance(request, pubsub.Subscription): 

455 request = pubsub.Subscription(request) 

456 

457 # If we have keyword arguments corresponding to fields on the 

458 # request, apply these. 

459 if name is not None: 

460 request.name = name 

461 if topic is not None: 

462 request.topic = topic 

463 if push_config is not None: 

464 request.push_config = push_config 

465 if ack_deadline_seconds is not None: 

466 request.ack_deadline_seconds = ack_deadline_seconds 

467 

468 # Wrap the RPC method; this adds retry and timeout information, 

469 # and friendly error handling. 

470 rpc = self._client._transport._wrapped_methods[ 

471 self._client._transport.create_subscription 

472 ] 

473 

474 # Certain fields should be provided within the metadata header; 

475 # add these here. 

476 metadata = tuple(metadata) + ( 

477 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

478 ) 

479 

480 # Validate the universe domain. 

481 self._client._validate_universe_domain() 

482 

483 # Send the request. 

484 response = await rpc( 

485 request, 

486 retry=retry, 

487 timeout=timeout, 

488 metadata=metadata, 

489 ) 

490 

491 # Done; return the response. 

492 return response 

493 

494 async def get_subscription( 

495 self, 

496 request: Optional[Union[pubsub.GetSubscriptionRequest, dict]] = None, 

497 *, 

498 subscription: Optional[str] = None, 

499 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

500 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

501 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

502 ) -> pubsub.Subscription: 

503 r"""Gets the configuration details of a subscription. 

504 

505 .. code-block:: python 

506 

507 # This snippet has been automatically generated and should be regarded as a 

508 # code template only. 

509 # It will require modifications to work: 

510 # - It may require correct/in-range values for request initialization. 

511 # - It may require specifying regional endpoints when creating the service 

512 # client as shown in: 

513 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

514 from google import pubsub_v1 

515 

516 async def sample_get_subscription(): 

517 # Create a client 

518 client = pubsub_v1.SubscriberAsyncClient() 

519 

520 # Initialize request argument(s) 

521 request = pubsub_v1.GetSubscriptionRequest( 

522 subscription="subscription_value", 

523 ) 

524 

525 # Make the request 

526 response = await client.get_subscription(request=request) 

527 

528 # Handle the response 

529 print(response) 

530 

531 Args: 

532 request (Optional[Union[google.pubsub_v1.types.GetSubscriptionRequest, dict]]): 

533 The request object. Request for the GetSubscription 

534 method. 

535 subscription (:class:`str`): 

536 Required. The name of the subscription to get. Format is 

537 ``projects/{project}/subscriptions/{sub}``. 

538 

539 This corresponds to the ``subscription`` field 

540 on the ``request`` instance; if ``request`` is provided, this 

541 should not be set. 

542 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

543 should be retried. 

544 timeout (float): The timeout for this request. 

545 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

546 sent along with the request as metadata. Normally, each value must be of type `str`, 

547 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

548 be of type `bytes`. 

549 

550 Returns: 

551 google.pubsub_v1.types.Subscription: 

552 A subscription resource. If none of push_config, bigquery_config, or 

553 cloud_storage_config is set, then the subscriber will 

554 pull and ack messages using API methods. At most one 

555 of these fields may be set. 

556 

557 """ 

558 # Create or coerce a protobuf request object. 

559 # - Quick check: If we got a request object, we should *not* have 

560 # gotten any keyword arguments that map to the request. 

561 flattened_params = [subscription] 

562 has_flattened_params = ( 

563 len([param for param in flattened_params if param is not None]) > 0 

564 ) 

565 if request is not None and has_flattened_params: 

566 raise ValueError( 

567 "If the `request` argument is set, then none of " 

568 "the individual field arguments should be set." 

569 ) 

570 

571 # - Use the request object if provided (there's no risk of modifying the input as 

572 # there are no flattened fields), or create one. 

573 if not isinstance(request, pubsub.GetSubscriptionRequest): 

574 request = pubsub.GetSubscriptionRequest(request) 

575 

576 # If we have keyword arguments corresponding to fields on the 

577 # request, apply these. 

578 if subscription is not None: 

579 request.subscription = subscription 

580 

581 # Wrap the RPC method; this adds retry and timeout information, 

582 # and friendly error handling. 

583 rpc = self._client._transport._wrapped_methods[ 

584 self._client._transport.get_subscription 

585 ] 

586 

587 # Certain fields should be provided within the metadata header; 

588 # add these here. 

589 metadata = tuple(metadata) + ( 

590 gapic_v1.routing_header.to_grpc_metadata( 

591 (("subscription", request.subscription),) 

592 ), 

593 ) 

594 

595 # Validate the universe domain. 

596 self._client._validate_universe_domain() 

597 

598 # Send the request. 

599 response = await rpc( 

600 request, 

601 retry=retry, 

602 timeout=timeout, 

603 metadata=metadata, 

604 ) 

605 

606 # Done; return the response. 

607 return response 

608 

609 async def update_subscription( 

610 self, 

611 request: Optional[Union[pubsub.UpdateSubscriptionRequest, dict]] = None, 

612 *, 

613 subscription: Optional[pubsub.Subscription] = None, 

614 update_mask: Optional[field_mask_pb2.FieldMask] = None, 

615 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

616 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

617 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

618 ) -> pubsub.Subscription: 

619 r"""Updates an existing subscription by updating the 

620 fields specified in the update mask. Note that certain 

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

622 modifiable. 

623 

624 .. code-block:: python 

625 

626 # This snippet has been automatically generated and should be regarded as a 

627 # code template only. 

628 # It will require modifications to work: 

629 # - It may require correct/in-range values for request initialization. 

630 # - It may require specifying regional endpoints when creating the service 

631 # client as shown in: 

632 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

633 from google import pubsub_v1 

634 

635 async def sample_update_subscription(): 

636 # Create a client 

637 client = pubsub_v1.SubscriberAsyncClient() 

638 

639 # Initialize request argument(s) 

640 subscription = pubsub_v1.Subscription() 

641 subscription.name = "name_value" 

642 subscription.topic = "topic_value" 

643 

644 request = pubsub_v1.UpdateSubscriptionRequest( 

645 subscription=subscription, 

646 ) 

647 

648 # Make the request 

649 response = await client.update_subscription(request=request) 

650 

651 # Handle the response 

652 print(response) 

653 

654 Args: 

655 request (Optional[Union[google.pubsub_v1.types.UpdateSubscriptionRequest, dict]]): 

656 The request object. Request for the UpdateSubscription 

657 method. 

658 subscription (:class:`google.pubsub_v1.types.Subscription`): 

659 Required. The updated subscription 

660 object. 

661 

662 This corresponds to the ``subscription`` field 

663 on the ``request`` instance; if ``request`` is provided, this 

664 should not be set. 

665 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): 

666 Required. Indicates which fields in 

667 the provided subscription to update. 

668 Must be specified and non-empty. 

669 

670 This corresponds to the ``update_mask`` field 

671 on the ``request`` instance; if ``request`` is provided, this 

672 should not be set. 

673 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

674 should be retried. 

675 timeout (float): The timeout for this request. 

676 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

677 sent along with the request as metadata. Normally, each value must be of type `str`, 

678 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

679 be of type `bytes`. 

680 

681 Returns: 

682 google.pubsub_v1.types.Subscription: 

683 A subscription resource. If none of push_config, bigquery_config, or 

684 cloud_storage_config is set, then the subscriber will 

685 pull and ack messages using API methods. At most one 

686 of these fields may be set. 

687 

688 """ 

689 # Create or coerce a protobuf request object. 

690 # - Quick check: If we got a request object, we should *not* have 

691 # gotten any keyword arguments that map to the request. 

692 flattened_params = [subscription, update_mask] 

693 has_flattened_params = ( 

694 len([param for param in flattened_params if param is not None]) > 0 

695 ) 

696 if request is not None and has_flattened_params: 

697 raise ValueError( 

698 "If the `request` argument is set, then none of " 

699 "the individual field arguments should be set." 

700 ) 

701 

702 # - Use the request object if provided (there's no risk of modifying the input as 

703 # there are no flattened fields), or create one. 

704 if not isinstance(request, pubsub.UpdateSubscriptionRequest): 

705 request = pubsub.UpdateSubscriptionRequest(request) 

706 

707 # If we have keyword arguments corresponding to fields on the 

708 # request, apply these. 

709 if subscription is not None: 

710 request.subscription = subscription 

711 if update_mask is not None: 

712 request.update_mask = update_mask 

713 

714 # Wrap the RPC method; this adds retry and timeout information, 

715 # and friendly error handling. 

716 rpc = self._client._transport._wrapped_methods[ 

717 self._client._transport.update_subscription 

718 ] 

719 

720 # Certain fields should be provided within the metadata header; 

721 # add these here. 

722 metadata = tuple(metadata) + ( 

723 gapic_v1.routing_header.to_grpc_metadata( 

724 (("subscription.name", request.subscription.name),) 

725 ), 

726 ) 

727 

728 # Validate the universe domain. 

729 self._client._validate_universe_domain() 

730 

731 # Send the request. 

732 response = await rpc( 

733 request, 

734 retry=retry, 

735 timeout=timeout, 

736 metadata=metadata, 

737 ) 

738 

739 # Done; return the response. 

740 return response 

741 

742 async def list_subscriptions( 

743 self, 

744 request: Optional[Union[pubsub.ListSubscriptionsRequest, dict]] = None, 

745 *, 

746 project: Optional[str] = None, 

747 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

748 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

749 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

750 ) -> pagers.ListSubscriptionsAsyncPager: 

751 r"""Lists matching subscriptions. 

752 

753 .. code-block:: python 

754 

755 # This snippet has been automatically generated and should be regarded as a 

756 # code template only. 

757 # It will require modifications to work: 

758 # - It may require correct/in-range values for request initialization. 

759 # - It may require specifying regional endpoints when creating the service 

760 # client as shown in: 

761 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

762 from google import pubsub_v1 

763 

764 async def sample_list_subscriptions(): 

765 # Create a client 

766 client = pubsub_v1.SubscriberAsyncClient() 

767 

768 # Initialize request argument(s) 

769 request = pubsub_v1.ListSubscriptionsRequest( 

770 project="project_value", 

771 ) 

772 

773 # Make the request 

774 page_result = client.list_subscriptions(request=request) 

775 

776 # Handle the response 

777 async for response in page_result: 

778 print(response) 

779 

780 Args: 

781 request (Optional[Union[google.pubsub_v1.types.ListSubscriptionsRequest, dict]]): 

782 The request object. Request for the ``ListSubscriptions`` method. 

783 project (:class:`str`): 

784 Required. The name of the project in which to list 

785 subscriptions. Format is ``projects/{project-id}``. 

786 

787 This corresponds to the ``project`` field 

788 on the ``request`` instance; if ``request`` is provided, this 

789 should not be set. 

790 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

791 should be retried. 

792 timeout (float): The timeout for this request. 

793 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

794 sent along with the request as metadata. Normally, each value must be of type `str`, 

795 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

796 be of type `bytes`. 

797 

798 Returns: 

799 google.pubsub_v1.services.subscriber.pagers.ListSubscriptionsAsyncPager: 

800 Response for the ListSubscriptions method. 

801 

802 Iterating over this object will yield results and 

803 resolve additional pages automatically. 

804 

805 """ 

806 # Create or coerce a protobuf request object. 

807 # - Quick check: If we got a request object, we should *not* have 

808 # gotten any keyword arguments that map to the request. 

809 flattened_params = [project] 

810 has_flattened_params = ( 

811 len([param for param in flattened_params if param is not None]) > 0 

812 ) 

813 if request is not None and has_flattened_params: 

814 raise ValueError( 

815 "If the `request` argument is set, then none of " 

816 "the individual field arguments should be set." 

817 ) 

818 

819 # - Use the request object if provided (there's no risk of modifying the input as 

820 # there are no flattened fields), or create one. 

821 if not isinstance(request, pubsub.ListSubscriptionsRequest): 

822 request = pubsub.ListSubscriptionsRequest(request) 

823 

824 # If we have keyword arguments corresponding to fields on the 

825 # request, apply these. 

826 if project is not None: 

827 request.project = project 

828 

829 # Wrap the RPC method; this adds retry and timeout information, 

830 # and friendly error handling. 

831 rpc = self._client._transport._wrapped_methods[ 

832 self._client._transport.list_subscriptions 

833 ] 

834 

835 # Certain fields should be provided within the metadata header; 

836 # add these here. 

837 metadata = tuple(metadata) + ( 

838 gapic_v1.routing_header.to_grpc_metadata((("project", request.project),)), 

839 ) 

840 

841 # Validate the universe domain. 

842 self._client._validate_universe_domain() 

843 

844 # Send the request. 

845 response = await rpc( 

846 request, 

847 retry=retry, 

848 timeout=timeout, 

849 metadata=metadata, 

850 ) 

851 

852 # This method is paged; wrap the response in a pager, which provides 

853 # an `__aiter__` convenience method. 

854 response = pagers.ListSubscriptionsAsyncPager( 

855 method=rpc, 

856 request=request, 

857 response=response, 

858 retry=retry, 

859 timeout=timeout, 

860 metadata=metadata, 

861 ) 

862 

863 # Done; return the response. 

864 return response 

865 

866 async def delete_subscription( 

867 self, 

868 request: Optional[Union[pubsub.DeleteSubscriptionRequest, dict]] = None, 

869 *, 

870 subscription: Optional[str] = None, 

871 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

872 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

873 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

874 ) -> None: 

875 r"""Deletes an existing subscription. All messages retained in the 

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

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

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

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

880 topic unless the same topic is specified. 

881 

882 .. code-block:: python 

883 

884 # This snippet has been automatically generated and should be regarded as a 

885 # code template only. 

886 # It will require modifications to work: 

887 # - It may require correct/in-range values for request initialization. 

888 # - It may require specifying regional endpoints when creating the service 

889 # client as shown in: 

890 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

891 from google import pubsub_v1 

892 

893 async def sample_delete_subscription(): 

894 # Create a client 

895 client = pubsub_v1.SubscriberAsyncClient() 

896 

897 # Initialize request argument(s) 

898 request = pubsub_v1.DeleteSubscriptionRequest( 

899 subscription="subscription_value", 

900 ) 

901 

902 # Make the request 

903 await client.delete_subscription(request=request) 

904 

905 Args: 

906 request (Optional[Union[google.pubsub_v1.types.DeleteSubscriptionRequest, dict]]): 

907 The request object. Request for the DeleteSubscription 

908 method. 

909 subscription (:class:`str`): 

910 Required. The subscription to delete. Format is 

911 ``projects/{project}/subscriptions/{sub}``. 

912 

913 This corresponds to the ``subscription`` field 

914 on the ``request`` instance; if ``request`` is provided, this 

915 should not be set. 

916 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

917 should be retried. 

918 timeout (float): The timeout for this request. 

919 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

920 sent along with the request as metadata. Normally, each value must be of type `str`, 

921 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

922 be of type `bytes`. 

923 """ 

924 # Create or coerce a protobuf request object. 

925 # - Quick check: If we got a request object, we should *not* have 

926 # gotten any keyword arguments that map to the request. 

927 flattened_params = [subscription] 

928 has_flattened_params = ( 

929 len([param for param in flattened_params if param is not None]) > 0 

930 ) 

931 if request is not None and has_flattened_params: 

932 raise ValueError( 

933 "If the `request` argument is set, then none of " 

934 "the individual field arguments should be set." 

935 ) 

936 

937 # - Use the request object if provided (there's no risk of modifying the input as 

938 # there are no flattened fields), or create one. 

939 if not isinstance(request, pubsub.DeleteSubscriptionRequest): 

940 request = pubsub.DeleteSubscriptionRequest(request) 

941 

942 # If we have keyword arguments corresponding to fields on the 

943 # request, apply these. 

944 if subscription is not None: 

945 request.subscription = subscription 

946 

947 # Wrap the RPC method; this adds retry and timeout information, 

948 # and friendly error handling. 

949 rpc = self._client._transport._wrapped_methods[ 

950 self._client._transport.delete_subscription 

951 ] 

952 

953 # Certain fields should be provided within the metadata header; 

954 # add these here. 

955 metadata = tuple(metadata) + ( 

956 gapic_v1.routing_header.to_grpc_metadata( 

957 (("subscription", request.subscription),) 

958 ), 

959 ) 

960 

961 # Validate the universe domain. 

962 self._client._validate_universe_domain() 

963 

964 # Send the request. 

965 await rpc( 

966 request, 

967 retry=retry, 

968 timeout=timeout, 

969 metadata=metadata, 

970 ) 

971 

972 async def modify_ack_deadline( 

973 self, 

974 request: Optional[Union[pubsub.ModifyAckDeadlineRequest, dict]] = None, 

975 *, 

976 subscription: Optional[str] = None, 

977 ack_ids: Optional[MutableSequence[str]] = None, 

978 ack_deadline_seconds: Optional[int] = None, 

979 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

980 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

981 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

982 ) -> None: 

983 r"""Modifies the ack deadline for a specific message. This method is 

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

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

986 redelivery if the processing was interrupted. Note that this 

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

988 used for subsequent messages. 

989 

990 .. code-block:: python 

991 

992 # This snippet has been automatically generated and should be regarded as a 

993 # code template only. 

994 # It will require modifications to work: 

995 # - It may require correct/in-range values for request initialization. 

996 # - It may require specifying regional endpoints when creating the service 

997 # client as shown in: 

998 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

999 from google import pubsub_v1 

1000 

1001 async def sample_modify_ack_deadline(): 

1002 # Create a client 

1003 client = pubsub_v1.SubscriberAsyncClient() 

1004 

1005 # Initialize request argument(s) 

1006 request = pubsub_v1.ModifyAckDeadlineRequest( 

1007 subscription="subscription_value", 

1008 ack_ids=['ack_ids_value1', 'ack_ids_value2'], 

1009 ack_deadline_seconds=2066, 

1010 ) 

1011 

1012 # Make the request 

1013 await client.modify_ack_deadline(request=request) 

1014 

1015 Args: 

1016 request (Optional[Union[google.pubsub_v1.types.ModifyAckDeadlineRequest, dict]]): 

1017 The request object. Request for the ModifyAckDeadline 

1018 method. 

1019 subscription (:class:`str`): 

1020 Required. The name of the subscription. Format is 

1021 ``projects/{project}/subscriptions/{sub}``. 

1022 

1023 This corresponds to the ``subscription`` field 

1024 on the ``request`` instance; if ``request`` is provided, this 

1025 should not be set. 

1026 ack_ids (:class:`MutableSequence[str]`): 

1027 Required. List of acknowledgment IDs. 

1028 This corresponds to the ``ack_ids`` field 

1029 on the ``request`` instance; if ``request`` is provided, this 

1030 should not be set. 

1031 ack_deadline_seconds (:class:`int`): 

1032 Required. The new ack deadline with respect to the time 

1033 this request was sent to the Pub/Sub system. For 

1034 example, if the value is 10, the new ack deadline will 

1035 expire 10 seconds after the ``ModifyAckDeadline`` call 

1036 was made. Specifying zero might immediately make the 

1037 message available for delivery to another subscriber 

1038 client. This typically results in an increase in the 

1039 rate of message redeliveries (that is, duplicates). The 

1040 minimum deadline you can specify is 0 seconds. The 

1041 maximum deadline you can specify in a single request is 

1042 600 seconds (10 minutes). 

1043 

1044 This corresponds to the ``ack_deadline_seconds`` field 

1045 on the ``request`` instance; if ``request`` is provided, this 

1046 should not be set. 

1047 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1048 should be retried. 

1049 timeout (float): The timeout for this request. 

1050 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1051 sent along with the request as metadata. Normally, each value must be of type `str`, 

1052 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1053 be of type `bytes`. 

1054 """ 

1055 # Create or coerce a protobuf request object. 

1056 # - Quick check: If we got a request object, we should *not* have 

1057 # gotten any keyword arguments that map to the request. 

1058 flattened_params = [subscription, ack_ids, ack_deadline_seconds] 

1059 has_flattened_params = ( 

1060 len([param for param in flattened_params if param is not None]) > 0 

1061 ) 

1062 if request is not None and has_flattened_params: 

1063 raise ValueError( 

1064 "If the `request` argument is set, then none of " 

1065 "the individual field arguments should be set." 

1066 ) 

1067 

1068 # - Use the request object if provided (there's no risk of modifying the input as 

1069 # there are no flattened fields), or create one. 

1070 if not isinstance(request, pubsub.ModifyAckDeadlineRequest): 

1071 request = pubsub.ModifyAckDeadlineRequest(request) 

1072 

1073 # If we have keyword arguments corresponding to fields on the 

1074 # request, apply these. 

1075 if subscription is not None: 

1076 request.subscription = subscription 

1077 if ack_deadline_seconds is not None: 

1078 request.ack_deadline_seconds = ack_deadline_seconds 

1079 if ack_ids: 

1080 request.ack_ids.extend(ack_ids) 

1081 

1082 # Wrap the RPC method; this adds retry and timeout information, 

1083 # and friendly error handling. 

1084 rpc = self._client._transport._wrapped_methods[ 

1085 self._client._transport.modify_ack_deadline 

1086 ] 

1087 

1088 # Certain fields should be provided within the metadata header; 

1089 # add these here. 

1090 metadata = tuple(metadata) + ( 

1091 gapic_v1.routing_header.to_grpc_metadata( 

1092 (("subscription", request.subscription),) 

1093 ), 

1094 ) 

1095 

1096 # Validate the universe domain. 

1097 self._client._validate_universe_domain() 

1098 

1099 # Send the request. 

1100 await rpc( 

1101 request, 

1102 retry=retry, 

1103 timeout=timeout, 

1104 metadata=metadata, 

1105 ) 

1106 

1107 async def acknowledge( 

1108 self, 

1109 request: Optional[Union[pubsub.AcknowledgeRequest, dict]] = None, 

1110 *, 

1111 subscription: Optional[str] = None, 

1112 ack_ids: Optional[MutableSequence[str]] = None, 

1113 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1114 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1115 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1116 ) -> None: 

1117 r"""Acknowledges the messages associated with the ``ack_ids`` in the 

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

1119 relevant messages from the subscription. 

1120 

1121 Acknowledging a message whose ack deadline has expired may 

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

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

1124 error. 

1125 

1126 .. code-block:: python 

1127 

1128 # This snippet has been automatically generated and should be regarded as a 

1129 # code template only. 

1130 # It will require modifications to work: 

1131 # - It may require correct/in-range values for request initialization. 

1132 # - It may require specifying regional endpoints when creating the service 

1133 # client as shown in: 

1134 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1135 from google import pubsub_v1 

1136 

1137 async def sample_acknowledge(): 

1138 # Create a client 

1139 client = pubsub_v1.SubscriberAsyncClient() 

1140 

1141 # Initialize request argument(s) 

1142 request = pubsub_v1.AcknowledgeRequest( 

1143 subscription="subscription_value", 

1144 ack_ids=['ack_ids_value1', 'ack_ids_value2'], 

1145 ) 

1146 

1147 # Make the request 

1148 await client.acknowledge(request=request) 

1149 

1150 Args: 

1151 request (Optional[Union[google.pubsub_v1.types.AcknowledgeRequest, dict]]): 

1152 The request object. Request for the Acknowledge method. 

1153 subscription (:class:`str`): 

1154 Required. The subscription whose message is being 

1155 acknowledged. Format is 

1156 ``projects/{project}/subscriptions/{sub}``. 

1157 

1158 This corresponds to the ``subscription`` field 

1159 on the ``request`` instance; if ``request`` is provided, this 

1160 should not be set. 

1161 ack_ids (:class:`MutableSequence[str]`): 

1162 Required. The acknowledgment ID for the messages being 

1163 acknowledged that was returned by the Pub/Sub system in 

1164 the ``Pull`` response. Must not be empty. 

1165 

1166 This corresponds to the ``ack_ids`` field 

1167 on the ``request`` instance; if ``request`` is provided, this 

1168 should not be set. 

1169 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1170 should be retried. 

1171 timeout (float): The timeout for this request. 

1172 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1173 sent along with the request as metadata. Normally, each value must be of type `str`, 

1174 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1175 be of type `bytes`. 

1176 """ 

1177 # Create or coerce a protobuf request object. 

1178 # - Quick check: If we got a request object, we should *not* have 

1179 # gotten any keyword arguments that map to the request. 

1180 flattened_params = [subscription, ack_ids] 

1181 has_flattened_params = ( 

1182 len([param for param in flattened_params if param is not None]) > 0 

1183 ) 

1184 if request is not None and has_flattened_params: 

1185 raise ValueError( 

1186 "If the `request` argument is set, then none of " 

1187 "the individual field arguments should be set." 

1188 ) 

1189 

1190 # - Use the request object if provided (there's no risk of modifying the input as 

1191 # there are no flattened fields), or create one. 

1192 if not isinstance(request, pubsub.AcknowledgeRequest): 

1193 request = pubsub.AcknowledgeRequest(request) 

1194 

1195 # If we have keyword arguments corresponding to fields on the 

1196 # request, apply these. 

1197 if subscription is not None: 

1198 request.subscription = subscription 

1199 if ack_ids: 

1200 request.ack_ids.extend(ack_ids) 

1201 

1202 # Wrap the RPC method; this adds retry and timeout information, 

1203 # and friendly error handling. 

1204 rpc = self._client._transport._wrapped_methods[ 

1205 self._client._transport.acknowledge 

1206 ] 

1207 

1208 # Certain fields should be provided within the metadata header; 

1209 # add these here. 

1210 metadata = tuple(metadata) + ( 

1211 gapic_v1.routing_header.to_grpc_metadata( 

1212 (("subscription", request.subscription),) 

1213 ), 

1214 ) 

1215 

1216 # Validate the universe domain. 

1217 self._client._validate_universe_domain() 

1218 

1219 # Send the request. 

1220 await rpc( 

1221 request, 

1222 retry=retry, 

1223 timeout=timeout, 

1224 metadata=metadata, 

1225 ) 

1226 

1227 async def pull( 

1228 self, 

1229 request: Optional[Union[pubsub.PullRequest, dict]] = None, 

1230 *, 

1231 subscription: Optional[str] = None, 

1232 return_immediately: Optional[bool] = None, 

1233 max_messages: Optional[int] = None, 

1234 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1235 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1236 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1237 ) -> pubsub.PullResponse: 

1238 r"""Pulls messages from the server. 

1239 

1240 .. code-block:: python 

1241 

1242 # This snippet has been automatically generated and should be regarded as a 

1243 # code template only. 

1244 # It will require modifications to work: 

1245 # - It may require correct/in-range values for request initialization. 

1246 # - It may require specifying regional endpoints when creating the service 

1247 # client as shown in: 

1248 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1249 from google import pubsub_v1 

1250 

1251 async def sample_pull(): 

1252 # Create a client 

1253 client = pubsub_v1.SubscriberAsyncClient() 

1254 

1255 # Initialize request argument(s) 

1256 request = pubsub_v1.PullRequest( 

1257 subscription="subscription_value", 

1258 max_messages=1277, 

1259 ) 

1260 

1261 # Make the request 

1262 response = await client.pull(request=request) 

1263 

1264 # Handle the response 

1265 print(response) 

1266 

1267 Args: 

1268 request (Optional[Union[google.pubsub_v1.types.PullRequest, dict]]): 

1269 The request object. Request for the ``Pull`` method. 

1270 subscription (:class:`str`): 

1271 Required. The subscription from which messages should be 

1272 pulled. Format is 

1273 ``projects/{project}/subscriptions/{sub}``. 

1274 

1275 This corresponds to the ``subscription`` field 

1276 on the ``request`` instance; if ``request`` is provided, this 

1277 should not be set. 

1278 return_immediately (:class:`bool`): 

1279 Optional. If this field set to true, the system will 

1280 respond immediately even if it there are no messages 

1281 available to return in the ``Pull`` response. Otherwise, 

1282 the system may wait (for a bounded amount of time) until 

1283 at least one message is available, rather than returning 

1284 no messages. Warning: setting this field to ``true`` is 

1285 discouraged because it adversely impacts the performance 

1286 of ``Pull`` operations. We recommend that users do not 

1287 set this field. 

1288 

1289 This corresponds to the ``return_immediately`` field 

1290 on the ``request`` instance; if ``request`` is provided, this 

1291 should not be set. 

1292 max_messages (:class:`int`): 

1293 Required. The maximum number of 

1294 messages to return for this request. 

1295 Must be a positive integer. The Pub/Sub 

1296 system may return fewer than the number 

1297 specified. 

1298 

1299 This corresponds to the ``max_messages`` field 

1300 on the ``request`` instance; if ``request`` is provided, this 

1301 should not be set. 

1302 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1303 should be retried. 

1304 timeout (float): The timeout for this request. 

1305 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1306 sent along with the request as metadata. Normally, each value must be of type `str`, 

1307 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1308 be of type `bytes`. 

1309 

1310 Returns: 

1311 google.pubsub_v1.types.PullResponse: 

1312 Response for the Pull method. 

1313 """ 

1314 # Create or coerce a protobuf request object. 

1315 # - Quick check: If we got a request object, we should *not* have 

1316 # gotten any keyword arguments that map to the request. 

1317 flattened_params = [subscription, return_immediately, max_messages] 

1318 has_flattened_params = ( 

1319 len([param for param in flattened_params if param is not None]) > 0 

1320 ) 

1321 if request is not None and has_flattened_params: 

1322 raise ValueError( 

1323 "If the `request` argument is set, then none of " 

1324 "the individual field arguments should be set." 

1325 ) 

1326 

1327 # - Use the request object if provided (there's no risk of modifying the input as 

1328 # there are no flattened fields), or create one. 

1329 if not isinstance(request, pubsub.PullRequest): 

1330 request = pubsub.PullRequest(request) 

1331 

1332 # If we have keyword arguments corresponding to fields on the 

1333 # request, apply these. 

1334 if subscription is not None: 

1335 request.subscription = subscription 

1336 if return_immediately is not None: 

1337 request.return_immediately = return_immediately 

1338 if max_messages is not None: 

1339 request.max_messages = max_messages 

1340 

1341 if request.return_immediately: 

1342 warnings.warn( 

1343 "The return_immediately flag is deprecated and should be set to False.", 

1344 category=DeprecationWarning, 

1345 ) 

1346 

1347 # Wrap the RPC method; this adds retry and timeout information, 

1348 # and friendly error handling. 

1349 rpc = self._client._transport._wrapped_methods[self._client._transport.pull] 

1350 

1351 # Certain fields should be provided within the metadata header; 

1352 # add these here. 

1353 metadata = tuple(metadata) + ( 

1354 gapic_v1.routing_header.to_grpc_metadata( 

1355 (("subscription", request.subscription),) 

1356 ), 

1357 ) 

1358 

1359 # Validate the universe domain. 

1360 self._client._validate_universe_domain() 

1361 

1362 # Send the request. 

1363 response = await rpc( 

1364 request, 

1365 retry=retry, 

1366 timeout=timeout, 

1367 metadata=metadata, 

1368 ) 

1369 

1370 # Done; return the response. 

1371 return response 

1372 

1373 def streaming_pull( 

1374 self, 

1375 requests: Optional[AsyncIterator[pubsub.StreamingPullRequest]] = None, 

1376 *, 

1377 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1378 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1379 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1380 ) -> Awaitable[AsyncIterable[pubsub.StreamingPullResponse]]: 

1381 r"""Establishes a stream with the server, which sends messages down 

1382 to the client. The client streams acknowledgments and ack 

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

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

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

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

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

1388 configuring the underlying RPC channel. 

1389 

1390 .. code-block:: python 

1391 

1392 # This snippet has been automatically generated and should be regarded as a 

1393 # code template only. 

1394 # It will require modifications to work: 

1395 # - It may require correct/in-range values for request initialization. 

1396 # - It may require specifying regional endpoints when creating the service 

1397 # client as shown in: 

1398 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1399 from google import pubsub_v1 

1400 

1401 async def sample_streaming_pull(): 

1402 # Create a client 

1403 client = pubsub_v1.SubscriberAsyncClient() 

1404 

1405 # Initialize request argument(s) 

1406 request = pubsub_v1.StreamingPullRequest( 

1407 subscription="subscription_value", 

1408 stream_ack_deadline_seconds=2813, 

1409 ) 

1410 

1411 # This method expects an iterator which contains 

1412 # 'pubsub_v1.StreamingPullRequest' objects 

1413 # Here we create a generator that yields a single `request` for 

1414 # demonstrative purposes. 

1415 requests = [request] 

1416 

1417 def request_generator(): 

1418 for request in requests: 

1419 yield request 

1420 

1421 # Make the request 

1422 stream = await client.streaming_pull(requests=request_generator()) 

1423 

1424 # Handle the response 

1425 async for response in stream: 

1426 print(response) 

1427 

1428 Args: 

1429 requests (AsyncIterator[`google.pubsub_v1.types.StreamingPullRequest`]): 

1430 The request object AsyncIterator. Request for the ``StreamingPull`` streaming RPC method. 

1431 This request is used to establish the initial stream as 

1432 well as to stream acknowledgments and ack deadline 

1433 modifications from the client to the server. 

1434 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1435 should be retried. 

1436 timeout (float): The timeout for this request. 

1437 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1438 sent along with the request as metadata. Normally, each value must be of type `str`, 

1439 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1440 be of type `bytes`. 

1441 

1442 Returns: 

1443 AsyncIterable[google.pubsub_v1.types.StreamingPullResponse]: 

1444 Response for the StreamingPull method. This response is used to stream 

1445 messages from the server to the client. 

1446 

1447 """ 

1448 

1449 # Wrap the RPC method; this adds retry and timeout information, 

1450 # and friendly error handling. 

1451 rpc = self._client._transport._wrapped_methods[ 

1452 self._client._transport.streaming_pull 

1453 ] 

1454 

1455 # Validate the universe domain. 

1456 self._client._validate_universe_domain() 

1457 

1458 # Send the request. 

1459 response = rpc( 

1460 requests, 

1461 retry=retry, 

1462 timeout=timeout, 

1463 metadata=metadata, 

1464 ) 

1465 

1466 # Done; return the response. 

1467 return response 

1468 

1469 async def modify_push_config( 

1470 self, 

1471 request: Optional[Union[pubsub.ModifyPushConfigRequest, dict]] = None, 

1472 *, 

1473 subscription: Optional[str] = None, 

1474 push_config: Optional[pubsub.PushConfig] = None, 

1475 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1476 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1477 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1478 ) -> None: 

1479 r"""Modifies the ``PushConfig`` for a specified subscription. 

1480 

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

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

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

1484 Messages will accumulate for delivery continuously through the 

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

1486 

1487 .. code-block:: python 

1488 

1489 # This snippet has been automatically generated and should be regarded as a 

1490 # code template only. 

1491 # It will require modifications to work: 

1492 # - It may require correct/in-range values for request initialization. 

1493 # - It may require specifying regional endpoints when creating the service 

1494 # client as shown in: 

1495 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1496 from google import pubsub_v1 

1497 

1498 async def sample_modify_push_config(): 

1499 # Create a client 

1500 client = pubsub_v1.SubscriberAsyncClient() 

1501 

1502 # Initialize request argument(s) 

1503 request = pubsub_v1.ModifyPushConfigRequest( 

1504 subscription="subscription_value", 

1505 ) 

1506 

1507 # Make the request 

1508 await client.modify_push_config(request=request) 

1509 

1510 Args: 

1511 request (Optional[Union[google.pubsub_v1.types.ModifyPushConfigRequest, dict]]): 

1512 The request object. Request for the ModifyPushConfig 

1513 method. 

1514 subscription (:class:`str`): 

1515 Required. The name of the subscription. Format is 

1516 ``projects/{project}/subscriptions/{sub}``. 

1517 

1518 This corresponds to the ``subscription`` field 

1519 on the ``request`` instance; if ``request`` is provided, this 

1520 should not be set. 

1521 push_config (:class:`google.pubsub_v1.types.PushConfig`): 

1522 Required. The push configuration for future deliveries. 

1523 

1524 An empty ``pushConfig`` indicates that the Pub/Sub 

1525 system should stop pushing messages from the given 

1526 subscription and allow messages to be pulled and 

1527 acknowledged - effectively pausing the subscription if 

1528 ``Pull`` or ``StreamingPull`` is not called. 

1529 

1530 This corresponds to the ``push_config`` field 

1531 on the ``request`` instance; if ``request`` is provided, this 

1532 should not be set. 

1533 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1534 should be retried. 

1535 timeout (float): The timeout for this request. 

1536 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1537 sent along with the request as metadata. Normally, each value must be of type `str`, 

1538 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1539 be of type `bytes`. 

1540 """ 

1541 # Create or coerce a protobuf request object. 

1542 # - Quick check: If we got a request object, we should *not* have 

1543 # gotten any keyword arguments that map to the request. 

1544 flattened_params = [subscription, push_config] 

1545 has_flattened_params = ( 

1546 len([param for param in flattened_params if param is not None]) > 0 

1547 ) 

1548 if request is not None and has_flattened_params: 

1549 raise ValueError( 

1550 "If the `request` argument is set, then none of " 

1551 "the individual field arguments should be set." 

1552 ) 

1553 

1554 # - Use the request object if provided (there's no risk of modifying the input as 

1555 # there are no flattened fields), or create one. 

1556 if not isinstance(request, pubsub.ModifyPushConfigRequest): 

1557 request = pubsub.ModifyPushConfigRequest(request) 

1558 

1559 # If we have keyword arguments corresponding to fields on the 

1560 # request, apply these. 

1561 if subscription is not None: 

1562 request.subscription = subscription 

1563 if push_config is not None: 

1564 request.push_config = push_config 

1565 

1566 # Wrap the RPC method; this adds retry and timeout information, 

1567 # and friendly error handling. 

1568 rpc = self._client._transport._wrapped_methods[ 

1569 self._client._transport.modify_push_config 

1570 ] 

1571 

1572 # Certain fields should be provided within the metadata header; 

1573 # add these here. 

1574 metadata = tuple(metadata) + ( 

1575 gapic_v1.routing_header.to_grpc_metadata( 

1576 (("subscription", request.subscription),) 

1577 ), 

1578 ) 

1579 

1580 # Validate the universe domain. 

1581 self._client._validate_universe_domain() 

1582 

1583 # Send the request. 

1584 await rpc( 

1585 request, 

1586 retry=retry, 

1587 timeout=timeout, 

1588 metadata=metadata, 

1589 ) 

1590 

1591 async def get_snapshot( 

1592 self, 

1593 request: Optional[Union[pubsub.GetSnapshotRequest, dict]] = None, 

1594 *, 

1595 snapshot: Optional[str] = None, 

1596 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1597 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1598 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1599 ) -> pubsub.Snapshot: 

1600 r"""Gets the configuration details of a snapshot. Snapshots are used 

1601 in 

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

1603 operations, which allow you to manage message acknowledgments in 

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

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

1606 

1607 .. code-block:: python 

1608 

1609 # This snippet has been automatically generated and should be regarded as a 

1610 # code template only. 

1611 # It will require modifications to work: 

1612 # - It may require correct/in-range values for request initialization. 

1613 # - It may require specifying regional endpoints when creating the service 

1614 # client as shown in: 

1615 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1616 from google import pubsub_v1 

1617 

1618 async def sample_get_snapshot(): 

1619 # Create a client 

1620 client = pubsub_v1.SubscriberAsyncClient() 

1621 

1622 # Initialize request argument(s) 

1623 request = pubsub_v1.GetSnapshotRequest( 

1624 snapshot="snapshot_value", 

1625 ) 

1626 

1627 # Make the request 

1628 response = await client.get_snapshot(request=request) 

1629 

1630 # Handle the response 

1631 print(response) 

1632 

1633 Args: 

1634 request (Optional[Union[google.pubsub_v1.types.GetSnapshotRequest, dict]]): 

1635 The request object. Request for the GetSnapshot method. 

1636 snapshot (:class:`str`): 

1637 Required. The name of the snapshot to get. Format is 

1638 ``projects/{project}/snapshots/{snap}``. 

1639 

1640 This corresponds to the ``snapshot`` field 

1641 on the ``request`` instance; if ``request`` is provided, this 

1642 should not be set. 

1643 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1644 should be retried. 

1645 timeout (float): The timeout for this request. 

1646 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1647 sent along with the request as metadata. Normally, each value must be of type `str`, 

1648 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1649 be of type `bytes`. 

1650 

1651 Returns: 

1652 google.pubsub_v1.types.Snapshot: 

1653 A snapshot resource. Snapshots are used in 

1654 [Seek](https://cloud.google.com/pubsub/docs/replay-overview) 

1655 operations, which allow you to manage message 

1656 acknowledgments in bulk. That is, you can set the 

1657 acknowledgment state of messages in an existing 

1658 subscription to the state captured by a snapshot. 

1659 

1660 """ 

1661 # Create or coerce a protobuf request object. 

1662 # - Quick check: If we got a request object, we should *not* have 

1663 # gotten any keyword arguments that map to the request. 

1664 flattened_params = [snapshot] 

1665 has_flattened_params = ( 

1666 len([param for param in flattened_params if param is not None]) > 0 

1667 ) 

1668 if request is not None and has_flattened_params: 

1669 raise ValueError( 

1670 "If the `request` argument is set, then none of " 

1671 "the individual field arguments should be set." 

1672 ) 

1673 

1674 # - Use the request object if provided (there's no risk of modifying the input as 

1675 # there are no flattened fields), or create one. 

1676 if not isinstance(request, pubsub.GetSnapshotRequest): 

1677 request = pubsub.GetSnapshotRequest(request) 

1678 

1679 # If we have keyword arguments corresponding to fields on the 

1680 # request, apply these. 

1681 if snapshot is not None: 

1682 request.snapshot = snapshot 

1683 

1684 # Wrap the RPC method; this adds retry and timeout information, 

1685 # and friendly error handling. 

1686 rpc = self._client._transport._wrapped_methods[ 

1687 self._client._transport.get_snapshot 

1688 ] 

1689 

1690 # Certain fields should be provided within the metadata header; 

1691 # add these here. 

1692 metadata = tuple(metadata) + ( 

1693 gapic_v1.routing_header.to_grpc_metadata((("snapshot", request.snapshot),)), 

1694 ) 

1695 

1696 # Validate the universe domain. 

1697 self._client._validate_universe_domain() 

1698 

1699 # Send the request. 

1700 response = await rpc( 

1701 request, 

1702 retry=retry, 

1703 timeout=timeout, 

1704 metadata=metadata, 

1705 ) 

1706 

1707 # Done; return the response. 

1708 return response 

1709 

1710 async def list_snapshots( 

1711 self, 

1712 request: Optional[Union[pubsub.ListSnapshotsRequest, dict]] = None, 

1713 *, 

1714 project: Optional[str] = None, 

1715 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1716 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1717 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1718 ) -> pagers.ListSnapshotsAsyncPager: 

1719 r"""Lists the existing snapshots. Snapshots are used in 

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

1721 operations, which allow you to manage message acknowledgments in 

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

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

1724 

1725 .. code-block:: python 

1726 

1727 # This snippet has been automatically generated and should be regarded as a 

1728 # code template only. 

1729 # It will require modifications to work: 

1730 # - It may require correct/in-range values for request initialization. 

1731 # - It may require specifying regional endpoints when creating the service 

1732 # client as shown in: 

1733 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1734 from google import pubsub_v1 

1735 

1736 async def sample_list_snapshots(): 

1737 # Create a client 

1738 client = pubsub_v1.SubscriberAsyncClient() 

1739 

1740 # Initialize request argument(s) 

1741 request = pubsub_v1.ListSnapshotsRequest( 

1742 project="project_value", 

1743 ) 

1744 

1745 # Make the request 

1746 page_result = client.list_snapshots(request=request) 

1747 

1748 # Handle the response 

1749 async for response in page_result: 

1750 print(response) 

1751 

1752 Args: 

1753 request (Optional[Union[google.pubsub_v1.types.ListSnapshotsRequest, dict]]): 

1754 The request object. Request for the ``ListSnapshots`` method. 

1755 project (:class:`str`): 

1756 Required. The name of the project in which to list 

1757 snapshots. Format is ``projects/{project-id}``. 

1758 

1759 This corresponds to the ``project`` field 

1760 on the ``request`` instance; if ``request`` is provided, this 

1761 should not be set. 

1762 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1763 should be retried. 

1764 timeout (float): The timeout for this request. 

1765 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1766 sent along with the request as metadata. Normally, each value must be of type `str`, 

1767 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1768 be of type `bytes`. 

1769 

1770 Returns: 

1771 google.pubsub_v1.services.subscriber.pagers.ListSnapshotsAsyncPager: 

1772 Response for the ListSnapshots method. 

1773 

1774 Iterating over this object will yield results and 

1775 resolve additional pages automatically. 

1776 

1777 """ 

1778 # Create or coerce a protobuf request object. 

1779 # - Quick check: If we got a request object, we should *not* have 

1780 # gotten any keyword arguments that map to the request. 

1781 flattened_params = [project] 

1782 has_flattened_params = ( 

1783 len([param for param in flattened_params if param is not None]) > 0 

1784 ) 

1785 if request is not None and has_flattened_params: 

1786 raise ValueError( 

1787 "If the `request` argument is set, then none of " 

1788 "the individual field arguments should be set." 

1789 ) 

1790 

1791 # - Use the request object if provided (there's no risk of modifying the input as 

1792 # there are no flattened fields), or create one. 

1793 if not isinstance(request, pubsub.ListSnapshotsRequest): 

1794 request = pubsub.ListSnapshotsRequest(request) 

1795 

1796 # If we have keyword arguments corresponding to fields on the 

1797 # request, apply these. 

1798 if project is not None: 

1799 request.project = project 

1800 

1801 # Wrap the RPC method; this adds retry and timeout information, 

1802 # and friendly error handling. 

1803 rpc = self._client._transport._wrapped_methods[ 

1804 self._client._transport.list_snapshots 

1805 ] 

1806 

1807 # Certain fields should be provided within the metadata header; 

1808 # add these here. 

1809 metadata = tuple(metadata) + ( 

1810 gapic_v1.routing_header.to_grpc_metadata((("project", request.project),)), 

1811 ) 

1812 

1813 # Validate the universe domain. 

1814 self._client._validate_universe_domain() 

1815 

1816 # Send the request. 

1817 response = await rpc( 

1818 request, 

1819 retry=retry, 

1820 timeout=timeout, 

1821 metadata=metadata, 

1822 ) 

1823 

1824 # This method is paged; wrap the response in a pager, which provides 

1825 # an `__aiter__` convenience method. 

1826 response = pagers.ListSnapshotsAsyncPager( 

1827 method=rpc, 

1828 request=request, 

1829 response=response, 

1830 retry=retry, 

1831 timeout=timeout, 

1832 metadata=metadata, 

1833 ) 

1834 

1835 # Done; return the response. 

1836 return response 

1837 

1838 async def create_snapshot( 

1839 self, 

1840 request: Optional[Union[pubsub.CreateSnapshotRequest, dict]] = None, 

1841 *, 

1842 name: Optional[str] = None, 

1843 subscription: Optional[str] = None, 

1844 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1845 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1846 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1847 ) -> pubsub.Snapshot: 

1848 r"""Creates a snapshot from the requested subscription. Snapshots 

1849 are used in 

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

1851 operations, which allow you to manage message acknowledgments in 

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

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

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

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

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

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

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

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

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

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

1862 the [resource name format] 

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

1864 The generated name is populated in the returned Snapshot object. 

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

1866 request. 

1867 

1868 .. code-block:: python 

1869 

1870 # This snippet has been automatically generated and should be regarded as a 

1871 # code template only. 

1872 # It will require modifications to work: 

1873 # - It may require correct/in-range values for request initialization. 

1874 # - It may require specifying regional endpoints when creating the service 

1875 # client as shown in: 

1876 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1877 from google import pubsub_v1 

1878 

1879 async def sample_create_snapshot(): 

1880 # Create a client 

1881 client = pubsub_v1.SubscriberAsyncClient() 

1882 

1883 # Initialize request argument(s) 

1884 request = pubsub_v1.CreateSnapshotRequest( 

1885 name="name_value", 

1886 subscription="subscription_value", 

1887 ) 

1888 

1889 # Make the request 

1890 response = await client.create_snapshot(request=request) 

1891 

1892 # Handle the response 

1893 print(response) 

1894 

1895 Args: 

1896 request (Optional[Union[google.pubsub_v1.types.CreateSnapshotRequest, dict]]): 

1897 The request object. Request for the ``CreateSnapshot`` method. 

1898 name (:class:`str`): 

1899 Required. User-provided name for this snapshot. If the 

1900 name is not provided in the request, the server will 

1901 assign a random name for this snapshot on the same 

1902 project as the subscription. Note that for REST API 

1903 requests, you must specify a name. See the `resource 

1904 name 

1905 rules <https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>`__. 

1906 Format is ``projects/{project}/snapshots/{snap}``. 

1907 

1908 This corresponds to the ``name`` field 

1909 on the ``request`` instance; if ``request`` is provided, this 

1910 should not be set. 

1911 subscription (:class:`str`): 

1912 Required. The subscription whose backlog the snapshot 

1913 retains. Specifically, the created snapshot is 

1914 guaranteed to retain: (a) The existing backlog on the 

1915 subscription. More precisely, this is defined as the 

1916 messages in the subscription's backlog that are 

1917 unacknowledged upon the successful completion of the 

1918 ``CreateSnapshot`` request; as well as: (b) Any messages 

1919 published to the subscription's topic following the 

1920 successful completion of the CreateSnapshot request. 

1921 Format is ``projects/{project}/subscriptions/{sub}``. 

1922 

1923 This corresponds to the ``subscription`` field 

1924 on the ``request`` instance; if ``request`` is provided, this 

1925 should not be set. 

1926 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

1927 should be retried. 

1928 timeout (float): The timeout for this request. 

1929 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1930 sent along with the request as metadata. Normally, each value must be of type `str`, 

1931 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1932 be of type `bytes`. 

1933 

1934 Returns: 

1935 google.pubsub_v1.types.Snapshot: 

1936 A snapshot resource. Snapshots are used in 

1937 [Seek](https://cloud.google.com/pubsub/docs/replay-overview) 

1938 operations, which allow you to manage message 

1939 acknowledgments in bulk. That is, you can set the 

1940 acknowledgment state of messages in an existing 

1941 subscription to the state captured by a snapshot. 

1942 

1943 """ 

1944 # Create or coerce a protobuf request object. 

1945 # - Quick check: If we got a request object, we should *not* have 

1946 # gotten any keyword arguments that map to the request. 

1947 flattened_params = [name, subscription] 

1948 has_flattened_params = ( 

1949 len([param for param in flattened_params if param is not None]) > 0 

1950 ) 

1951 if request is not None and has_flattened_params: 

1952 raise ValueError( 

1953 "If the `request` argument is set, then none of " 

1954 "the individual field arguments should be set." 

1955 ) 

1956 

1957 # - Use the request object if provided (there's no risk of modifying the input as 

1958 # there are no flattened fields), or create one. 

1959 if not isinstance(request, pubsub.CreateSnapshotRequest): 

1960 request = pubsub.CreateSnapshotRequest(request) 

1961 

1962 # If we have keyword arguments corresponding to fields on the 

1963 # request, apply these. 

1964 if name is not None: 

1965 request.name = name 

1966 if subscription is not None: 

1967 request.subscription = subscription 

1968 

1969 # Wrap the RPC method; this adds retry and timeout information, 

1970 # and friendly error handling. 

1971 rpc = self._client._transport._wrapped_methods[ 

1972 self._client._transport.create_snapshot 

1973 ] 

1974 

1975 # Certain fields should be provided within the metadata header; 

1976 # add these here. 

1977 metadata = tuple(metadata) + ( 

1978 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1979 ) 

1980 

1981 # Validate the universe domain. 

1982 self._client._validate_universe_domain() 

1983 

1984 # Send the request. 

1985 response = await rpc( 

1986 request, 

1987 retry=retry, 

1988 timeout=timeout, 

1989 metadata=metadata, 

1990 ) 

1991 

1992 # Done; return the response. 

1993 return response 

1994 

1995 async def update_snapshot( 

1996 self, 

1997 request: Optional[Union[pubsub.UpdateSnapshotRequest, dict]] = None, 

1998 *, 

1999 snapshot: Optional[pubsub.Snapshot] = None, 

2000 update_mask: Optional[field_mask_pb2.FieldMask] = None, 

2001 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2002 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

2003 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2004 ) -> pubsub.Snapshot: 

2005 r"""Updates an existing snapshot by updating the fields specified in 

2006 the update mask. Snapshots are used in 

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

2008 operations, which allow you to manage message acknowledgments in 

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

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

2011 

2012 .. code-block:: python 

2013 

2014 # This snippet has been automatically generated and should be regarded as a 

2015 # code template only. 

2016 # It will require modifications to work: 

2017 # - It may require correct/in-range values for request initialization. 

2018 # - It may require specifying regional endpoints when creating the service 

2019 # client as shown in: 

2020 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

2021 from google import pubsub_v1 

2022 

2023 async def sample_update_snapshot(): 

2024 # Create a client 

2025 client = pubsub_v1.SubscriberAsyncClient() 

2026 

2027 # Initialize request argument(s) 

2028 request = pubsub_v1.UpdateSnapshotRequest( 

2029 ) 

2030 

2031 # Make the request 

2032 response = await client.update_snapshot(request=request) 

2033 

2034 # Handle the response 

2035 print(response) 

2036 

2037 Args: 

2038 request (Optional[Union[google.pubsub_v1.types.UpdateSnapshotRequest, dict]]): 

2039 The request object. Request for the UpdateSnapshot 

2040 method. 

2041 snapshot (:class:`google.pubsub_v1.types.Snapshot`): 

2042 Required. The updated snapshot 

2043 object. 

2044 

2045 This corresponds to the ``snapshot`` field 

2046 on the ``request`` instance; if ``request`` is provided, this 

2047 should not be set. 

2048 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): 

2049 Required. Indicates which fields in 

2050 the provided snapshot to update. Must be 

2051 specified and non-empty. 

2052 

2053 This corresponds to the ``update_mask`` field 

2054 on the ``request`` instance; if ``request`` is provided, this 

2055 should not be set. 

2056 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

2057 should be retried. 

2058 timeout (float): The timeout for this request. 

2059 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2060 sent along with the request as metadata. Normally, each value must be of type `str`, 

2061 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2062 be of type `bytes`. 

2063 

2064 Returns: 

2065 google.pubsub_v1.types.Snapshot: 

2066 A snapshot resource. Snapshots are used in 

2067 [Seek](https://cloud.google.com/pubsub/docs/replay-overview) 

2068 operations, which allow you to manage message 

2069 acknowledgments in bulk. That is, you can set the 

2070 acknowledgment state of messages in an existing 

2071 subscription to the state captured by a snapshot. 

2072 

2073 """ 

2074 # Create or coerce a protobuf request object. 

2075 # - Quick check: If we got a request object, we should *not* have 

2076 # gotten any keyword arguments that map to the request. 

2077 flattened_params = [snapshot, update_mask] 

2078 has_flattened_params = ( 

2079 len([param for param in flattened_params if param is not None]) > 0 

2080 ) 

2081 if request is not None and has_flattened_params: 

2082 raise ValueError( 

2083 "If the `request` argument is set, then none of " 

2084 "the individual field arguments should be set." 

2085 ) 

2086 

2087 # - Use the request object if provided (there's no risk of modifying the input as 

2088 # there are no flattened fields), or create one. 

2089 if not isinstance(request, pubsub.UpdateSnapshotRequest): 

2090 request = pubsub.UpdateSnapshotRequest(request) 

2091 

2092 # If we have keyword arguments corresponding to fields on the 

2093 # request, apply these. 

2094 if snapshot is not None: 

2095 request.snapshot = snapshot 

2096 if update_mask is not None: 

2097 request.update_mask = update_mask 

2098 

2099 # Wrap the RPC method; this adds retry and timeout information, 

2100 # and friendly error handling. 

2101 rpc = self._client._transport._wrapped_methods[ 

2102 self._client._transport.update_snapshot 

2103 ] 

2104 

2105 # Certain fields should be provided within the metadata header; 

2106 # add these here. 

2107 metadata = tuple(metadata) + ( 

2108 gapic_v1.routing_header.to_grpc_metadata( 

2109 (("snapshot.name", request.snapshot.name),) 

2110 ), 

2111 ) 

2112 

2113 # Validate the universe domain. 

2114 self._client._validate_universe_domain() 

2115 

2116 # Send the request. 

2117 response = await rpc( 

2118 request, 

2119 retry=retry, 

2120 timeout=timeout, 

2121 metadata=metadata, 

2122 ) 

2123 

2124 # Done; return the response. 

2125 return response 

2126 

2127 async def delete_snapshot( 

2128 self, 

2129 request: Optional[Union[pubsub.DeleteSnapshotRequest, dict]] = None, 

2130 *, 

2131 snapshot: Optional[str] = None, 

2132 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2133 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

2134 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2135 ) -> None: 

2136 r"""Removes an existing snapshot. Snapshots are used in [Seek] 

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

2138 operations, which allow you to manage message acknowledgments in 

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

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

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

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

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

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

2145 the same subscription is specified. 

2146 

2147 .. code-block:: python 

2148 

2149 # This snippet has been automatically generated and should be regarded as a 

2150 # code template only. 

2151 # It will require modifications to work: 

2152 # - It may require correct/in-range values for request initialization. 

2153 # - It may require specifying regional endpoints when creating the service 

2154 # client as shown in: 

2155 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

2156 from google import pubsub_v1 

2157 

2158 async def sample_delete_snapshot(): 

2159 # Create a client 

2160 client = pubsub_v1.SubscriberAsyncClient() 

2161 

2162 # Initialize request argument(s) 

2163 request = pubsub_v1.DeleteSnapshotRequest( 

2164 snapshot="snapshot_value", 

2165 ) 

2166 

2167 # Make the request 

2168 await client.delete_snapshot(request=request) 

2169 

2170 Args: 

2171 request (Optional[Union[google.pubsub_v1.types.DeleteSnapshotRequest, dict]]): 

2172 The request object. Request for the ``DeleteSnapshot`` method. 

2173 snapshot (:class:`str`): 

2174 Required. The name of the snapshot to delete. Format is 

2175 ``projects/{project}/snapshots/{snap}``. 

2176 

2177 This corresponds to the ``snapshot`` field 

2178 on the ``request`` instance; if ``request`` is provided, this 

2179 should not be set. 

2180 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

2181 should be retried. 

2182 timeout (float): The timeout for this request. 

2183 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2184 sent along with the request as metadata. Normally, each value must be of type `str`, 

2185 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2186 be of type `bytes`. 

2187 """ 

2188 # Create or coerce a protobuf request object. 

2189 # - Quick check: If we got a request object, we should *not* have 

2190 # gotten any keyword arguments that map to the request. 

2191 flattened_params = [snapshot] 

2192 has_flattened_params = ( 

2193 len([param for param in flattened_params if param is not None]) > 0 

2194 ) 

2195 if request is not None and has_flattened_params: 

2196 raise ValueError( 

2197 "If the `request` argument is set, then none of " 

2198 "the individual field arguments should be set." 

2199 ) 

2200 

2201 # - Use the request object if provided (there's no risk of modifying the input as 

2202 # there are no flattened fields), or create one. 

2203 if not isinstance(request, pubsub.DeleteSnapshotRequest): 

2204 request = pubsub.DeleteSnapshotRequest(request) 

2205 

2206 # If we have keyword arguments corresponding to fields on the 

2207 # request, apply these. 

2208 if snapshot is not None: 

2209 request.snapshot = snapshot 

2210 

2211 # Wrap the RPC method; this adds retry and timeout information, 

2212 # and friendly error handling. 

2213 rpc = self._client._transport._wrapped_methods[ 

2214 self._client._transport.delete_snapshot 

2215 ] 

2216 

2217 # Certain fields should be provided within the metadata header; 

2218 # add these here. 

2219 metadata = tuple(metadata) + ( 

2220 gapic_v1.routing_header.to_grpc_metadata((("snapshot", request.snapshot),)), 

2221 ) 

2222 

2223 # Validate the universe domain. 

2224 self._client._validate_universe_domain() 

2225 

2226 # Send the request. 

2227 await rpc( 

2228 request, 

2229 retry=retry, 

2230 timeout=timeout, 

2231 metadata=metadata, 

2232 ) 

2233 

2234 async def seek( 

2235 self, 

2236 request: Optional[Union[pubsub.SeekRequest, dict]] = None, 

2237 *, 

2238 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2239 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

2240 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2241 ) -> pubsub.SeekResponse: 

2242 r"""Seeks an existing subscription to a point in time or to a given 

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

2244 used in [Seek] 

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

2246 operations, which allow you to manage message acknowledgments in 

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

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

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

2250 same topic. 

2251 

2252 .. code-block:: python 

2253 

2254 # This snippet has been automatically generated and should be regarded as a 

2255 # code template only. 

2256 # It will require modifications to work: 

2257 # - It may require correct/in-range values for request initialization. 

2258 # - It may require specifying regional endpoints when creating the service 

2259 # client as shown in: 

2260 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

2261 from google import pubsub_v1 

2262 

2263 async def sample_seek(): 

2264 # Create a client 

2265 client = pubsub_v1.SubscriberAsyncClient() 

2266 

2267 # Initialize request argument(s) 

2268 request = pubsub_v1.SeekRequest( 

2269 subscription="subscription_value", 

2270 ) 

2271 

2272 # Make the request 

2273 response = await client.seek(request=request) 

2274 

2275 # Handle the response 

2276 print(response) 

2277 

2278 Args: 

2279 request (Optional[Union[google.pubsub_v1.types.SeekRequest, dict]]): 

2280 The request object. Request for the ``Seek`` method. 

2281 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

2282 should be retried. 

2283 timeout (float): The timeout for this request. 

2284 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2285 sent along with the request as metadata. Normally, each value must be of type `str`, 

2286 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2287 be of type `bytes`. 

2288 

2289 Returns: 

2290 google.pubsub_v1.types.SeekResponse: 

2291 Response for the Seek method (this response is empty). 

2292 """ 

2293 # Create or coerce a protobuf request object. 

2294 # - Use the request object if provided (there's no risk of modifying the input as 

2295 # there are no flattened fields), or create one. 

2296 if not isinstance(request, pubsub.SeekRequest): 

2297 request = pubsub.SeekRequest(request) 

2298 

2299 # Wrap the RPC method; this adds retry and timeout information, 

2300 # and friendly error handling. 

2301 rpc = self._client._transport._wrapped_methods[self._client._transport.seek] 

2302 

2303 # Certain fields should be provided within the metadata header; 

2304 # add these here. 

2305 metadata = tuple(metadata) + ( 

2306 gapic_v1.routing_header.to_grpc_metadata( 

2307 (("subscription", request.subscription),) 

2308 ), 

2309 ) 

2310 

2311 # Validate the universe domain. 

2312 self._client._validate_universe_domain() 

2313 

2314 # Send the request. 

2315 response = await rpc( 

2316 request, 

2317 retry=retry, 

2318 timeout=timeout, 

2319 metadata=metadata, 

2320 ) 

2321 

2322 # Done; return the response. 

2323 return response 

2324 

2325 async def set_iam_policy( 

2326 self, 

2327 request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, 

2328 *, 

2329 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2330 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

2331 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2332 ) -> policy_pb2.Policy: 

2333 r"""Sets the IAM access control policy on the specified function. 

2334 

2335 Replaces any existing policy. 

2336 

2337 Args: 

2338 request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): 

2339 The request object. Request message for `SetIamPolicy` 

2340 method. 

2341 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

2342 should be retried. 

2343 timeout (float): The timeout for this request. 

2344 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2345 sent along with the request as metadata. Normally, each value must be of type `str`, 

2346 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2347 be of type `bytes`. 

2348 Returns: 

2349 ~.policy_pb2.Policy: 

2350 Defines an Identity and Access Management (IAM) policy. 

2351 It is used to specify access control policies for Cloud 

2352 Platform resources. 

2353 A ``Policy`` is a collection of ``bindings``. A 

2354 ``binding`` binds one or more ``members`` to a single 

2355 ``role``. Members can be user accounts, service 

2356 accounts, Google groups, and domains (such as G Suite). 

2357 A ``role`` is a named list of permissions (defined by 

2358 IAM or configured by users). A ``binding`` can 

2359 optionally specify a ``condition``, which is a logic 

2360 expression that further constrains the role binding 

2361 based on attributes about the request and/or target 

2362 resource. 

2363 

2364 **JSON Example** 

2365 

2366 :: 

2367 

2368 { 

2369 "bindings": [ 

2370 { 

2371 "role": "roles/resourcemanager.organizationAdmin", 

2372 "members": [ 

2373 "user:mike@example.com", 

2374 "group:admins@example.com", 

2375 "domain:google.com", 

2376 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

2377 ] 

2378 }, 

2379 { 

2380 "role": "roles/resourcemanager.organizationViewer", 

2381 "members": ["user:eve@example.com"], 

2382 "condition": { 

2383 "title": "expirable access", 

2384 "description": "Does not grant access after Sep 2020", 

2385 "expression": "request.time < 

2386 timestamp('2020-10-01T00:00:00.000Z')", 

2387 } 

2388 } 

2389 ] 

2390 } 

2391 

2392 **YAML Example** 

2393 

2394 :: 

2395 

2396 bindings: 

2397 - members: 

2398 - user:mike@example.com 

2399 - group:admins@example.com 

2400 - domain:google.com 

2401 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

2402 role: roles/resourcemanager.organizationAdmin 

2403 - members: 

2404 - user:eve@example.com 

2405 role: roles/resourcemanager.organizationViewer 

2406 condition: 

2407 title: expirable access 

2408 description: Does not grant access after Sep 2020 

2409 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

2410 

2411 For a description of IAM and its features, see the `IAM 

2412 developer's 

2413 guide <https://cloud.google.com/iam/docs>`__. 

2414 """ 

2415 # Create or coerce a protobuf request object. 

2416 

2417 # The request isn't a proto-plus wrapped type, 

2418 # so it must be constructed via keyword expansion. 

2419 if isinstance(request, dict): 

2420 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

2421 

2422 # Wrap the RPC method; this adds retry and timeout information, 

2423 # and friendly error handling. 

2424 rpc = self.transport._wrapped_methods[self._client._transport.set_iam_policy] 

2425 

2426 # Certain fields should be provided within the metadata header; 

2427 # add these here. 

2428 metadata = tuple(metadata) + ( 

2429 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

2430 ) 

2431 

2432 # Validate the universe domain. 

2433 self._client._validate_universe_domain() 

2434 

2435 # Send the request. 

2436 response = await rpc( 

2437 request, 

2438 retry=retry, 

2439 timeout=timeout, 

2440 metadata=metadata, 

2441 ) 

2442 

2443 # Done; return the response. 

2444 return response 

2445 

2446 async def get_iam_policy( 

2447 self, 

2448 request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, 

2449 *, 

2450 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2451 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

2452 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2453 ) -> policy_pb2.Policy: 

2454 r"""Gets the IAM access control policy for a function. 

2455 

2456 Returns an empty policy if the function exists and does not have a 

2457 policy set. 

2458 

2459 Args: 

2460 request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): 

2461 The request object. Request message for `GetIamPolicy` 

2462 method. 

2463 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if 

2464 any, should be retried. 

2465 timeout (float): The timeout for this request. 

2466 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2467 sent along with the request as metadata. Normally, each value must be of type `str`, 

2468 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2469 be of type `bytes`. 

2470 Returns: 

2471 ~.policy_pb2.Policy: 

2472 Defines an Identity and Access Management (IAM) policy. 

2473 It is used to specify access control policies for Cloud 

2474 Platform resources. 

2475 A ``Policy`` is a collection of ``bindings``. A 

2476 ``binding`` binds one or more ``members`` to a single 

2477 ``role``. Members can be user accounts, service 

2478 accounts, Google groups, and domains (such as G Suite). 

2479 A ``role`` is a named list of permissions (defined by 

2480 IAM or configured by users). A ``binding`` can 

2481 optionally specify a ``condition``, which is a logic 

2482 expression that further constrains the role binding 

2483 based on attributes about the request and/or target 

2484 resource. 

2485 

2486 **JSON Example** 

2487 

2488 :: 

2489 

2490 { 

2491 "bindings": [ 

2492 { 

2493 "role": "roles/resourcemanager.organizationAdmin", 

2494 "members": [ 

2495 "user:mike@example.com", 

2496 "group:admins@example.com", 

2497 "domain:google.com", 

2498 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

2499 ] 

2500 }, 

2501 { 

2502 "role": "roles/resourcemanager.organizationViewer", 

2503 "members": ["user:eve@example.com"], 

2504 "condition": { 

2505 "title": "expirable access", 

2506 "description": "Does not grant access after Sep 2020", 

2507 "expression": "request.time < 

2508 timestamp('2020-10-01T00:00:00.000Z')", 

2509 } 

2510 } 

2511 ] 

2512 } 

2513 

2514 **YAML Example** 

2515 

2516 :: 

2517 

2518 bindings: 

2519 - members: 

2520 - user:mike@example.com 

2521 - group:admins@example.com 

2522 - domain:google.com 

2523 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

2524 role: roles/resourcemanager.organizationAdmin 

2525 - members: 

2526 - user:eve@example.com 

2527 role: roles/resourcemanager.organizationViewer 

2528 condition: 

2529 title: expirable access 

2530 description: Does not grant access after Sep 2020 

2531 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

2532 

2533 For a description of IAM and its features, see the `IAM 

2534 developer's 

2535 guide <https://cloud.google.com/iam/docs>`__. 

2536 """ 

2537 # Create or coerce a protobuf request object. 

2538 

2539 # The request isn't a proto-plus wrapped type, 

2540 # so it must be constructed via keyword expansion. 

2541 if isinstance(request, dict): 

2542 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

2543 

2544 # Wrap the RPC method; this adds retry and timeout information, 

2545 # and friendly error handling. 

2546 rpc = self.transport._wrapped_methods[self._client._transport.get_iam_policy] 

2547 

2548 # Certain fields should be provided within the metadata header; 

2549 # add these here. 

2550 metadata = tuple(metadata) + ( 

2551 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

2552 ) 

2553 

2554 # Validate the universe domain. 

2555 self._client._validate_universe_domain() 

2556 

2557 # Send the request. 

2558 response = await rpc( 

2559 request, 

2560 retry=retry, 

2561 timeout=timeout, 

2562 metadata=metadata, 

2563 ) 

2564 

2565 # Done; return the response. 

2566 return response 

2567 

2568 async def test_iam_permissions( 

2569 self, 

2570 request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, 

2571 *, 

2572 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2573 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

2574 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2575 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

2576 r"""Tests the specified IAM permissions against the IAM access control 

2577 policy for a function. 

2578 

2579 If the function does not exist, this will return an empty set 

2580 of permissions, not a NOT_FOUND error. 

2581 

2582 Args: 

2583 request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): 

2584 The request object. Request message for 

2585 `TestIamPermissions` method. 

2586 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, 

2587 if any, should be retried. 

2588 timeout (float): The timeout for this request. 

2589 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2590 sent along with the request as metadata. Normally, each value must be of type `str`, 

2591 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2592 be of type `bytes`. 

2593 Returns: 

2594 ~.iam_policy_pb2.TestIamPermissionsResponse: 

2595 Response message for ``TestIamPermissions`` method. 

2596 """ 

2597 # Create or coerce a protobuf request object. 

2598 

2599 # The request isn't a proto-plus wrapped type, 

2600 # so it must be constructed via keyword expansion. 

2601 if isinstance(request, dict): 

2602 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

2603 

2604 # Wrap the RPC method; this adds retry and timeout information, 

2605 # and friendly error handling. 

2606 rpc = self.transport._wrapped_methods[ 

2607 self._client._transport.test_iam_permissions 

2608 ] 

2609 

2610 # Certain fields should be provided within the metadata header; 

2611 # add these here. 

2612 metadata = tuple(metadata) + ( 

2613 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

2614 ) 

2615 

2616 # Validate the universe domain. 

2617 self._client._validate_universe_domain() 

2618 

2619 # Send the request. 

2620 response = await rpc( 

2621 request, 

2622 retry=retry, 

2623 timeout=timeout, 

2624 metadata=metadata, 

2625 ) 

2626 

2627 # Done; return the response. 

2628 return response 

2629 

2630 async def __aenter__(self) -> "SubscriberAsyncClient": 

2631 return self 

2632 

2633 async def __aexit__(self, exc_type, exc, tb): 

2634 await self.transport.close() 

2635 

2636 

2637DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

2638 client_library_version=package_version.__version__ 

2639) 

2640 

2641if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

2642 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

2643 

2644 

2645__all__ = ("SubscriberAsyncClient",)