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.2, created at 2023-03-26 06:25 +0000

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

2# Copyright 2022 Google LLC 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

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

9# 

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

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

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

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

14# limitations under the License. 

15# 

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 

870 `ListTopicSubscriptions` method. 

871 topic (:class:`str`): 

872 Required. The name of the topic that subscriptions are 

873 attached to. Format is 

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

875 

876 This corresponds to the ``topic`` field 

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

878 should not be set. 

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

880 should be retried. 

881 timeout (TimeoutType): 

882 The timeout for this request. 

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

884 sent along with the request as metadata. 

885 

886 Returns: 

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

888 Response for the ListTopicSubscriptions method. 

889 

890 Iterating over this object will yield results and 

891 resolve additional pages automatically. 

892 

893 """ 

894 # Create or coerce a protobuf request object. 

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

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

897 has_flattened_params = any([topic]) 

898 if request is not None and has_flattened_params: 

899 raise ValueError( 

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

901 "the individual field arguments should be set." 

902 ) 

903 

904 request = pubsub.ListTopicSubscriptionsRequest(request) 

905 

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

907 # request, apply these. 

908 if topic is not None: 

909 request.topic = topic 

910 

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

912 # and friendly error handling. 

913 rpc = gapic_v1.method_async.wrap_method( 

914 self._client._transport.list_topic_subscriptions, 

915 default_retry=retries.Retry( 

916 initial=0.1, 

917 maximum=60.0, 

918 multiplier=1.3, 

919 predicate=retries.if_exception_type( 

920 core_exceptions.Aborted, 

921 core_exceptions.ServiceUnavailable, 

922 core_exceptions.Unknown, 

923 ), 

924 deadline=60.0, 

925 ), 

926 default_timeout=60.0, 

927 client_info=DEFAULT_CLIENT_INFO, 

928 ) 

929 

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

931 # add these here. 

932 metadata = tuple(metadata) + ( 

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

934 ) 

935 

936 # Send the request. 

937 response = await rpc( 

938 request, 

939 retry=retry, 

940 timeout=timeout, 

941 metadata=metadata, 

942 ) 

943 

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

945 # an `__aiter__` convenience method. 

946 response = pagers.ListTopicSubscriptionsAsyncPager( 

947 method=rpc, 

948 request=request, 

949 response=response, 

950 metadata=metadata, 

951 ) 

952 

953 # Done; return the response. 

954 return response 

955 

956 async def list_topic_snapshots( 

957 self, 

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

959 *, 

960 topic: Optional[str] = None, 

961 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

962 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

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

964 ) -> pagers.ListTopicSnapshotsAsyncPager: 

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

966 used in 

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

968 operations, which allow you to manage message acknowledgments in 

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

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

971 

972 .. code-block:: python 

973 

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

975 # code template only. 

976 # It will require modifications to work: 

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

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

979 # client as shown in: 

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

981 from google import pubsub_v1 

982 

983 async def sample_list_topic_snapshots(): 

984 # Create a client 

985 client = pubsub_v1.PublisherAsyncClient() 

986 

987 # Initialize request argument(s) 

988 request = pubsub_v1.ListTopicSnapshotsRequest( 

989 topic="topic_value", 

990 ) 

991 

992 # Make the request 

993 page_result = client.list_topic_snapshots(request=request) 

994 

995 # Handle the response 

996 async for response in page_result: 

997 print(response) 

998 

999 Args: 

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

1001 The request object. Request for the `ListTopicSnapshots` 

1002 method. 

1003 topic (:class:`str`): 

1004 Required. The name of the topic that snapshots are 

1005 attached to. Format is 

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

1007 

1008 This corresponds to the ``topic`` field 

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

1010 should not be set. 

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

1012 should be retried. 

1013 timeout (TimeoutType): 

1014 The timeout for this request. 

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

1016 sent along with the request as metadata. 

1017 

1018 Returns: 

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

1020 Response for the ListTopicSnapshots method. 

1021 

1022 Iterating over this object will yield results and 

1023 resolve additional pages automatically. 

1024 

1025 """ 

1026 # Create or coerce a protobuf request object. 

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

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

1029 has_flattened_params = any([topic]) 

1030 if request is not None and has_flattened_params: 

1031 raise ValueError( 

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

1033 "the individual field arguments should be set." 

1034 ) 

1035 

1036 request = pubsub.ListTopicSnapshotsRequest(request) 

1037 

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

1039 # request, apply these. 

1040 if topic is not None: 

1041 request.topic = topic 

1042 

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

1044 # and friendly error handling. 

1045 rpc = gapic_v1.method_async.wrap_method( 

1046 self._client._transport.list_topic_snapshots, 

1047 default_retry=retries.Retry( 

1048 initial=0.1, 

1049 maximum=60.0, 

1050 multiplier=1.3, 

1051 predicate=retries.if_exception_type( 

1052 core_exceptions.Aborted, 

1053 core_exceptions.ServiceUnavailable, 

1054 core_exceptions.Unknown, 

1055 ), 

1056 deadline=60.0, 

1057 ), 

1058 default_timeout=60.0, 

1059 client_info=DEFAULT_CLIENT_INFO, 

1060 ) 

1061 

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

1063 # add these here. 

1064 metadata = tuple(metadata) + ( 

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

1066 ) 

1067 

1068 # Send the request. 

1069 response = await rpc( 

1070 request, 

1071 retry=retry, 

1072 timeout=timeout, 

1073 metadata=metadata, 

1074 ) 

1075 

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

1077 # an `__aiter__` convenience method. 

1078 response = pagers.ListTopicSnapshotsAsyncPager( 

1079 method=rpc, 

1080 request=request, 

1081 response=response, 

1082 metadata=metadata, 

1083 ) 

1084 

1085 # Done; return the response. 

1086 return response 

1087 

1088 async def delete_topic( 

1089 self, 

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

1091 *, 

1092 topic: Optional[str] = None, 

1093 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1094 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

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

1096 ) -> None: 

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

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

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

1100 with none of the old configuration or subscriptions. Existing 

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

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

1103 

1104 .. code-block:: python 

1105 

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

1107 # code template only. 

1108 # It will require modifications to work: 

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

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

1111 # client as shown in: 

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

1113 from google import pubsub_v1 

1114 

1115 async def sample_delete_topic(): 

1116 # Create a client 

1117 client = pubsub_v1.PublisherAsyncClient() 

1118 

1119 # Initialize request argument(s) 

1120 request = pubsub_v1.DeleteTopicRequest( 

1121 topic="topic_value", 

1122 ) 

1123 

1124 # Make the request 

1125 await client.delete_topic(request=request) 

1126 

1127 Args: 

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

1129 The request object. Request for the `DeleteTopic` 

1130 method. 

1131 topic (:class:`str`): 

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

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

1134 

1135 This corresponds to the ``topic`` field 

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

1137 should not be set. 

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

1139 should be retried. 

1140 timeout (TimeoutType): 

1141 The timeout for this request. 

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

1143 sent along with the request as metadata. 

1144 """ 

1145 # Create or coerce a protobuf request object. 

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

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

1148 has_flattened_params = any([topic]) 

1149 if request is not None and has_flattened_params: 

1150 raise ValueError( 

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

1152 "the individual field arguments should be set." 

1153 ) 

1154 

1155 request = pubsub.DeleteTopicRequest(request) 

1156 

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

1158 # request, apply these. 

1159 if topic is not None: 

1160 request.topic = topic 

1161 

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

1163 # and friendly error handling. 

1164 rpc = gapic_v1.method_async.wrap_method( 

1165 self._client._transport.delete_topic, 

1166 default_retry=retries.Retry( 

1167 initial=0.1, 

1168 maximum=60.0, 

1169 multiplier=1.3, 

1170 predicate=retries.if_exception_type( 

1171 core_exceptions.ServiceUnavailable, 

1172 ), 

1173 deadline=60.0, 

1174 ), 

1175 default_timeout=60.0, 

1176 client_info=DEFAULT_CLIENT_INFO, 

1177 ) 

1178 

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

1180 # add these here. 

1181 metadata = tuple(metadata) + ( 

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

1183 ) 

1184 

1185 # Send the request. 

1186 await rpc( 

1187 request, 

1188 retry=retry, 

1189 timeout=timeout, 

1190 metadata=metadata, 

1191 ) 

1192 

1193 async def detach_subscription( 

1194 self, 

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

1196 *, 

1197 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1198 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

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

1200 ) -> pubsub.DetachSubscriptionResponse: 

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

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

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

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

1205 will stop. 

1206 

1207 .. code-block:: python 

1208 

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

1210 # code template only. 

1211 # It will require modifications to work: 

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

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

1214 # client as shown in: 

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

1216 from google import pubsub_v1 

1217 

1218 async def sample_detach_subscription(): 

1219 # Create a client 

1220 client = pubsub_v1.PublisherAsyncClient() 

1221 

1222 # Initialize request argument(s) 

1223 request = pubsub_v1.DetachSubscriptionRequest( 

1224 subscription="subscription_value", 

1225 ) 

1226 

1227 # Make the request 

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

1229 

1230 # Handle the response 

1231 print(response) 

1232 

1233 Args: 

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

1235 The request object. Request for the DetachSubscription 

1236 method. 

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

1238 should be retried. 

1239 timeout (TimeoutType): 

1240 The timeout for this request. 

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

1242 sent along with the request as metadata. 

1243 

1244 Returns: 

1245 google.pubsub_v1.types.DetachSubscriptionResponse: 

1246 Response for the DetachSubscription 

1247 method. Reserved for future use. 

1248 

1249 """ 

1250 # Create or coerce a protobuf request object. 

1251 request = pubsub.DetachSubscriptionRequest(request) 

1252 

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

1254 # and friendly error handling. 

1255 rpc = gapic_v1.method_async.wrap_method( 

1256 self._client._transport.detach_subscription, 

1257 default_retry=retries.Retry( 

1258 initial=0.1, 

1259 maximum=60.0, 

1260 multiplier=1.3, 

1261 predicate=retries.if_exception_type( 

1262 core_exceptions.ServiceUnavailable, 

1263 ), 

1264 deadline=60.0, 

1265 ), 

1266 default_timeout=60.0, 

1267 client_info=DEFAULT_CLIENT_INFO, 

1268 ) 

1269 

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

1271 # add these here. 

1272 metadata = tuple(metadata) + ( 

1273 gapic_v1.routing_header.to_grpc_metadata( 

1274 (("subscription", request.subscription),) 

1275 ), 

1276 ) 

1277 

1278 # Send the request. 

1279 response = await rpc( 

1280 request, 

1281 retry=retry, 

1282 timeout=timeout, 

1283 metadata=metadata, 

1284 ) 

1285 

1286 # Done; return the response. 

1287 return response 

1288 

1289 async def set_iam_policy( 

1290 self, 

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

1292 *, 

1293 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1294 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

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

1296 ) -> policy_pb2.Policy: 

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

1298 

1299 Replaces any existing policy. 

1300 

1301 Args: 

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

1303 The request object. Request message for `SetIamPolicy` 

1304 method. 

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

1306 should be retried. 

1307 timeout (TimeoutType): 

1308 The timeout for this request. 

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

1310 sent along with the request as metadata. 

1311 Returns: 

1312 ~.policy_pb2.Policy: 

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

1314 It is used to specify access control policies for Cloud 

1315 Platform resources. 

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

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

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

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

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

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

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

1323 expression that further constrains the role binding 

1324 based on attributes about the request and/or target 

1325 resource. 

1326 

1327 **JSON Example** 

1328 

1329 :: 

1330 { 

1331 "bindings": [ 

1332 { 

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

1334 "members": [ 

1335 "user:mike@example.com", 

1336 "group:admins@example.com", 

1337 "domain:google.com", 

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

1339 ] 

1340 }, 

1341 { 

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

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

1344 "condition": { 

1345 "title": "expirable access", 

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

1347 "expression": "request.time < 

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

1349 } 

1350 } 

1351 ] 

1352 } 

1353 

1354 **YAML Example** 

1355 

1356 :: 

1357 

1358 bindings: 

1359 - members: 

1360 - user:mike@example.com 

1361 - group:admins@example.com 

1362 - domain:google.com 

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

1364 role: roles/resourcemanager.organizationAdmin 

1365 - members: 

1366 - user:eve@example.com 

1367 role: roles/resourcemanager.organizationViewer 

1368 condition: 

1369 title: expirable access 

1370 description: Does not grant access after Sep 2020 

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

1372 

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

1374 developer's 

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

1376 """ 

1377 # Create or coerce a protobuf request object. 

1378 

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

1380 # so it must be constructed via keyword expansion. 

1381 if isinstance(request, dict): 

1382 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1383 

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

1385 # and friendly error handling. 

1386 rpc = gapic_v1.method_async.wrap_method( 

1387 self._client._transport.set_iam_policy, 

1388 default_timeout=None, 

1389 client_info=DEFAULT_CLIENT_INFO, 

1390 ) 

1391 

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

1393 # add these here. 

1394 metadata = tuple(metadata) + ( 

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

1396 ) 

1397 

1398 # Send the request. 

1399 response = await rpc( 

1400 request, 

1401 retry=retry, 

1402 timeout=timeout, 

1403 metadata=metadata, 

1404 ) 

1405 

1406 # Done; return the response. 

1407 return response 

1408 

1409 async def get_iam_policy( 

1410 self, 

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

1412 *, 

1413 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1414 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

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

1416 ) -> policy_pb2.Policy: 

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

1418 

1419 Returns an empty policy if the function exists and does 

1420 not have a policy set. 

1421 

1422 Args: 

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

1424 The request object. Request message for `GetIamPolicy` 

1425 method. 

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

1427 should be retried. 

1428 timeout (TimeoutType): 

1429 The timeout for this request. 

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

1431 sent along with the request as metadata. 

1432 Returns: 

1433 ~.policy_pb2.Policy: 

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

1435 It is used to specify access control policies for Cloud 

1436 Platform resources. 

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

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

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

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

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

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

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

1444 expression that further constrains the role binding 

1445 based on attributes about the request and/or target 

1446 resource. 

1447 

1448 **JSON Example** 

1449 

1450 :: 

1451 

1452 { 

1453 "bindings": [ 

1454 { 

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

1456 "members": [ 

1457 "user:mike@example.com", 

1458 "group:admins@example.com", 

1459 "domain:google.com", 

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

1461 ] 

1462 }, 

1463 { 

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

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

1466 "condition": { 

1467 "title": "expirable access", 

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

1469 "expression": "request.time < 

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

1471 } 

1472 } 

1473 ] 

1474 } 

1475 

1476 **YAML Example** 

1477 

1478 :: 

1479 

1480 bindings: 

1481 - members: 

1482 - user:mike@example.com 

1483 - group:admins@example.com 

1484 - domain:google.com 

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

1486 role: roles/resourcemanager.organizationAdmin 

1487 - members: 

1488 - user:eve@example.com 

1489 role: roles/resourcemanager.organizationViewer 

1490 condition: 

1491 title: expirable access 

1492 description: Does not grant access after Sep 2020 

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

1494 

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

1496 developer's 

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

1498 """ 

1499 # Create or coerce a protobuf request object. 

1500 

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

1502 # so it must be constructed via keyword expansion. 

1503 if isinstance(request, dict): 

1504 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1505 

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

1507 # and friendly error handling. 

1508 rpc = gapic_v1.method_async.wrap_method( 

1509 self._client._transport.get_iam_policy, 

1510 default_timeout=None, 

1511 client_info=DEFAULT_CLIENT_INFO, 

1512 ) 

1513 

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

1515 # add these here. 

1516 metadata = tuple(metadata) + ( 

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

1518 ) 

1519 

1520 # Send the request. 

1521 response = await rpc( 

1522 request, 

1523 retry=retry, 

1524 timeout=timeout, 

1525 metadata=metadata, 

1526 ) 

1527 

1528 # Done; return the response. 

1529 return response 

1530 

1531 async def test_iam_permissions( 

1532 self, 

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

1534 *, 

1535 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1536 timeout: TimeoutType = gapic_v1.method.DEFAULT, 

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

1538 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

1540 policy for a function. 

1541 

1542 If the function does not exist, this will 

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

1544 

1545 Args: 

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

1547 The request object. Request message for 

1548 `TestIamPermissions` method. 

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

1550 should be retried. 

1551 timeout (TimeoutType): 

1552 The timeout for this request. 

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

1554 sent along with the request as metadata. 

1555 Returns: 

1556 ~iam_policy_pb2.PolicyTestIamPermissionsResponse: 

1557 Response message for ``TestIamPermissions`` method. 

1558 """ 

1559 # Create or coerce a protobuf request object. 

1560 

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

1562 # so it must be constructed via keyword expansion. 

1563 if isinstance(request, dict): 

1564 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1565 

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

1567 # and friendly error handling. 

1568 rpc = gapic_v1.method_async.wrap_method( 

1569 self._client._transport.test_iam_permissions, 

1570 default_timeout=None, 

1571 client_info=DEFAULT_CLIENT_INFO, 

1572 ) 

1573 

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

1575 # add these here. 

1576 metadata = tuple(metadata) + ( 

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

1578 ) 

1579 

1580 # Send the request. 

1581 response = await rpc( 

1582 request, 

1583 retry=retry, 

1584 timeout=timeout, 

1585 metadata=metadata, 

1586 ) 

1587 

1588 # Done; return the response. 

1589 return response 

1590 

1591 async def __aenter__(self): 

1592 return self 

1593 

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

1595 await self.transport.close() 

1596 

1597 

1598DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1599 client_library_version=package_version.__version__ 

1600) 

1601 

1602 

1603__all__ = ("PublisherAsyncClient",)