|
1 |
| -from abc import ABC, abstractmethod |
2 |
| -from typing import List |
| 1 | +from typing import Optional, List |
3 | 2 |
|
| 3 | +from overrides import overrides |
| 4 | +from google.api_core.client_options import ClientOptions |
| 5 | +from google.auth.credentials import Credentials |
| 6 | +from google.protobuf.field_mask_pb2 import FieldMask |
| 7 | + |
| 8 | +from google.cloud.pubsublite.admin_client_interface import AdminClientInterface |
| 9 | +from google.cloud.pubsublite.internal.constructable_from_service_account import ( |
| 10 | + ConstructableFromServiceAccount, |
| 11 | +) |
| 12 | +from google.cloud.pubsublite.internal.endpoints import regional_endpoint |
| 13 | +from google.cloud.pubsublite.internal.wire.admin_client_impl import AdminClientImpl |
4 | 14 | from google.cloud.pubsublite.types import (
|
5 | 15 | CloudRegion,
|
6 |
| - TopicPath, |
7 |
| - LocationPath, |
8 | 16 | SubscriptionPath,
|
| 17 | + LocationPath, |
| 18 | + TopicPath, |
9 | 19 | )
|
10 |
| -from google.cloud.pubsublite_v1 import Topic, Subscription |
11 |
| -from google.protobuf.field_mask_pb2 import FieldMask |
| 20 | +from google.cloud.pubsublite_v1 import AdminServiceClient, Subscription, Topic |
| 21 | + |
| 22 | + |
| 23 | +class AdminClient(AdminClientInterface, ConstructableFromServiceAccount): |
| 24 | + """ |
| 25 | + An admin client for Pub/Sub Lite. Only operates on a single region. |
| 26 | + """ |
| 27 | + |
| 28 | + _impl: AdminClientInterface |
| 29 | + |
| 30 | + def __init__( |
| 31 | + self, |
| 32 | + region: CloudRegion, |
| 33 | + credentials: Optional[Credentials] = None, |
| 34 | + transport: Optional[str] = None, |
| 35 | + client_options: Optional[ClientOptions] = None, |
| 36 | + ): |
| 37 | + """ |
| 38 | + Create a new AdminClient. |
12 | 39 |
|
| 40 | + Args: |
| 41 | + region: The cloud region to connect to. |
| 42 | + credentials: The credentials to use when connecting. |
| 43 | + transport: The transport to use. |
| 44 | + client_options: The client options to use when connecting. If used, must explicitly set `api_endpoint`. |
| 45 | + """ |
| 46 | + if client_options is None: |
| 47 | + client_options = ClientOptions(api_endpoint=regional_endpoint(region)) |
| 48 | + self._impl = AdminClientImpl( |
| 49 | + AdminServiceClient( |
| 50 | + client_options=client_options, |
| 51 | + transport=transport, |
| 52 | + credentials=credentials, |
| 53 | + ), |
| 54 | + region, |
| 55 | + ) |
13 | 56 |
|
14 |
| -class AdminClient(ABC): |
15 |
| - @abstractmethod |
| 57 | + @overrides |
16 | 58 | def region(self) -> CloudRegion:
|
17 |
| - """The region this client is for.""" |
| 59 | + return self._impl.region() |
18 | 60 |
|
19 |
| - @abstractmethod |
| 61 | + @overrides |
20 | 62 | def create_topic(self, topic: Topic) -> Topic:
|
21 |
| - """Create a topic, returns the created topic.""" |
| 63 | + return self._impl.create_topic(topic) |
22 | 64 |
|
23 |
| - @abstractmethod |
| 65 | + @overrides |
24 | 66 | def get_topic(self, topic_path: TopicPath) -> Topic:
|
25 |
| - """Get the topic object from the server.""" |
| 67 | + return self._impl.get_topic(topic_path) |
26 | 68 |
|
27 |
| - @abstractmethod |
| 69 | + @overrides |
28 | 70 | def get_topic_partition_count(self, topic_path: TopicPath) -> int:
|
29 |
| - """Get the number of partitions in the provided topic.""" |
| 71 | + return self._impl.get_topic_partition_count(topic_path) |
30 | 72 |
|
31 |
| - @abstractmethod |
| 73 | + @overrides |
32 | 74 | def list_topics(self, location_path: LocationPath) -> List[Topic]:
|
33 |
| - """List the Pub/Sub lite topics that exist for a project in a given location.""" |
| 75 | + return self._impl.list_topics(location_path) |
34 | 76 |
|
35 |
| - @abstractmethod |
| 77 | + @overrides |
36 | 78 | def update_topic(self, topic: Topic, update_mask: FieldMask) -> Topic:
|
37 |
| - """Update the masked fields of the provided topic.""" |
| 79 | + return self._impl.update_topic(topic, update_mask) |
38 | 80 |
|
39 |
| - @abstractmethod |
| 81 | + @overrides |
40 | 82 | def delete_topic(self, topic_path: TopicPath):
|
41 |
| - """Delete a topic and all associated messages.""" |
| 83 | + return self._impl.delete_topic(topic_path) |
42 | 84 |
|
43 |
| - @abstractmethod |
| 85 | + @overrides |
44 | 86 | def list_topic_subscriptions(self, topic_path: TopicPath):
|
45 |
| - """List the subscriptions that exist for a given topic.""" |
| 87 | + return self._impl.list_topic_subscriptions(topic_path) |
46 | 88 |
|
47 |
| - @abstractmethod |
| 89 | + @overrides |
48 | 90 | def create_subscription(self, subscription: Subscription) -> Subscription:
|
49 |
| - """Create a subscription, returns the created subscription.""" |
| 91 | + return self._impl.create_subscription(subscription) |
50 | 92 |
|
51 |
| - @abstractmethod |
| 93 | + @overrides |
52 | 94 | def get_subscription(self, subscription_path: SubscriptionPath) -> Subscription:
|
53 |
| - """Get the subscription object from the server.""" |
| 95 | + return self._impl.get_subscription(subscription_path) |
54 | 96 |
|
55 |
| - @abstractmethod |
| 97 | + @overrides |
56 | 98 | def list_subscriptions(self, location_path: LocationPath) -> List[Subscription]:
|
57 |
| - """List the Pub/Sub lite subscriptions that exist for a project in a given location.""" |
| 99 | + return self._impl.list_subscriptions(location_path) |
58 | 100 |
|
59 |
| - @abstractmethod |
| 101 | + @overrides |
60 | 102 | def update_subscription(
|
61 | 103 | self, subscription: Subscription, update_mask: FieldMask
|
62 | 104 | ) -> Subscription:
|
63 |
| - """Update the masked fields of the provided subscription.""" |
| 105 | + return self._impl.update_subscription(subscription, update_mask) |
64 | 106 |
|
65 |
| - @abstractmethod |
| 107 | + @overrides |
66 | 108 | def delete_subscription(self, subscription_path: SubscriptionPath):
|
67 |
| - """Delete a subscription and all associated messages.""" |
| 109 | + return self._impl.delete_subscription(subscription_path) |
0 commit comments