Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit f3f1a86

Browse files
feat: add common resource helpers; expose client transport; remove send/recv gRPC limits (#38)
1 parent add0735 commit f3f1a86

File tree

21 files changed

+883
-387
lines changed

21 files changed

+883
-387
lines changed

docs/redis_v1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Redis v1 API
33

44
.. automodule:: google.cloud.redis_v1.types
55
:members:
6+
:show-inheritance:

docs/redis_v1beta1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Redis v1beta1 API
33

44
.. automodule:: google.cloud.redis_v1beta1.types
55
:members:
6+
:show-inheritance:

google/cloud/redis_v1/services/cloud_redis/async_client.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,41 @@ class CloudRedisAsyncClient:
7474
instance_path = staticmethod(CloudRedisClient.instance_path)
7575
parse_instance_path = staticmethod(CloudRedisClient.parse_instance_path)
7676

77+
common_billing_account_path = staticmethod(
78+
CloudRedisClient.common_billing_account_path
79+
)
80+
parse_common_billing_account_path = staticmethod(
81+
CloudRedisClient.parse_common_billing_account_path
82+
)
83+
84+
common_folder_path = staticmethod(CloudRedisClient.common_folder_path)
85+
parse_common_folder_path = staticmethod(CloudRedisClient.parse_common_folder_path)
86+
87+
common_organization_path = staticmethod(CloudRedisClient.common_organization_path)
88+
parse_common_organization_path = staticmethod(
89+
CloudRedisClient.parse_common_organization_path
90+
)
91+
92+
common_project_path = staticmethod(CloudRedisClient.common_project_path)
93+
parse_common_project_path = staticmethod(CloudRedisClient.parse_common_project_path)
94+
95+
common_location_path = staticmethod(CloudRedisClient.common_location_path)
96+
parse_common_location_path = staticmethod(
97+
CloudRedisClient.parse_common_location_path
98+
)
99+
77100
from_service_account_file = CloudRedisClient.from_service_account_file
78101
from_service_account_json = from_service_account_file
79102

103+
@property
104+
def transport(self) -> CloudRedisTransport:
105+
"""Return the transport used by the client instance.
106+
107+
Returns:
108+
CloudRedisTransport: The transport used by the client instance.
109+
"""
110+
return self._client.transport
111+
80112
get_transport_class = functools.partial(
81113
type(CloudRedisClient).get_transport_class, type(CloudRedisClient)
82114
)
@@ -180,7 +212,8 @@ async def list_instances(
180212
# Create or coerce a protobuf request object.
181213
# Sanity check: If we got a request object, we should *not* have
182214
# gotten any keyword arguments that map to the request.
183-
if request is not None and builtins.any([parent]):
215+
has_flattened_params = builtins.any([parent])
216+
if request is not None and has_flattened_params:
184217
raise ValueError(
185218
"If the `request` argument is set, then none of "
186219
"the individual field arguments should be set."
@@ -256,7 +289,8 @@ async def get_instance(
256289
# Create or coerce a protobuf request object.
257290
# Sanity check: If we got a request object, we should *not* have
258291
# gotten any keyword arguments that map to the request.
259-
if request is not None and builtins.any([name]):
292+
has_flattened_params = builtins.any([name])
293+
if request is not None and has_flattened_params:
260294
raise ValueError(
261295
"If the `request` argument is set, then none of "
262296
"the individual field arguments should be set."
@@ -365,7 +399,8 @@ async def create_instance(
365399
# Create or coerce a protobuf request object.
366400
# Sanity check: If we got a request object, we should *not* have
367401
# gotten any keyword arguments that map to the request.
368-
if request is not None and builtins.any([parent, instance_id, instance]):
402+
has_flattened_params = builtins.any([parent, instance_id, instance])
403+
if request is not None and has_flattened_params:
369404
raise ValueError(
370405
"If the `request` argument is set, then none of "
371406
"the individual field arguments should be set."
@@ -470,7 +505,8 @@ async def update_instance(
470505
# Create or coerce a protobuf request object.
471506
# Sanity check: If we got a request object, we should *not* have
472507
# gotten any keyword arguments that map to the request.
473-
if request is not None and builtins.any([update_mask, instance]):
508+
has_flattened_params = builtins.any([update_mask, instance])
509+
if request is not None and has_flattened_params:
474510
raise ValueError(
475511
"If the `request` argument is set, then none of "
476512
"the individual field arguments should be set."
@@ -565,7 +601,8 @@ async def upgrade_instance(
565601
# Create or coerce a protobuf request object.
566602
# Sanity check: If we got a request object, we should *not* have
567603
# gotten any keyword arguments that map to the request.
568-
if request is not None and builtins.any([name, redis_version]):
604+
has_flattened_params = builtins.any([name, redis_version])
605+
if request is not None and has_flattened_params:
569606
raise ValueError(
570607
"If the `request` argument is set, then none of "
571608
"the individual field arguments should be set."
@@ -665,7 +702,8 @@ async def import_instance(
665702
# Create or coerce a protobuf request object.
666703
# Sanity check: If we got a request object, we should *not* have
667704
# gotten any keyword arguments that map to the request.
668-
if request is not None and builtins.any([name, input_config]):
705+
has_flattened_params = builtins.any([name, input_config])
706+
if request is not None and has_flattened_params:
669707
raise ValueError(
670708
"If the `request` argument is set, then none of "
671709
"the individual field arguments should be set."
@@ -761,7 +799,8 @@ async def export_instance(
761799
# Create or coerce a protobuf request object.
762800
# Sanity check: If we got a request object, we should *not* have
763801
# gotten any keyword arguments that map to the request.
764-
if request is not None and builtins.any([name, output_config]):
802+
has_flattened_params = builtins.any([name, output_config])
803+
if request is not None and has_flattened_params:
765804
raise ValueError(
766805
"If the `request` argument is set, then none of "
767806
"the individual field arguments should be set."
@@ -856,7 +895,8 @@ async def failover_instance(
856895
# Create or coerce a protobuf request object.
857896
# Sanity check: If we got a request object, we should *not* have
858897
# gotten any keyword arguments that map to the request.
859-
if request is not None and builtins.any([name, data_protection_mode]):
898+
has_flattened_params = builtins.any([name, data_protection_mode])
899+
if request is not None and has_flattened_params:
860900
raise ValueError(
861901
"If the `request` argument is set, then none of "
862902
"the individual field arguments should be set."
@@ -954,7 +994,8 @@ async def delete_instance(
954994
# Create or coerce a protobuf request object.
955995
# Sanity check: If we got a request object, we should *not* have
956996
# gotten any keyword arguments that map to the request.
957-
if request is not None and builtins.any([name]):
997+
has_flattened_params = builtins.any([name])
998+
if request is not None and has_flattened_params:
958999
raise ValueError(
9591000
"If the `request` argument is set, then none of "
9601001
"the individual field arguments should be set."

google/cloud/redis_v1/services/cloud_redis/client.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
155155

156156
from_service_account_json = from_service_account_file
157157

158+
@property
159+
def transport(self) -> CloudRedisTransport:
160+
"""Return the transport used by the client instance.
161+
162+
Returns:
163+
CloudRedisTransport: The transport used by the client instance.
164+
"""
165+
return self._transport
166+
158167
@staticmethod
159168
def instance_path(project: str, location: str, instance: str,) -> str:
160169
"""Return a fully-qualified instance string."""
@@ -171,6 +180,65 @@ def parse_instance_path(path: str) -> Dict[str, str]:
171180
)
172181
return m.groupdict() if m else {}
173182

183+
@staticmethod
184+
def common_billing_account_path(billing_account: str,) -> str:
185+
"""Return a fully-qualified billing_account string."""
186+
return "billingAccounts/{billing_account}".format(
187+
billing_account=billing_account,
188+
)
189+
190+
@staticmethod
191+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
192+
"""Parse a billing_account path into its component segments."""
193+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
194+
return m.groupdict() if m else {}
195+
196+
@staticmethod
197+
def common_folder_path(folder: str,) -> str:
198+
"""Return a fully-qualified folder string."""
199+
return "folders/{folder}".format(folder=folder,)
200+
201+
@staticmethod
202+
def parse_common_folder_path(path: str) -> Dict[str, str]:
203+
"""Parse a folder path into its component segments."""
204+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
205+
return m.groupdict() if m else {}
206+
207+
@staticmethod
208+
def common_organization_path(organization: str,) -> str:
209+
"""Return a fully-qualified organization string."""
210+
return "organizations/{organization}".format(organization=organization,)
211+
212+
@staticmethod
213+
def parse_common_organization_path(path: str) -> Dict[str, str]:
214+
"""Parse a organization path into its component segments."""
215+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
216+
return m.groupdict() if m else {}
217+
218+
@staticmethod
219+
def common_project_path(project: str,) -> str:
220+
"""Return a fully-qualified project string."""
221+
return "projects/{project}".format(project=project,)
222+
223+
@staticmethod
224+
def parse_common_project_path(path: str) -> Dict[str, str]:
225+
"""Parse a project path into its component segments."""
226+
m = re.match(r"^projects/(?P<project>.+?)$", path)
227+
return m.groupdict() if m else {}
228+
229+
@staticmethod
230+
def common_location_path(project: str, location: str,) -> str:
231+
"""Return a fully-qualified location string."""
232+
return "projects/{project}/locations/{location}".format(
233+
project=project, location=location,
234+
)
235+
236+
@staticmethod
237+
def parse_common_location_path(path: str) -> Dict[str, str]:
238+
"""Parse a location path into its component segments."""
239+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
240+
return m.groupdict() if m else {}
241+
174242
def __init__(
175243
self,
176244
*,
@@ -206,10 +274,10 @@ def __init__(
206274
not provided, the default SSL client certificate will be used if
207275
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
208276
set, no client certificate will be used.
209-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
210-
The client info used to send a user-agent string along with
211-
API requests. If ``None``, then default info will be used.
212-
Generally, you only need to set this if you're developing
277+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
278+
The client info used to send a user-agent string along with
279+
API requests. If ``None``, then default info will be used.
280+
Generally, you only need to set this if you're developing
213281
your own client library.
214282
215283
Raises:

google/cloud/redis_v1/services/cloud_redis/transports/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
_transport_registry["grpc"] = CloudRedisGrpcTransport
2929
_transport_registry["grpc_asyncio"] = CloudRedisGrpcAsyncIOTransport
3030

31-
3231
__all__ = (
3332
"CloudRedisTransport",
3433
"CloudRedisGrpcTransport",

google/cloud/redis_v1/services/cloud_redis/transports/grpc.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ def __init__(
111111
for grpc channel. It is ignored if ``channel`` is provided.
112112
quota_project_id (Optional[str]): An optional project to use for billing
113113
and quota.
114-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
115-
The client info used to send a user-agent string along with
116-
API requests. If ``None``, then default info will be used.
117-
Generally, you only need to set this if you're developing
114+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
115+
The client info used to send a user-agent string along with
116+
API requests. If ``None``, then default info will be used.
117+
Generally, you only need to set this if you're developing
118118
your own client library.
119119
120120
Raises:
@@ -123,13 +123,16 @@ def __init__(
123123
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
124124
and ``credentials_file`` are passed.
125125
"""
126+
self._ssl_channel_credentials = ssl_channel_credentials
127+
126128
if channel:
127129
# Sanity check: Ensure that channel and credentials are not both
128130
# provided.
129131
credentials = False
130132

131133
# If a channel was explicitly provided, set it.
132134
self._grpc_channel = channel
135+
self._ssl_channel_credentials = None
133136
elif api_mtls_endpoint:
134137
warnings.warn(
135138
"api_mtls_endpoint and client_cert_source are deprecated",
@@ -165,7 +168,12 @@ def __init__(
165168
ssl_credentials=ssl_credentials,
166169
scopes=scopes or self.AUTH_SCOPES,
167170
quota_project_id=quota_project_id,
171+
options=[
172+
("grpc.max_send_message_length", -1),
173+
("grpc.max_receive_message_length", -1),
174+
],
168175
)
176+
self._ssl_channel_credentials = ssl_credentials
169177
else:
170178
host = host if ":" in host else host + ":443"
171179

@@ -182,9 +190,14 @@ def __init__(
182190
ssl_credentials=ssl_channel_credentials,
183191
scopes=scopes or self.AUTH_SCOPES,
184192
quota_project_id=quota_project_id,
193+
options=[
194+
("grpc.max_send_message_length", -1),
195+
("grpc.max_receive_message_length", -1),
196+
],
185197
)
186198

187199
self._stubs = {} # type: Dict[str, Callable]
200+
self._operations_client = None
188201

189202
# Run the base constructor.
190203
super().__init__(
@@ -208,7 +221,7 @@ def create_channel(
208221
) -> grpc.Channel:
209222
"""Create and return a gRPC channel object.
210223
Args:
211-
address (Optionsl[str]): The host for the channel to use.
224+
address (Optional[str]): The host for the channel to use.
212225
credentials (Optional[~.Credentials]): The
213226
authorization credentials to attach to requests. These
214227
credentials identify this application to the service. If
@@ -243,12 +256,8 @@ def create_channel(
243256

244257
@property
245258
def grpc_channel(self) -> grpc.Channel:
246-
"""Create the channel designed to connect to this service.
247-
248-
This property caches on the instance; repeated calls return
249-
the same channel.
259+
"""Return the channel designed to connect to this service.
250260
"""
251-
# Return the channel from cache.
252261
return self._grpc_channel
253262

254263
@property
@@ -259,13 +268,11 @@ def operations_client(self) -> operations_v1.OperationsClient:
259268
client.
260269
"""
261270
# Sanity check: Only create a new client if we do not already have one.
262-
if "operations_client" not in self.__dict__:
263-
self.__dict__["operations_client"] = operations_v1.OperationsClient(
264-
self.grpc_channel
265-
)
271+
if self._operations_client is None:
272+
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)
266273

267274
# Return the client from cache.
268-
return self.__dict__["operations_client"]
275+
return self._operations_client
269276

270277
@property
271278
def list_instances(

0 commit comments

Comments
 (0)