Skip to content

Commit 386e85e

Browse files
authored
fix: request and flattened params are exclusive, surface transport in generated layer (#256)
- Restore path helper methods to generated clients. - Enforce that 'request' argument to generated client methods is exclusive to flattened arguments. - Surface 'transport' property for generated clients. Closes #251 Closes #252
1 parent ab19546 commit 386e85e

File tree

16 files changed

+1041
-452
lines changed

16 files changed

+1041
-452
lines changed

google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,58 @@ class FirestoreAdminAsyncClient:
5454
DEFAULT_ENDPOINT = FirestoreAdminClient.DEFAULT_ENDPOINT
5555
DEFAULT_MTLS_ENDPOINT = FirestoreAdminClient.DEFAULT_MTLS_ENDPOINT
5656

57+
collection_group_path = staticmethod(FirestoreAdminClient.collection_group_path)
58+
parse_collection_group_path = staticmethod(
59+
FirestoreAdminClient.parse_collection_group_path
60+
)
61+
database_path = staticmethod(FirestoreAdminClient.database_path)
62+
parse_database_path = staticmethod(FirestoreAdminClient.parse_database_path)
5763
field_path = staticmethod(FirestoreAdminClient.field_path)
5864
parse_field_path = staticmethod(FirestoreAdminClient.parse_field_path)
5965
index_path = staticmethod(FirestoreAdminClient.index_path)
6066
parse_index_path = staticmethod(FirestoreAdminClient.parse_index_path)
6167

68+
common_billing_account_path = staticmethod(
69+
FirestoreAdminClient.common_billing_account_path
70+
)
71+
parse_common_billing_account_path = staticmethod(
72+
FirestoreAdminClient.parse_common_billing_account_path
73+
)
74+
75+
common_folder_path = staticmethod(FirestoreAdminClient.common_folder_path)
76+
parse_common_folder_path = staticmethod(
77+
FirestoreAdminClient.parse_common_folder_path
78+
)
79+
80+
common_organization_path = staticmethod(
81+
FirestoreAdminClient.common_organization_path
82+
)
83+
parse_common_organization_path = staticmethod(
84+
FirestoreAdminClient.parse_common_organization_path
85+
)
86+
87+
common_project_path = staticmethod(FirestoreAdminClient.common_project_path)
88+
parse_common_project_path = staticmethod(
89+
FirestoreAdminClient.parse_common_project_path
90+
)
91+
92+
common_location_path = staticmethod(FirestoreAdminClient.common_location_path)
93+
parse_common_location_path = staticmethod(
94+
FirestoreAdminClient.parse_common_location_path
95+
)
96+
6297
from_service_account_file = FirestoreAdminClient.from_service_account_file
6398
from_service_account_json = from_service_account_file
6499

100+
@property
101+
def transport(self) -> FirestoreAdminTransport:
102+
"""Return the transport used by the client instance.
103+
104+
Returns:
105+
FirestoreAdminTransport: The transport used by the client instance.
106+
"""
107+
return self._client.transport
108+
65109
get_transport_class = functools.partial(
66110
type(FirestoreAdminClient).get_transport_class, type(FirestoreAdminClient)
67111
)
@@ -166,7 +210,8 @@ async def create_index(
166210
# Create or coerce a protobuf request object.
167211
# Sanity check: If we got a request object, we should *not* have
168212
# gotten any keyword arguments that map to the request.
169-
if request is not None and any([parent, index]):
213+
has_flattened_params = any([parent, index])
214+
if request is not None and has_flattened_params:
170215
raise ValueError(
171216
"If the `request` argument is set, then none of "
172217
"the individual field arguments should be set."
@@ -250,7 +295,8 @@ async def list_indexes(
250295
# Create or coerce a protobuf request object.
251296
# Sanity check: If we got a request object, we should *not* have
252297
# gotten any keyword arguments that map to the request.
253-
if request is not None and any([parent]):
298+
has_flattened_params = any([parent])
299+
if request is not None and has_flattened_params:
254300
raise ValueError(
255301
"If the `request` argument is set, then none of "
256302
"the individual field arguments should be set."
@@ -338,7 +384,8 @@ async def get_index(
338384
# Create or coerce a protobuf request object.
339385
# Sanity check: If we got a request object, we should *not* have
340386
# gotten any keyword arguments that map to the request.
341-
if request is not None and any([name]):
387+
has_flattened_params = any([name])
388+
if request is not None and has_flattened_params:
342389
raise ValueError(
343390
"If the `request` argument is set, then none of "
344391
"the individual field arguments should be set."
@@ -413,7 +460,8 @@ async def delete_index(
413460
# Create or coerce a protobuf request object.
414461
# Sanity check: If we got a request object, we should *not* have
415462
# gotten any keyword arguments that map to the request.
416-
if request is not None and any([name]):
463+
has_flattened_params = any([name])
464+
if request is not None and has_flattened_params:
417465
raise ValueError(
418466
"If the `request` argument is set, then none of "
419467
"the individual field arguments should be set."
@@ -496,7 +544,8 @@ async def get_field(
496544
# Create or coerce a protobuf request object.
497545
# Sanity check: If we got a request object, we should *not* have
498546
# gotten any keyword arguments that map to the request.
499-
if request is not None and any([name]):
547+
has_flattened_params = any([name])
548+
if request is not None and has_flattened_params:
500549
raise ValueError(
501550
"If the `request` argument is set, then none of "
502551
"the individual field arguments should be set."
@@ -598,7 +647,8 @@ async def update_field(
598647
# Create or coerce a protobuf request object.
599648
# Sanity check: If we got a request object, we should *not* have
600649
# gotten any keyword arguments that map to the request.
601-
if request is not None and any([field]):
650+
has_flattened_params = any([field])
651+
if request is not None and has_flattened_params:
602652
raise ValueError(
603653
"If the `request` argument is set, then none of "
604654
"the individual field arguments should be set."
@@ -689,7 +739,8 @@ async def list_fields(
689739
# Create or coerce a protobuf request object.
690740
# Sanity check: If we got a request object, we should *not* have
691741
# gotten any keyword arguments that map to the request.
692-
if request is not None and any([parent]):
742+
has_flattened_params = any([parent])
743+
if request is not None and has_flattened_params:
693744
raise ValueError(
694745
"If the `request` argument is set, then none of "
695746
"the individual field arguments should be set."
@@ -790,7 +841,8 @@ async def export_documents(
790841
# Create or coerce a protobuf request object.
791842
# Sanity check: If we got a request object, we should *not* have
792843
# gotten any keyword arguments that map to the request.
793-
if request is not None and any([name]):
844+
has_flattened_params = any([name])
845+
if request is not None and has_flattened_params:
794846
raise ValueError(
795847
"If the `request` argument is set, then none of "
796848
"the individual field arguments should be set."
@@ -890,7 +942,8 @@ async def import_documents(
890942
# Create or coerce a protobuf request object.
891943
# Sanity check: If we got a request object, we should *not* have
892944
# gotten any keyword arguments that map to the request.
893-
if request is not None and any([name]):
945+
has_flattened_params = any([name])
946+
if request is not None and has_flattened_params:
894947
raise ValueError(
895948
"If the `request` argument is set, then none of "
896949
"the individual field arguments should be set."

google/cloud/firestore_admin_v1/services/firestore_admin/client.py

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,44 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
140140

141141
from_service_account_json = from_service_account_file
142142

143+
@property
144+
def transport(self) -> FirestoreAdminTransport:
145+
"""Return the transport used by the client instance.
146+
147+
Returns:
148+
FirestoreAdminTransport: The transport used by the client instance.
149+
"""
150+
return self._transport
151+
152+
@staticmethod
153+
def collection_group_path(project: str, database: str, collection: str,) -> str:
154+
"""Return a fully-qualified collection_group string."""
155+
return "projects/{project}/databases/{database}/collectionGroups/{collection}".format(
156+
project=project, database=database, collection=collection,
157+
)
158+
159+
@staticmethod
160+
def parse_collection_group_path(path: str) -> Dict[str, str]:
161+
"""Parse a collection_group path into its component segments."""
162+
m = re.match(
163+
r"^projects/(?P<project>.+?)/databases/(?P<database>.+?)/collectionGroups/(?P<collection>.+?)$",
164+
path,
165+
)
166+
return m.groupdict() if m else {}
167+
168+
@staticmethod
169+
def database_path(project: str, database: str,) -> str:
170+
"""Return a fully-qualified database string."""
171+
return "projects/{project}/databases/{database}".format(
172+
project=project, database=database,
173+
)
174+
175+
@staticmethod
176+
def parse_database_path(path: str) -> Dict[str, str]:
177+
"""Parse a database path into its component segments."""
178+
m = re.match(r"^projects/(?P<project>.+?)/databases/(?P<database>.+?)$", path)
179+
return m.groupdict() if m else {}
180+
143181
@staticmethod
144182
def field_path(project: str, database: str, collection: str, field: str,) -> str:
145183
"""Return a fully-qualified field string."""
@@ -172,6 +210,65 @@ def parse_index_path(path: str) -> Dict[str, str]:
172210
)
173211
return m.groupdict() if m else {}
174212

213+
@staticmethod
214+
def common_billing_account_path(billing_account: str,) -> str:
215+
"""Return a fully-qualified billing_account string."""
216+
return "billingAccounts/{billing_account}".format(
217+
billing_account=billing_account,
218+
)
219+
220+
@staticmethod
221+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
222+
"""Parse a billing_account path into its component segments."""
223+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
224+
return m.groupdict() if m else {}
225+
226+
@staticmethod
227+
def common_folder_path(folder: str,) -> str:
228+
"""Return a fully-qualified folder string."""
229+
return "folders/{folder}".format(folder=folder,)
230+
231+
@staticmethod
232+
def parse_common_folder_path(path: str) -> Dict[str, str]:
233+
"""Parse a folder path into its component segments."""
234+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
235+
return m.groupdict() if m else {}
236+
237+
@staticmethod
238+
def common_organization_path(organization: str,) -> str:
239+
"""Return a fully-qualified organization string."""
240+
return "organizations/{organization}".format(organization=organization,)
241+
242+
@staticmethod
243+
def parse_common_organization_path(path: str) -> Dict[str, str]:
244+
"""Parse a organization path into its component segments."""
245+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
246+
return m.groupdict() if m else {}
247+
248+
@staticmethod
249+
def common_project_path(project: str,) -> str:
250+
"""Return a fully-qualified project string."""
251+
return "projects/{project}".format(project=project,)
252+
253+
@staticmethod
254+
def parse_common_project_path(path: str) -> Dict[str, str]:
255+
"""Parse a project path into its component segments."""
256+
m = re.match(r"^projects/(?P<project>.+?)$", path)
257+
return m.groupdict() if m else {}
258+
259+
@staticmethod
260+
def common_location_path(project: str, location: str,) -> str:
261+
"""Return a fully-qualified location string."""
262+
return "projects/{project}/locations/{location}".format(
263+
project=project, location=location,
264+
)
265+
266+
@staticmethod
267+
def parse_common_location_path(path: str) -> Dict[str, str]:
268+
"""Parse a location path into its component segments."""
269+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
270+
return m.groupdict() if m else {}
271+
175272
def __init__(
176273
self,
177274
*,
@@ -207,10 +304,10 @@ def __init__(
207304
not provided, the default SSL client certificate will be used if
208305
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
209306
set, no client certificate will be used.
210-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
211-
The client info used to send a user-agent string along with
212-
API requests. If ``None``, then default info will be used.
213-
Generally, you only need to set this if you're developing
307+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
308+
The client info used to send a user-agent string along with
309+
API requests. If ``None``, then default info will be used.
310+
Generally, you only need to set this if you're developing
214311
your own client library.
215312
216313
Raises:

google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def __init__(
9595
for grpc channel. It is ignored if ``channel`` is provided.
9696
quota_project_id (Optional[str]): An optional project to use for billing
9797
and quota.
98-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
99-
The client info used to send a user-agent string along with
100-
API requests. If ``None``, then default info will be used.
101-
Generally, you only need to set this if you're developing
98+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
99+
The client info used to send a user-agent string along with
100+
API requests. If ``None``, then default info will be used.
101+
Generally, you only need to set this if you're developing
102102
your own client library.
103103
104104
Raises:
@@ -107,13 +107,16 @@ def __init__(
107107
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
108108
and ``credentials_file`` are passed.
109109
"""
110+
self._ssl_channel_credentials = ssl_channel_credentials
111+
110112
if channel:
111113
# Sanity check: Ensure that channel and credentials are not both
112114
# provided.
113115
credentials = False
114116

115117
# If a channel was explicitly provided, set it.
116118
self._grpc_channel = channel
119+
self._ssl_channel_credentials = None
117120
elif api_mtls_endpoint:
118121
warnings.warn(
119122
"api_mtls_endpoint and client_cert_source are deprecated",
@@ -150,6 +153,7 @@ def __init__(
150153
scopes=scopes or self.AUTH_SCOPES,
151154
quota_project_id=quota_project_id,
152155
)
156+
self._ssl_channel_credentials = ssl_credentials
153157
else:
154158
host = host if ":" in host else host + ":443"
155159

@@ -227,12 +231,8 @@ def create_channel(
227231

228232
@property
229233
def grpc_channel(self) -> grpc.Channel:
230-
"""Create the channel designed to connect to this service.
231-
232-
This property caches on the instance; repeated calls return
233-
the same channel.
234+
"""Return the channel designed to connect to this service.
234235
"""
235-
# Return the channel from cache.
236236
return self._grpc_channel
237237

238238
@property

google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,16 @@ def __init__(
152152
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
153153
and ``credentials_file`` are passed.
154154
"""
155+
self._ssl_channel_credentials = ssl_channel_credentials
156+
155157
if channel:
156158
# Sanity check: Ensure that channel and credentials are not both
157159
# provided.
158160
credentials = False
159161

160162
# If a channel was explicitly provided, set it.
161163
self._grpc_channel = channel
164+
self._ssl_channel_credentials = None
162165
elif api_mtls_endpoint:
163166
warnings.warn(
164167
"api_mtls_endpoint and client_cert_source are deprecated",
@@ -195,6 +198,7 @@ def __init__(
195198
scopes=scopes or self.AUTH_SCOPES,
196199
quota_project_id=quota_project_id,
197200
)
201+
self._ssl_channel_credentials = ssl_credentials
198202
else:
199203
host = host if ":" in host else host + ":443"
200204

0 commit comments

Comments
 (0)