Skip to content

Commit 0fdc38e

Browse files
Timur Sadykovpartheaohmayr
authored
fix: disable universe-domain validation (#2236)
Co-authored-by: Anthonios Partheniou <partheniou@google.com> Co-authored-by: ohmayr <omairn@google.com>
1 parent 7ffa74e commit 0fdc38e

17 files changed

Lines changed: 32 additions & 735 deletions

File tree

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -400,33 +400,6 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
400400
if len(universe_domain.strip()) == 0:
401401
raise ValueError("Universe Domain cannot be an empty string.")
402402
return universe_domain
403-
404-
@staticmethod
405-
def _compare_universes(client_universe: str,
406-
credentials: ga_credentials.Credentials) -> bool:
407-
"""Returns True iff the universe domains used by the client and credentials match.
408-
409-
Args:
410-
client_universe (str): The universe domain configured via the client options.
411-
credentials (ga_credentials.Credentials): The credentials being used in the client.
412-
413-
Returns:
414-
bool: True iff client_universe matches the universe in credentials.
415-
416-
Raises:
417-
ValueError: when client_universe does not match the universe in credentials.
418-
"""
419-
420-
default_universe = {{ service.client_name }}._DEFAULT_UNIVERSE
421-
credentials_universe = getattr(credentials, "universe_domain", default_universe)
422-
423-
if client_universe != credentials_universe:
424-
raise ValueError("The configured universe domain "
425-
f"({client_universe}) does not match the universe domain "
426-
f"found in the credentials ({credentials_universe}). "
427-
"If you haven't configured the universe domain explicitly, "
428-
f"`{default_universe}` is the default.")
429-
return True
430403

431404
def _validate_universe_domain(self):
432405
"""Validates client's and credentials' universe domains are consistent.
@@ -437,9 +410,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
437410
Raises:
438411
ValueError: If the configured universe domain is not valid.
439412
"""
440-
self._is_universe_domain_valid = (self._is_universe_domain_valid or
441-
{{ service.client_name }}._compare_universes(self.universe_domain, self.transport._credentials))
442-
return self._is_universe_domain_valid
413+
414+
# NOTE (b/349488459): universe validation is disabled until further notice.
415+
return True
443416

444417
@property
445418
def api_endpoint(self):

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -268,71 +268,6 @@ def test__get_universe_domain():
268268
{{ service.client_name }}._get_universe_domain("", None)
269269
assert str(excinfo.value) == "Universe Domain cannot be an empty string."
270270

271-
@pytest.mark.parametrize("client_class,transport_class,transport_name", [
272-
{% if 'grpc' in opts.transport %}
273-
({{ service.client_name }}, transports.{{ service.grpc_transport_name }}, "grpc"),
274-
{% endif %}
275-
{% if 'rest' in opts.transport %}
276-
({{ service.client_name }}, transports.{{ service.rest_transport_name }}, "rest"),
277-
{% endif %}
278-
])
279-
def test__validate_universe_domain(client_class, transport_class, transport_name):
280-
client = client_class(
281-
transport=transport_class(
282-
credentials=ga_credentials.AnonymousCredentials()
283-
)
284-
)
285-
assert client._validate_universe_domain() == True
286-
287-
# Test the case when universe is already validated.
288-
assert client._validate_universe_domain() == True
289-
290-
if transport_name == "grpc":
291-
# Test the case where credentials are provided by the
292-
# `local_channel_credentials`. The default universes in both match.
293-
channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())
294-
client = client_class(transport=transport_class(channel=channel))
295-
assert client._validate_universe_domain() == True
296-
297-
# Test the case where credentials do not exist: e.g. a transport is provided
298-
# with no credentials. Validation should still succeed because there is no
299-
# mismatch with non-existent credentials.
300-
channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())
301-
transport=transport_class(channel=channel)
302-
transport._credentials = None
303-
client = client_class(transport=transport)
304-
assert client._validate_universe_domain() == True
305-
306-
# TODO: This is needed to cater for older versions of google-auth
307-
# Make this test unconditional once the minimum supported version of
308-
# google-auth becomes 2.23.0 or higher.
309-
google_auth_major, google_auth_minor = [int(part) for part in google.auth.__version__.split(".")[0:2]]
310-
if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23):
311-
credentials = ga_credentials.AnonymousCredentials()
312-
credentials._universe_domain = "foo.com"
313-
# Test the case when there is a universe mismatch from the credentials.
314-
client = client_class(
315-
transport=transport_class(credentials=credentials)
316-
)
317-
with pytest.raises(ValueError) as excinfo:
318-
client._validate_universe_domain()
319-
assert str(excinfo.value) == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
320-
321-
# Test the case when there is a universe mismatch from the client.
322-
#
323-
# TODO: Make this test unconditional once the minimum supported version of
324-
# google-api-core becomes 2.15.0 or higher.
325-
api_core_major, api_core_minor = [int(part) for part in api_core_version.__version__.split(".")[0:2]]
326-
if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15):
327-
client = client_class(client_options={"universe_domain": "bar.com"}, transport=transport_class(credentials=ga_credentials.AnonymousCredentials(),))
328-
with pytest.raises(ValueError) as excinfo:
329-
client._validate_universe_domain()
330-
assert str(excinfo.value) == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
331-
332-
# Test that ValueError is raised if universe_domain is provided via client options and credentials is None
333-
with pytest.raises(ValueError):
334-
client._compare_universes("foo.bar", None)
335-
336271

337272
@pytest.mark.parametrize("client_class,transport_name", [
338273
{% if 'grpc' in opts.transport %}

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -460,33 +460,6 @@ def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_
460460
raise ValueError("Universe Domain cannot be an empty string.")
461461
return universe_domain
462462

463-
@staticmethod
464-
def _compare_universes(client_universe: str,
465-
credentials: ga_credentials.Credentials) -> bool:
466-
"""Returns True iff the universe domains used by the client and credentials match.
467-
468-
Args:
469-
client_universe (str): The universe domain configured via the client options.
470-
credentials (ga_credentials.Credentials): The credentials being used in the client.
471-
472-
Returns:
473-
bool: True iff client_universe matches the universe in credentials.
474-
475-
Raises:
476-
ValueError: when client_universe does not match the universe in credentials.
477-
"""
478-
479-
default_universe = AssetServiceClient._DEFAULT_UNIVERSE
480-
credentials_universe = getattr(credentials, "universe_domain", default_universe)
481-
482-
if client_universe != credentials_universe:
483-
raise ValueError("The configured universe domain "
484-
f"({client_universe}) does not match the universe domain "
485-
f"found in the credentials ({credentials_universe}). "
486-
"If you haven't configured the universe domain explicitly, "
487-
f"`{default_universe}` is the default.")
488-
return True
489-
490463
def _validate_universe_domain(self):
491464
"""Validates client's and credentials' universe domains are consistent.
492465
@@ -496,9 +469,9 @@ def _validate_universe_domain(self):
496469
Raises:
497470
ValueError: If the configured universe domain is not valid.
498471
"""
499-
self._is_universe_domain_valid = (self._is_universe_domain_valid or
500-
AssetServiceClient._compare_universes(self.universe_domain, self.transport._credentials))
501-
return self._is_universe_domain_valid
472+
473+
# NOTE (b/349488459): universe validation is disabled until further notice.
474+
return True
502475

503476
@property
504477
def api_endpoint(self):

packages/gapic-generator/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -192,67 +192,6 @@ def test__get_universe_domain():
192192
AssetServiceClient._get_universe_domain("", None)
193193
assert str(excinfo.value) == "Universe Domain cannot be an empty string."
194194

195-
@pytest.mark.parametrize("client_class,transport_class,transport_name", [
196-
(AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"),
197-
(AssetServiceClient, transports.AssetServiceRestTransport, "rest"),
198-
])
199-
def test__validate_universe_domain(client_class, transport_class, transport_name):
200-
client = client_class(
201-
transport=transport_class(
202-
credentials=ga_credentials.AnonymousCredentials()
203-
)
204-
)
205-
assert client._validate_universe_domain() == True
206-
207-
# Test the case when universe is already validated.
208-
assert client._validate_universe_domain() == True
209-
210-
if transport_name == "grpc":
211-
# Test the case where credentials are provided by the
212-
# `local_channel_credentials`. The default universes in both match.
213-
channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())
214-
client = client_class(transport=transport_class(channel=channel))
215-
assert client._validate_universe_domain() == True
216-
217-
# Test the case where credentials do not exist: e.g. a transport is provided
218-
# with no credentials. Validation should still succeed because there is no
219-
# mismatch with non-existent credentials.
220-
channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())
221-
transport=transport_class(channel=channel)
222-
transport._credentials = None
223-
client = client_class(transport=transport)
224-
assert client._validate_universe_domain() == True
225-
226-
# TODO: This is needed to cater for older versions of google-auth
227-
# Make this test unconditional once the minimum supported version of
228-
# google-auth becomes 2.23.0 or higher.
229-
google_auth_major, google_auth_minor = [int(part) for part in google.auth.__version__.split(".")[0:2]]
230-
if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23):
231-
credentials = ga_credentials.AnonymousCredentials()
232-
credentials._universe_domain = "foo.com"
233-
# Test the case when there is a universe mismatch from the credentials.
234-
client = client_class(
235-
transport=transport_class(credentials=credentials)
236-
)
237-
with pytest.raises(ValueError) as excinfo:
238-
client._validate_universe_domain()
239-
assert str(excinfo.value) == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
240-
241-
# Test the case when there is a universe mismatch from the client.
242-
#
243-
# TODO: Make this test unconditional once the minimum supported version of
244-
# google-api-core becomes 2.15.0 or higher.
245-
api_core_major, api_core_minor = [int(part) for part in api_core_version.__version__.split(".")[0:2]]
246-
if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15):
247-
client = client_class(client_options={"universe_domain": "bar.com"}, transport=transport_class(credentials=ga_credentials.AnonymousCredentials(),))
248-
with pytest.raises(ValueError) as excinfo:
249-
client._validate_universe_domain()
250-
assert str(excinfo.value) == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
251-
252-
# Test that ValueError is raised if universe_domain is provided via client options and credentials is None
253-
with pytest.raises(ValueError):
254-
client._compare_universes("foo.bar", None)
255-
256195

257196
@pytest.mark.parametrize("client_class,transport_name", [
258197
(AssetServiceClient, "grpc"),

packages/gapic-generator/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -397,33 +397,6 @@ def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_
397397
raise ValueError("Universe Domain cannot be an empty string.")
398398
return universe_domain
399399

400-
@staticmethod
401-
def _compare_universes(client_universe: str,
402-
credentials: ga_credentials.Credentials) -> bool:
403-
"""Returns True iff the universe domains used by the client and credentials match.
404-
405-
Args:
406-
client_universe (str): The universe domain configured via the client options.
407-
credentials (ga_credentials.Credentials): The credentials being used in the client.
408-
409-
Returns:
410-
bool: True iff client_universe matches the universe in credentials.
411-
412-
Raises:
413-
ValueError: when client_universe does not match the universe in credentials.
414-
"""
415-
416-
default_universe = IAMCredentialsClient._DEFAULT_UNIVERSE
417-
credentials_universe = getattr(credentials, "universe_domain", default_universe)
418-
419-
if client_universe != credentials_universe:
420-
raise ValueError("The configured universe domain "
421-
f"({client_universe}) does not match the universe domain "
422-
f"found in the credentials ({credentials_universe}). "
423-
"If you haven't configured the universe domain explicitly, "
424-
f"`{default_universe}` is the default.")
425-
return True
426-
427400
def _validate_universe_domain(self):
428401
"""Validates client's and credentials' universe domains are consistent.
429402
@@ -433,9 +406,9 @@ def _validate_universe_domain(self):
433406
Raises:
434407
ValueError: If the configured universe domain is not valid.
435408
"""
436-
self._is_universe_domain_valid = (self._is_universe_domain_valid or
437-
IAMCredentialsClient._compare_universes(self.universe_domain, self.transport._credentials))
438-
return self._is_universe_domain_valid
409+
410+
# NOTE (b/349488459): universe validation is disabled until further notice.
411+
return True
439412

440413
@property
441414
def api_endpoint(self):

packages/gapic-generator/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -182,67 +182,6 @@ def test__get_universe_domain():
182182
IAMCredentialsClient._get_universe_domain("", None)
183183
assert str(excinfo.value) == "Universe Domain cannot be an empty string."
184184

185-
@pytest.mark.parametrize("client_class,transport_class,transport_name", [
186-
(IAMCredentialsClient, transports.IAMCredentialsGrpcTransport, "grpc"),
187-
(IAMCredentialsClient, transports.IAMCredentialsRestTransport, "rest"),
188-
])
189-
def test__validate_universe_domain(client_class, transport_class, transport_name):
190-
client = client_class(
191-
transport=transport_class(
192-
credentials=ga_credentials.AnonymousCredentials()
193-
)
194-
)
195-
assert client._validate_universe_domain() == True
196-
197-
# Test the case when universe is already validated.
198-
assert client._validate_universe_domain() == True
199-
200-
if transport_name == "grpc":
201-
# Test the case where credentials are provided by the
202-
# `local_channel_credentials`. The default universes in both match.
203-
channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())
204-
client = client_class(transport=transport_class(channel=channel))
205-
assert client._validate_universe_domain() == True
206-
207-
# Test the case where credentials do not exist: e.g. a transport is provided
208-
# with no credentials. Validation should still succeed because there is no
209-
# mismatch with non-existent credentials.
210-
channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())
211-
transport=transport_class(channel=channel)
212-
transport._credentials = None
213-
client = client_class(transport=transport)
214-
assert client._validate_universe_domain() == True
215-
216-
# TODO: This is needed to cater for older versions of google-auth
217-
# Make this test unconditional once the minimum supported version of
218-
# google-auth becomes 2.23.0 or higher.
219-
google_auth_major, google_auth_minor = [int(part) for part in google.auth.__version__.split(".")[0:2]]
220-
if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23):
221-
credentials = ga_credentials.AnonymousCredentials()
222-
credentials._universe_domain = "foo.com"
223-
# Test the case when there is a universe mismatch from the credentials.
224-
client = client_class(
225-
transport=transport_class(credentials=credentials)
226-
)
227-
with pytest.raises(ValueError) as excinfo:
228-
client._validate_universe_domain()
229-
assert str(excinfo.value) == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
230-
231-
# Test the case when there is a universe mismatch from the client.
232-
#
233-
# TODO: Make this test unconditional once the minimum supported version of
234-
# google-api-core becomes 2.15.0 or higher.
235-
api_core_major, api_core_minor = [int(part) for part in api_core_version.__version__.split(".")[0:2]]
236-
if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15):
237-
client = client_class(client_options={"universe_domain": "bar.com"}, transport=transport_class(credentials=ga_credentials.AnonymousCredentials(),))
238-
with pytest.raises(ValueError) as excinfo:
239-
client._validate_universe_domain()
240-
assert str(excinfo.value) == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
241-
242-
# Test that ValueError is raised if universe_domain is provided via client options and credentials is None
243-
with pytest.raises(ValueError):
244-
client._compare_universes("foo.bar", None)
245-
246185

247186
@pytest.mark.parametrize("client_class,transport_name", [
248187
(IAMCredentialsClient, "grpc"),

0 commit comments

Comments
 (0)