Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/pubsub_v1/services/publisher/async_client.py: 38%

187 statements  

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

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

2# Copyright 2022 Google LLC 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

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

9# 

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

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

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

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

14# limitations under the License. 

15# 

16from collections import OrderedDict 

17import functools 

18import re 

19from typing import ( 

20 Dict, 

21 Mapping, 

22 MutableMapping, 

23 MutableSequence, 

24 Optional, 

25 Sequence, 

26 Tuple, 

27 Type, 

28 Union, 

29) 

30 

31from google.pubsub_v1 import gapic_version as package_version 

32 

33from google.api_core.client_options import ClientOptions 

34from google.api_core import exceptions as core_exceptions 

35from google.api_core import gapic_v1 

36from google.api_core import retry as retries 

37from google.api_core import timeout as timeouts # type: ignore 

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

39from google.oauth2 import service_account # type: ignore 

40 

41try: 

42 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] 

43except AttributeError: # pragma: NO COVER 

44 OptionalRetry = Union[retries.Retry, object] # type: ignore 

45 

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

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

48from google.protobuf import duration_pb2 # type: ignore 

49from google.protobuf import field_mask_pb2 # type: ignore 

50from google.pubsub_v1.services.publisher import pagers 

51from google.pubsub_v1.types import pubsub 

52from google.pubsub_v1.types import TimeoutType 

53from .transports.base import PublisherTransport, DEFAULT_CLIENT_INFO 

54from .transports.grpc_asyncio import PublisherGrpcAsyncIOTransport 

55from .client import PublisherClient 

56 

57 

58class PublisherAsyncClient: 

59 """The service that an application uses to manipulate topics, 

60 and to send messages to a topic. 

61 """ 

62 

63 _client: PublisherClient 

64 

65 DEFAULT_ENDPOINT = PublisherClient.DEFAULT_ENDPOINT 

66 DEFAULT_MTLS_ENDPOINT = PublisherClient.DEFAULT_MTLS_ENDPOINT 

67 

68 schema_path = staticmethod(PublisherClient.schema_path) 

69 parse_schema_path = staticmethod(PublisherClient.parse_schema_path) 

70 subscription_path = staticmethod(PublisherClient.subscription_path) 

71 parse_subscription_path = staticmethod(PublisherClient.parse_subscription_path) 

72 topic_path = staticmethod(PublisherClient.topic_path) 

73 parse_topic_path = staticmethod(PublisherClient.parse_topic_path) 

74 common_billing_account_path = staticmethod( 

75 PublisherClient.common_billing_account_path 

76 ) 

77 parse_common_billing_account_path = staticmethod( 

78 PublisherClient.parse_common_billing_account_path 

79 ) 

80 common_folder_path = staticmethod(PublisherClient.common_folder_path) 

81 parse_common_folder_path = staticmethod(PublisherClient.parse_common_folder_path) 

82 common_organization_path = staticmethod(PublisherClient.common_organization_path) 

83 parse_common_organization_path = staticmethod( 

84 PublisherClient.parse_common_organization_path 

85 ) 

86 common_project_path = staticmethod(PublisherClient.common_project_path) 

87 parse_common_project_path = staticmethod(PublisherClient.parse_common_project_path) 

88 common_location_path = staticmethod(PublisherClient.common_location_path) 

89 parse_common_location_path = staticmethod( 

90 PublisherClient.parse_common_location_path 

91 ) 

92 

93 @classmethod 

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

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

96 info. 

97 

98 Args: 

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

100 args: Additional arguments to pass to the constructor. 

101 kwargs: Additional arguments to pass to the constructor. 

102 

103 Returns: 

104 PublisherAsyncClient: The constructed client. 

105 """ 

106 return PublisherClient.from_service_account_info.__func__(PublisherAsyncClient, info, *args, **kwargs) # type: ignore 

107 

108 @classmethod 

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

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

111 file. 

112 

113 Args: 

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

115 file. 

116 args: Additional arguments to pass to the constructor. 

117 kwargs: Additional arguments to pass to the constructor. 

118 

119 Returns: 

120 PublisherAsyncClient: The constructed client. 

121 """ 

122 return PublisherClient.from_service_account_file.__func__(PublisherAsyncClient, filename, *args, **kwargs) # type: ignore 

123 

124 from_service_account_json = from_service_account_file 

125 

126 @classmethod 

127 def get_mtls_endpoint_and_cert_source( 

128 cls, client_options: Optional[ClientOptions] = None 

129 ): 

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

131 

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

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

134 client cert source is None. 

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

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

137 source is None. 

138 

139 The API endpoint is determined in the following order: 

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

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

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

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

144 use the default API endpoint. 

145 

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

147 

148 Args: 

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

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

151 in this method. 

152 

153 Returns: 

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

155 client cert source to use. 

156 

157 Raises: 

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

159 """ 

160 return PublisherClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

161 

162 @property 

163 def transport(self) -> PublisherTransport: 

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

165 

166 Returns: 

167 PublisherTransport: The transport used by the client instance. 

168 """ 

169 return self._client.transport 

170 

171 get_transport_class = functools.partial( 

172 type(PublisherClient).get_transport_class, type(PublisherClient) 

173 ) 

174 

175 def __init__( 

176 self, 

177 *, 

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

179 transport: Union[str, PublisherTransport] = "grpc_asyncio", 

180 client_options: Optional[ClientOptions] = None, 

181 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

182 ) -> None: 

183 """Instantiates the publisher client. 

184 

185 Args: 

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

187 authorization credentials to attach to requests. These 

188 credentials identify the application to the service; if none 

189 are specified, the client will attempt to ascertain the 

190 credentials from the environment. 

191 transport (Union[str, ~.PublisherTransport]): The 

192 transport to use. If set to None, a transport is chosen 

193 automatically. 

194 client_options (ClientOptions): Custom options for the client. It 

195 won't take effect if a ``transport`` instance is provided. 

196 (1) The ``api_endpoint`` property can be used to override the 

197 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

198 environment variable can also be used to override the endpoint: 

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

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

201 default mTLS endpoint if client certificate is present, this is 

202 the default value). However, the ``api_endpoint`` property takes 

203 precedence if provided. 

204 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

206 to provide client certificate for mutual TLS transport. If 

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

208 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

209 set, no client certificate will be used. 

210 

211 Raises: 

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

213 creation failed for any reason. 

214 """ 

215 self._client = PublisherClient( 

216 credentials=credentials, 

217 transport=transport, 

218 client_options=client_options, 

219 client_info=client_info, 

220 ) 

221 

222 async def create_topic( 

223 self, 

224 request: Optional[Union[pubsub.Topic, dict]] = None, 

225 *, 

226 name: Optional[str] = None, 

227 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

228 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

229 metadata: Sequence[Tuple[str, str]] = (), 

230 ) -> pubsub.Topic: 

231 r"""Creates the given topic with the given name. See the [resource 

232 name rules] 

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

234 

235 .. code-block:: python 

236 

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

238 # code template only. 

239 # It will require modifications to work: 

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

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

242 # client as shown in: 

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

244 from google import pubsub_v1 

245 

246 async def sample_create_topic(): 

247 # Create a client 

248 client = pubsub_v1.PublisherAsyncClient() 

249 

250 # Initialize request argument(s) 

251 request = pubsub_v1.Topic( 

252 name="name_value", 

253 ) 

254 

255 # Make the request 

256 response = await client.create_topic(request=request) 

257 

258 # Handle the response 

259 print(response) 

260 

261 Args: 

262 request (Optional[Union[google.pubsub_v1.types.Topic, dict]]): 

263 The request object. A topic resource. 

264 name (:class:`str`): 

265 Required. The name of the topic. It must have the format 

266 ``"projects/{project}/topics/{topic}"``. ``{topic}`` 

267 must start with a letter, and contain only letters 

268 (``[A-Za-z]``), numbers (``[0-9]``), dashes (``-``), 

269 underscores (``_``), periods (``.``), tildes (``~``), 

270 plus (``+``) or percent signs (``%``). It must be 

271 between 3 and 255 characters in length, and it must not 

272 start with ``"goog"``. 

273 

274 This corresponds to the ``name`` field 

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

276 should not be set. 

277 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

278 should be retried. 

279 timeout (TimeoutType): 

280 The timeout for this request. 

281 metadata (Sequence[Tuple[str, str]]): Strings which should be 

282 sent along with the request as metadata. 

283 

284 Returns: 

285 google.pubsub_v1.types.Topic: 

286 A topic resource. 

287 """ 

288 # Create or coerce a protobuf request object. 

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

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

291 has_flattened_params = any([name]) 

292 if request is not None and has_flattened_params: 

293 raise ValueError( 

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

295 "the individual field arguments should be set." 

296 ) 

297 

298 request = pubsub.Topic(request) 

299 

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

301 # request, apply these. 

302 if name is not None: 

303 request.name = name 

304 

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

306 # and friendly error handling. 

307 rpc = gapic_v1.method_async.wrap_method( 

308 self._client._transport.create_topic, 

309 default_retry=retries.Retry( 

310 initial=0.1, 

311 maximum=60.0, 

312 multiplier=1.3, 

313 predicate=retries.if_exception_type( 

314 core_exceptions.ServiceUnavailable, 

315 ), 

316 deadline=60.0, 

317 ), 

318 default_timeout=60.0, 

319 client_info=DEFAULT_CLIENT_INFO, 

320 ) 

321 

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

323 # add these here. 

324 metadata = tuple(metadata) + ( 

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

326 ) 

327 

328 # Send the request. 

329 response = await rpc( 

330 request, 

331 retry=retry, 

332 timeout=timeout, 

333 metadata=metadata, 

334 ) 

335 

336 # Done; return the response. 

337 return response 

338 

339 async def update_topic( 

340 self, 

341 request: Optional[Union[pubsub.UpdateTopicRequest, dict]] = None, 

342 *, 

343 topic: Optional[pubsub.Topic] = None, 

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

345 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

346 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

347 metadata: Sequence[Tuple[str, str]] = (), 

348 ) -> pubsub.Topic: 

349 r"""Updates an existing topic. Note that certain 

350 properties of a topic are not modifiable. 

351 

352 .. code-block:: python 

353 

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

355 # code template only. 

356 # It will require modifications to work: 

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

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

359 # client as shown in: 

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

361 from google import pubsub_v1 

362 

363 async def sample_update_topic(): 

364 # Create a client 

365 client = pubsub_v1.PublisherAsyncClient() 

366 

367 # Initialize request argument(s) 

368 topic = pubsub_v1.Topic() 

369 topic.name = "name_value" 

370 

371 request = pubsub_v1.UpdateTopicRequest( 

372 topic=topic, 

373 ) 

374 

375 # Make the request 

376 response = await client.update_topic(request=request) 

377 

378 # Handle the response 

379 print(response) 

380 

381 Args: 

382 request (Optional[Union[google.pubsub_v1.types.UpdateTopicRequest, dict]]): 

383 The request object. Request for the UpdateTopic method. 

384 topic (:class:`google.pubsub_v1.types.Topic`): 

385 Required. The updated topic object. 

386 This corresponds to the ``topic`` field 

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

388 should not be set. 

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

390 Required. Indicates which fields in the provided topic 

391 to update. Must be specified and non-empty. Note that if 

392 ``update_mask`` contains "message_storage_policy" but 

393 the ``message_storage_policy`` is not set in the 

394 ``topic`` provided above, then the updated value is 

395 determined by the policy configured at the project or 

396 organization level. 

397 

398 This corresponds to the ``update_mask`` field 

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

400 should not be set. 

401 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

402 should be retried. 

403 timeout (TimeoutType): 

404 The timeout for this request. 

405 metadata (Sequence[Tuple[str, str]]): Strings which should be 

406 sent along with the request as metadata. 

407 

408 Returns: 

409 google.pubsub_v1.types.Topic: 

410 A topic resource. 

411 """ 

412 # Create or coerce a protobuf request object. 

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

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

415 has_flattened_params = any([topic, update_mask]) 

416 if request is not None and has_flattened_params: 

417 raise ValueError( 

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

419 "the individual field arguments should be set." 

420 ) 

421 

422 request = pubsub.UpdateTopicRequest(request) 

423 

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

425 # request, apply these. 

426 if topic is not None: 

427 request.topic = topic 

428 if update_mask is not None: 

429 request.update_mask = update_mask 

430 

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

432 # and friendly error handling. 

433 rpc = gapic_v1.method_async.wrap_method( 

434 self._client._transport.update_topic, 

435 default_retry=retries.Retry( 

436 initial=0.1, 

437 maximum=60.0, 

438 multiplier=1.3, 

439 predicate=retries.if_exception_type( 

440 core_exceptions.ServiceUnavailable, 

441 ), 

442 deadline=60.0, 

443 ), 

444 default_timeout=60.0, 

445 client_info=DEFAULT_CLIENT_INFO, 

446 ) 

447 

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

449 # add these here. 

450 metadata = tuple(metadata) + ( 

451 gapic_v1.routing_header.to_grpc_metadata( 

452 (("topic.name", request.topic.name),) 

453 ), 

454 ) 

455 

456 # Send the request. 

457 response = await rpc( 

458 request, 

459 retry=retry, 

460 timeout=timeout, 

461 metadata=metadata, 

462 ) 

463 

464 # Done; return the response. 

465 return response 

466 

467 async def publish( 

468 self, 

469 request: Optional[Union[pubsub.PublishRequest, dict]] = None, 

470 *, 

471 topic: Optional[str] = None, 

472 messages: Optional[MutableSequence[pubsub.PubsubMessage]] = None, 

473 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

474 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

475 metadata: Sequence[Tuple[str, str]] = (), 

476 ) -> pubsub.PublishResponse: 

477 r"""Adds one or more messages to the topic. Returns ``NOT_FOUND`` if 

478 the topic does not exist. 

479 

480 .. code-block:: python 

481 

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

483 # code template only. 

484 # It will require modifications to work: 

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

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

487 # client as shown in: 

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

489 from google import pubsub_v1 

490 

491 async def sample_publish(): 

492 # Create a client 

493 client = pubsub_v1.PublisherAsyncClient() 

494 

495 # Initialize request argument(s) 

496 request = pubsub_v1.PublishRequest( 

497 topic="topic_value", 

498 ) 

499 

500 # Make the request 

501 response = await client.publish(request=request) 

502 

503 # Handle the response 

504 print(response) 

505 

506 Args: 

507 request (Optional[Union[google.pubsub_v1.types.PublishRequest, dict]]): 

508 The request object. Request for the Publish method. 

509 topic (:class:`str`): 

510 Required. The messages in the request will be published 

511 on this topic. Format is 

512 ``projects/{project}/topics/{topic}``. 

513 

514 This corresponds to the ``topic`` field 

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

516 should not be set. 

517 messages (:class:`MutableSequence[google.pubsub_v1.types.PubsubMessage]`): 

518 Required. The messages to publish. 

519 This corresponds to the ``messages`` field 

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

521 should not be set. 

522 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

523 should be retried. 

524 timeout (TimeoutType): 

525 The timeout for this request. 

526 metadata (Sequence[Tuple[str, str]]): Strings which should be 

527 sent along with the request as metadata. 

528 

529 Returns: 

530 google.pubsub_v1.types.PublishResponse: 

531 Response for the Publish method. 

532 """ 

533 # Create or coerce a protobuf request object. 

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

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

536 has_flattened_params = any([topic, messages]) 

537 if request is not None and has_flattened_params: 

538 raise ValueError( 

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

540 "the individual field arguments should be set." 

541 ) 

542 

543 request = pubsub.PublishRequest(request) 

544 

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

546 # request, apply these. 

547 if topic is not None: 

548 request.topic = topic 

549 if messages: 

550 request.messages.extend(messages) 

551 

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

553 # and friendly error handling. 

554 rpc = gapic_v1.method_async.wrap_method( 

555 self._client._transport.publish, 

556 default_retry=retries.Retry( 

557 initial=0.1, 

558 maximum=60.0, 

559 multiplier=1.3, 

560 predicate=retries.if_exception_type( 

561 core_exceptions.Aborted, 

562 core_exceptions.Cancelled, 

563 core_exceptions.DeadlineExceeded, 

564 core_exceptions.InternalServerError, 

565 core_exceptions.ResourceExhausted, 

566 core_exceptions.ServiceUnavailable, 

567 core_exceptions.Unknown, 

568 ), 

569 deadline=60.0, 

570 ), 

571 default_timeout=60.0, 

572 client_info=DEFAULT_CLIENT_INFO, 

573 ) 

574 

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

576 # add these here. 

577 metadata = tuple(metadata) + ( 

578 gapic_v1.routing_header.to_grpc_metadata((("topic", request.topic),)), 

579 ) 

580 

581 # Send the request. 

582 response = await rpc( 

583 request, 

584 retry=retry, 

585 timeout=timeout, 

586 metadata=metadata, 

587 ) 

588 

589 # Done; return the response. 

590 return response 

591 

592 async def get_topic( 

593 self, 

594 request: Optional[Union[pubsub.GetTopicRequest, dict]] = None, 

595 *, 

596 topic: Optional[str] = None, 

597 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

598 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

599 metadata: Sequence[Tuple[str, str]] = (), 

600 ) -> pubsub.Topic: 

601 r"""Gets the configuration of a topic. 

602 

603 .. code-block:: python 

604 

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

606 # code template only. 

607 # It will require modifications to work: 

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

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

610 # client as shown in: 

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

612 from google import pubsub_v1 

613 

614 async def sample_get_topic(): 

615 # Create a client 

616 client = pubsub_v1.PublisherAsyncClient() 

617 

618 # Initialize request argument(s) 

619 request = pubsub_v1.GetTopicRequest( 

620 topic="topic_value", 

621 ) 

622 

623 # Make the request 

624 response = await client.get_topic(request=request) 

625 

626 # Handle the response 

627 print(response) 

628 

629 Args: 

630 request (Optional[Union[google.pubsub_v1.types.GetTopicRequest, dict]]): 

631 The request object. Request for the GetTopic method. 

632 topic (:class:`str`): 

633 Required. The name of the topic to get. Format is 

634 ``projects/{project}/topics/{topic}``. 

635 

636 This corresponds to the ``topic`` field 

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

638 should not be set. 

639 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

640 should be retried. 

641 timeout (TimeoutType): 

642 The timeout for this request. 

643 metadata (Sequence[Tuple[str, str]]): Strings which should be 

644 sent along with the request as metadata. 

645 

646 Returns: 

647 google.pubsub_v1.types.Topic: 

648 A topic resource. 

649 """ 

650 # Create or coerce a protobuf request object. 

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

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

653 has_flattened_params = any([topic]) 

654 if request is not None and has_flattened_params: 

655 raise ValueError( 

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

657 "the individual field arguments should be set." 

658 ) 

659 

660 request = pubsub.GetTopicRequest(request) 

661 

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

663 # request, apply these. 

664 if topic is not None: 

665 request.topic = topic 

666 

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

668 # and friendly error handling. 

669 rpc = gapic_v1.method_async.wrap_method( 

670 self._client._transport.get_topic, 

671 default_retry=retries.Retry( 

672 initial=0.1, 

673 maximum=60.0, 

674 multiplier=1.3, 

675 predicate=retries.if_exception_type( 

676 core_exceptions.Aborted, 

677 core_exceptions.ServiceUnavailable, 

678 core_exceptions.Unknown, 

679 ), 

680 deadline=60.0, 

681 ), 

682 default_timeout=60.0, 

683 client_info=DEFAULT_CLIENT_INFO, 

684 ) 

685 

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

687 # add these here. 

688 metadata = tuple(metadata) + ( 

689 gapic_v1.routing_header.to_grpc_metadata((("topic", request.topic),)), 

690 ) 

691 

692 # Send the request. 

693 response = await rpc( 

694 request, 

695 retry=retry, 

696 timeout=timeout, 

697 metadata=metadata, 

698 ) 

699 

700 # Done; return the response. 

701 return response 

702 

703 async def list_topics( 

704 self, 

705 request: Optional[Union[pubsub.ListTopicsRequest, dict]] = None, 

706 *, 

707 project: Optional[str] = None, 

708 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

709 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

710 metadata: Sequence[Tuple[str, str]] = (), 

711 ) -> pagers.ListTopicsAsyncPager: 

712 r"""Lists matching topics. 

713 

714 .. code-block:: python 

715 

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

717 # code template only. 

718 # It will require modifications to work: 

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

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

721 # client as shown in: 

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

723 from google import pubsub_v1 

724 

725 async def sample_list_topics(): 

726 # Create a client 

727 client = pubsub_v1.PublisherAsyncClient() 

728 

729 # Initialize request argument(s) 

730 request = pubsub_v1.ListTopicsRequest( 

731 project="project_value", 

732 ) 

733 

734 # Make the request 

735 page_result = client.list_topics(request=request) 

736 

737 # Handle the response 

738 async for response in page_result: 

739 print(response) 

740 

741 Args: 

742 request (Optional[Union[google.pubsub_v1.types.ListTopicsRequest, dict]]): 

743 The request object. Request for the ``ListTopics`` method. 

744 project (:class:`str`): 

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

746 topics. Format is ``projects/{project-id}``. 

747 

748 This corresponds to the ``project`` field 

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

750 should not be set. 

751 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

752 should be retried. 

753 timeout (TimeoutType): 

754 The timeout for this request. 

755 metadata (Sequence[Tuple[str, str]]): Strings which should be 

756 sent along with the request as metadata. 

757 

758 Returns: 

759 google.pubsub_v1.services.publisher.pagers.ListTopicsAsyncPager: 

760 Response for the ListTopics method. 

761 

762 Iterating over this object will yield results and 

763 resolve additional pages automatically. 

764 

765 """ 

766 # Create or coerce a protobuf request object. 

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

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

769 has_flattened_params = any([project]) 

770 if request is not None and has_flattened_params: 

771 raise ValueError( 

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

773 "the individual field arguments should be set." 

774 ) 

775 

776 request = pubsub.ListTopicsRequest(request) 

777 

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

779 # request, apply these. 

780 if project is not None: 

781 request.project = project 

782 

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

784 # and friendly error handling. 

785 rpc = gapic_v1.method_async.wrap_method( 

786 self._client._transport.list_topics, 

787 default_retry=retries.Retry( 

788 initial=0.1, 

789 maximum=60.0, 

790 multiplier=1.3, 

791 predicate=retries.if_exception_type( 

792 core_exceptions.Aborted, 

793 core_exceptions.ServiceUnavailable, 

794 core_exceptions.Unknown, 

795 ), 

796 deadline=60.0, 

797 ), 

798 default_timeout=60.0, 

799 client_info=DEFAULT_CLIENT_INFO, 

800 ) 

801 

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

803 # add these here. 

804 metadata = tuple(metadata) + ( 

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

806 ) 

807 

808 # Send the request. 

809 response = await rpc( 

810 request, 

811 retry=retry, 

812 timeout=timeout, 

813 metadata=metadata, 

814 ) 

815 

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

817 # an `__aiter__` convenience method. 

818 response = pagers.ListTopicsAsyncPager( 

819 method=rpc, 

820 request=request, 

821 response=response, 

822 metadata=metadata, 

823 ) 

824 

825 # Done; return the response. 

826 return response 

827 

828 async def list_topic_subscriptions( 

829 self, 

830 request: Optional[Union[pubsub.ListTopicSubscriptionsRequest, dict]] = None, 

831 *, 

832 topic: Optional[str] = None, 

833 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

834 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

835 metadata: Sequence[Tuple[str, str]] = (), 

836 ) -> pagers.ListTopicSubscriptionsAsyncPager: 

837 r"""Lists the names of the attached subscriptions on this 

838 topic. 

839 

840 .. code-block:: python 

841 

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

843 # code template only. 

844 # It will require modifications to work: 

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

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

847 # client as shown in: 

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

849 from google import pubsub_v1 

850 

851 async def sample_list_topic_subscriptions(): 

852 # Create a client 

853 client = pubsub_v1.PublisherAsyncClient() 

854 

855 # Initialize request argument(s) 

856 request = pubsub_v1.ListTopicSubscriptionsRequest( 

857 topic="topic_value", 

858 ) 

859 

860 # Make the request 

861 page_result = client.list_topic_subscriptions(request=request) 

862 

863 # Handle the response 

864 async for response in page_result: 

865 print(response) 

866 

867 Args: 

868 request (Optional[Union[google.pubsub_v1.types.ListTopicSubscriptionsRequest, dict]]): 

869 The request object. Request for the ``ListTopicSubscriptions`` method. 

870 topic (:class:`str`): 

871 Required. The name of the topic that subscriptions are 

872 attached to. Format is 

873 ``projects/{project}/topics/{topic}``. 

874 

875 This corresponds to the ``topic`` field 

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

877 should not be set. 

878 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

879 should be retried. 

880 timeout (TimeoutType): 

881 The timeout for this request. 

882 metadata (Sequence[Tuple[str, str]]): Strings which should be 

883 sent along with the request as metadata. 

884 

885 Returns: 

886 google.pubsub_v1.services.publisher.pagers.ListTopicSubscriptionsAsyncPager: 

887 Response for the ListTopicSubscriptions method. 

888 

889 Iterating over this object will yield results and 

890 resolve additional pages automatically. 

891 

892 """ 

893 # Create or coerce a protobuf request object. 

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

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

896 has_flattened_params = any([topic]) 

897 if request is not None and has_flattened_params: 

898 raise ValueError( 

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

900 "the individual field arguments should be set." 

901 ) 

902 

903 request = pubsub.ListTopicSubscriptionsRequest(request) 

904 

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

906 # request, apply these. 

907 if topic is not None: 

908 request.topic = topic 

909 

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

911 # and friendly error handling. 

912 rpc = gapic_v1.method_async.wrap_method( 

913 self._client._transport.list_topic_subscriptions, 

914 default_retry=retries.Retry( 

915 initial=0.1, 

916 maximum=60.0, 

917 multiplier=1.3, 

918 predicate=retries.if_exception_type( 

919 core_exceptions.Aborted, 

920 core_exceptions.ServiceUnavailable, 

921 core_exceptions.Unknown, 

922 ), 

923 deadline=60.0, 

924 ), 

925 default_timeout=60.0, 

926 client_info=DEFAULT_CLIENT_INFO, 

927 ) 

928 

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

930 # add these here. 

931 metadata = tuple(metadata) + ( 

932 gapic_v1.routing_header.to_grpc_metadata((("topic", request.topic),)), 

933 ) 

934 

935 # Send the request. 

936 response = await rpc( 

937 request, 

938 retry=retry, 

939 timeout=timeout, 

940 metadata=metadata, 

941 ) 

942 

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

944 # an `__aiter__` convenience method. 

945 response = pagers.ListTopicSubscriptionsAsyncPager( 

946 method=rpc, 

947 request=request, 

948 response=response, 

949 metadata=metadata, 

950 ) 

951 

952 # Done; return the response. 

953 return response 

954 

955 async def list_topic_snapshots( 

956 self, 

957 request: Optional[Union[pubsub.ListTopicSnapshotsRequest, dict]] = None, 

958 *, 

959 topic: Optional[str] = None, 

960 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

961 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

962 metadata: Sequence[Tuple[str, str]] = (), 

963 ) -> pagers.ListTopicSnapshotsAsyncPager: 

964 r"""Lists the names of the snapshots on this topic. Snapshots are 

965 used in 

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

967 operations, which allow you to manage message acknowledgments in 

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

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

970 

971 .. code-block:: python 

972 

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

974 # code template only. 

975 # It will require modifications to work: 

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

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

978 # client as shown in: 

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

980 from google import pubsub_v1 

981 

982 async def sample_list_topic_snapshots(): 

983 # Create a client 

984 client = pubsub_v1.PublisherAsyncClient() 

985 

986 # Initialize request argument(s) 

987 request = pubsub_v1.ListTopicSnapshotsRequest( 

988 topic="topic_value", 

989 ) 

990 

991 # Make the request 

992 page_result = client.list_topic_snapshots(request=request) 

993 

994 # Handle the response 

995 async for response in page_result: 

996 print(response) 

997 

998 Args: 

999 request (Optional[Union[google.pubsub_v1.types.ListTopicSnapshotsRequest, dict]]): 

1000 The request object. Request for the ``ListTopicSnapshots`` method. 

1001 topic (:class:`str`): 

1002 Required. The name of the topic that snapshots are 

1003 attached to. Format is 

1004 ``projects/{project}/topics/{topic}``. 

1005 

1006 This corresponds to the ``topic`` field 

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

1008 should not be set. 

1009 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1010 should be retried. 

1011 timeout (TimeoutType): 

1012 The timeout for this request. 

1013 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1014 sent along with the request as metadata. 

1015 

1016 Returns: 

1017 google.pubsub_v1.services.publisher.pagers.ListTopicSnapshotsAsyncPager: 

1018 Response for the ListTopicSnapshots method. 

1019 

1020 Iterating over this object will yield results and 

1021 resolve additional pages automatically. 

1022 

1023 """ 

1024 # Create or coerce a protobuf request object. 

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

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

1027 has_flattened_params = any([topic]) 

1028 if request is not None and has_flattened_params: 

1029 raise ValueError( 

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

1031 "the individual field arguments should be set." 

1032 ) 

1033 

1034 request = pubsub.ListTopicSnapshotsRequest(request) 

1035 

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

1037 # request, apply these. 

1038 if topic is not None: 

1039 request.topic = topic 

1040 

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

1042 # and friendly error handling. 

1043 rpc = gapic_v1.method_async.wrap_method( 

1044 self._client._transport.list_topic_snapshots, 

1045 default_retry=retries.Retry( 

1046 initial=0.1, 

1047 maximum=60.0, 

1048 multiplier=1.3, 

1049 predicate=retries.if_exception_type( 

1050 core_exceptions.Aborted, 

1051 core_exceptions.ServiceUnavailable, 

1052 core_exceptions.Unknown, 

1053 ), 

1054 deadline=60.0, 

1055 ), 

1056 default_timeout=60.0, 

1057 client_info=DEFAULT_CLIENT_INFO, 

1058 ) 

1059 

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

1061 # add these here. 

1062 metadata = tuple(metadata) + ( 

1063 gapic_v1.routing_header.to_grpc_metadata((("topic", request.topic),)), 

1064 ) 

1065 

1066 # Send the request. 

1067 response = await rpc( 

1068 request, 

1069 retry=retry, 

1070 timeout=timeout, 

1071 metadata=metadata, 

1072 ) 

1073 

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

1075 # an `__aiter__` convenience method. 

1076 response = pagers.ListTopicSnapshotsAsyncPager( 

1077 method=rpc, 

1078 request=request, 

1079 response=response, 

1080 metadata=metadata, 

1081 ) 

1082 

1083 # Done; return the response. 

1084 return response 

1085 

1086 async def delete_topic( 

1087 self, 

1088 request: Optional[Union[pubsub.DeleteTopicRequest, dict]] = None, 

1089 *, 

1090 topic: Optional[str] = None, 

1091 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1092 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

1093 metadata: Sequence[Tuple[str, str]] = (), 

1094 ) -> None: 

1095 r"""Deletes the topic with the given name. Returns ``NOT_FOUND`` if 

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

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

1098 with none of the old configuration or subscriptions. Existing 

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

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

1101 

1102 .. code-block:: python 

1103 

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

1105 # code template only. 

1106 # It will require modifications to work: 

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

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

1109 # client as shown in: 

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

1111 from google import pubsub_v1 

1112 

1113 async def sample_delete_topic(): 

1114 # Create a client 

1115 client = pubsub_v1.PublisherAsyncClient() 

1116 

1117 # Initialize request argument(s) 

1118 request = pubsub_v1.DeleteTopicRequest( 

1119 topic="topic_value", 

1120 ) 

1121 

1122 # Make the request 

1123 await client.delete_topic(request=request) 

1124 

1125 Args: 

1126 request (Optional[Union[google.pubsub_v1.types.DeleteTopicRequest, dict]]): 

1127 The request object. Request for the ``DeleteTopic`` method. 

1128 topic (:class:`str`): 

1129 Required. Name of the topic to delete. Format is 

1130 ``projects/{project}/topics/{topic}``. 

1131 

1132 This corresponds to the ``topic`` field 

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

1134 should not be set. 

1135 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1136 should be retried. 

1137 timeout (TimeoutType): 

1138 The timeout for this request. 

1139 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1140 sent along with the request as metadata. 

1141 """ 

1142 # Create or coerce a protobuf request object. 

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

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

1145 has_flattened_params = any([topic]) 

1146 if request is not None and has_flattened_params: 

1147 raise ValueError( 

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

1149 "the individual field arguments should be set." 

1150 ) 

1151 

1152 request = pubsub.DeleteTopicRequest(request) 

1153 

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

1155 # request, apply these. 

1156 if topic is not None: 

1157 request.topic = topic 

1158 

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

1160 # and friendly error handling. 

1161 rpc = gapic_v1.method_async.wrap_method( 

1162 self._client._transport.delete_topic, 

1163 default_retry=retries.Retry( 

1164 initial=0.1, 

1165 maximum=60.0, 

1166 multiplier=1.3, 

1167 predicate=retries.if_exception_type( 

1168 core_exceptions.ServiceUnavailable, 

1169 ), 

1170 deadline=60.0, 

1171 ), 

1172 default_timeout=60.0, 

1173 client_info=DEFAULT_CLIENT_INFO, 

1174 ) 

1175 

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

1177 # add these here. 

1178 metadata = tuple(metadata) + ( 

1179 gapic_v1.routing_header.to_grpc_metadata((("topic", request.topic),)), 

1180 ) 

1181 

1182 # Send the request. 

1183 await rpc( 

1184 request, 

1185 retry=retry, 

1186 timeout=timeout, 

1187 metadata=metadata, 

1188 ) 

1189 

1190 async def detach_subscription( 

1191 self, 

1192 request: Optional[Union[pubsub.DetachSubscriptionRequest, dict]] = None, 

1193 *, 

1194 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1195 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

1196 metadata: Sequence[Tuple[str, str]] = (), 

1197 ) -> pubsub.DetachSubscriptionResponse: 

1198 r"""Detaches a subscription from this topic. All messages retained 

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

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

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

1202 will stop. 

1203 

1204 .. code-block:: python 

1205 

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

1207 # code template only. 

1208 # It will require modifications to work: 

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

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

1211 # client as shown in: 

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

1213 from google import pubsub_v1 

1214 

1215 async def sample_detach_subscription(): 

1216 # Create a client 

1217 client = pubsub_v1.PublisherAsyncClient() 

1218 

1219 # Initialize request argument(s) 

1220 request = pubsub_v1.DetachSubscriptionRequest( 

1221 subscription="subscription_value", 

1222 ) 

1223 

1224 # Make the request 

1225 response = await client.detach_subscription(request=request) 

1226 

1227 # Handle the response 

1228 print(response) 

1229 

1230 Args: 

1231 request (Optional[Union[google.pubsub_v1.types.DetachSubscriptionRequest, dict]]): 

1232 The request object. Request for the DetachSubscription 

1233 method. 

1234 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1235 should be retried. 

1236 timeout (TimeoutType): 

1237 The timeout for this request. 

1238 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1239 sent along with the request as metadata. 

1240 

1241 Returns: 

1242 google.pubsub_v1.types.DetachSubscriptionResponse: 

1243 Response for the DetachSubscription 

1244 method. Reserved for future use. 

1245 

1246 """ 

1247 # Create or coerce a protobuf request object. 

1248 request = pubsub.DetachSubscriptionRequest(request) 

1249 

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

1251 # and friendly error handling. 

1252 rpc = gapic_v1.method_async.wrap_method( 

1253 self._client._transport.detach_subscription, 

1254 default_retry=retries.Retry( 

1255 initial=0.1, 

1256 maximum=60.0, 

1257 multiplier=1.3, 

1258 predicate=retries.if_exception_type( 

1259 core_exceptions.ServiceUnavailable, 

1260 ), 

1261 deadline=60.0, 

1262 ), 

1263 default_timeout=60.0, 

1264 client_info=DEFAULT_CLIENT_INFO, 

1265 ) 

1266 

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

1268 # add these here. 

1269 metadata = tuple(metadata) + ( 

1270 gapic_v1.routing_header.to_grpc_metadata( 

1271 (("subscription", request.subscription),) 

1272 ), 

1273 ) 

1274 

1275 # Send the request. 

1276 response = await rpc( 

1277 request, 

1278 retry=retry, 

1279 timeout=timeout, 

1280 metadata=metadata, 

1281 ) 

1282 

1283 # Done; return the response. 

1284 return response 

1285 

1286 async def set_iam_policy( 

1287 self, 

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

1289 *, 

1290 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1291 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

1292 metadata: Sequence[Tuple[str, str]] = (), 

1293 ) -> policy_pb2.Policy: 

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

1295 

1296 Replaces any existing policy. 

1297 

1298 Args: 

1299 request (:class:`~.policy_pb2.SetIamPolicyRequest`): 

1300 The request object. Request message for `SetIamPolicy` 

1301 method. 

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

1303 should be retried. 

1304 timeout (TimeoutType): 

1305 The timeout for this request. 

1306 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1307 sent along with the request as metadata. 

1308 Returns: 

1309 ~.policy_pb2.Policy: 

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

1311 It is used to specify access control policies for Cloud 

1312 Platform resources. 

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

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

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

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

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

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

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

1320 expression that further constrains the role binding 

1321 based on attributes about the request and/or target 

1322 resource. 

1323 

1324 **JSON Example** 

1325 

1326 :: 

1327 { 

1328 "bindings": [ 

1329 { 

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

1331 "members": [ 

1332 "user:mike@example.com", 

1333 "group:admins@example.com", 

1334 "domain:google.com", 

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

1336 ] 

1337 }, 

1338 { 

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

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

1341 "condition": { 

1342 "title": "expirable access", 

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

1344 "expression": "request.time < 

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

1346 } 

1347 } 

1348 ] 

1349 } 

1350 

1351 **YAML Example** 

1352 

1353 :: 

1354 

1355 bindings: 

1356 - members: 

1357 - user:mike@example.com 

1358 - group:admins@example.com 

1359 - domain:google.com 

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

1361 role: roles/resourcemanager.organizationAdmin 

1362 - members: 

1363 - user:eve@example.com 

1364 role: roles/resourcemanager.organizationViewer 

1365 condition: 

1366 title: expirable access 

1367 description: Does not grant access after Sep 2020 

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

1369 

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

1371 developer's 

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

1373 """ 

1374 # Create or coerce a protobuf request object. 

1375 

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

1377 # so it must be constructed via keyword expansion. 

1378 if isinstance(request, dict): 

1379 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1380 

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

1382 # and friendly error handling. 

1383 rpc = gapic_v1.method_async.wrap_method( 

1384 self._client._transport.set_iam_policy, 

1385 default_timeout=None, 

1386 client_info=DEFAULT_CLIENT_INFO, 

1387 ) 

1388 

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

1390 # add these here. 

1391 metadata = tuple(metadata) + ( 

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

1393 ) 

1394 

1395 # Send the request. 

1396 response = await rpc( 

1397 request, 

1398 retry=retry, 

1399 timeout=timeout, 

1400 metadata=metadata, 

1401 ) 

1402 

1403 # Done; return the response. 

1404 return response 

1405 

1406 async def get_iam_policy( 

1407 self, 

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

1409 *, 

1410 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1411 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

1412 metadata: Sequence[Tuple[str, str]] = (), 

1413 ) -> policy_pb2.Policy: 

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

1415 

1416 Returns an empty policy if the function exists and does 

1417 not have a policy set. 

1418 

1419 Args: 

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

1421 The request object. Request message for `GetIamPolicy` 

1422 method. 

1423 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1424 should be retried. 

1425 timeout (TimeoutType): 

1426 The timeout for this request. 

1427 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1428 sent along with the request as metadata. 

1429 Returns: 

1430 ~.policy_pb2.Policy: 

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

1432 It is used to specify access control policies for Cloud 

1433 Platform resources. 

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

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

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

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

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

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

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

1441 expression that further constrains the role binding 

1442 based on attributes about the request and/or target 

1443 resource. 

1444 

1445 **JSON Example** 

1446 

1447 :: 

1448 

1449 { 

1450 "bindings": [ 

1451 { 

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

1453 "members": [ 

1454 "user:mike@example.com", 

1455 "group:admins@example.com", 

1456 "domain:google.com", 

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

1458 ] 

1459 }, 

1460 { 

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

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

1463 "condition": { 

1464 "title": "expirable access", 

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

1466 "expression": "request.time < 

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

1468 } 

1469 } 

1470 ] 

1471 } 

1472 

1473 **YAML Example** 

1474 

1475 :: 

1476 

1477 bindings: 

1478 - members: 

1479 - user:mike@example.com 

1480 - group:admins@example.com 

1481 - domain:google.com 

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

1483 role: roles/resourcemanager.organizationAdmin 

1484 - members: 

1485 - user:eve@example.com 

1486 role: roles/resourcemanager.organizationViewer 

1487 condition: 

1488 title: expirable access 

1489 description: Does not grant access after Sep 2020 

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

1491 

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

1493 developer's 

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

1495 """ 

1496 # Create or coerce a protobuf request object. 

1497 

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

1499 # so it must be constructed via keyword expansion. 

1500 if isinstance(request, dict): 

1501 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1502 

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

1504 # and friendly error handling. 

1505 rpc = gapic_v1.method_async.wrap_method( 

1506 self._client._transport.get_iam_policy, 

1507 default_timeout=None, 

1508 client_info=DEFAULT_CLIENT_INFO, 

1509 ) 

1510 

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

1512 # add these here. 

1513 metadata = tuple(metadata) + ( 

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

1515 ) 

1516 

1517 # Send the request. 

1518 response = await rpc( 

1519 request, 

1520 retry=retry, 

1521 timeout=timeout, 

1522 metadata=metadata, 

1523 ) 

1524 

1525 # Done; return the response. 

1526 return response 

1527 

1528 async def test_iam_permissions( 

1529 self, 

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

1531 *, 

1532 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1533 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

1534 metadata: Sequence[Tuple[str, str]] = (), 

1535 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

1537 policy for a function. 

1538 

1539 If the function does not exist, this will 

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

1541 

1542 Args: 

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

1544 The request object. Request message for 

1545 `TestIamPermissions` method. 

1546 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1547 should be retried. 

1548 timeout (TimeoutType): 

1549 The timeout for this request. 

1550 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1551 sent along with the request as metadata. 

1552 Returns: 

1553 ~iam_policy_pb2.PolicyTestIamPermissionsResponse: 

1554 Response message for ``TestIamPermissions`` method. 

1555 """ 

1556 # Create or coerce a protobuf request object. 

1557 

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

1559 # so it must be constructed via keyword expansion. 

1560 if isinstance(request, dict): 

1561 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1562 

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

1564 # and friendly error handling. 

1565 rpc = gapic_v1.method_async.wrap_method( 

1566 self._client._transport.test_iam_permissions, 

1567 default_timeout=None, 

1568 client_info=DEFAULT_CLIENT_INFO, 

1569 ) 

1570 

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

1572 # add these here. 

1573 metadata = tuple(metadata) + ( 

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

1575 ) 

1576 

1577 # Send the request. 

1578 response = await rpc( 

1579 request, 

1580 retry=retry, 

1581 timeout=timeout, 

1582 metadata=metadata, 

1583 ) 

1584 

1585 # Done; return the response. 

1586 return response 

1587 

1588 async def __aenter__(self): 

1589 return self 

1590 

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

1592 await self.transport.close() 

1593 

1594 

1595DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1596 client_library_version=package_version.__version__ 

1597) 

1598 

1599 

1600__all__ = ("PublisherAsyncClient",)