Skip to content

Commit 3ce36bf

Browse files
committed
refactor(api-core): import get_universe_domain from universe.py instead of local definition
1 parent 26e7820 commit 3ce36bf

2 files changed

Lines changed: 2 additions & 64 deletions

File tree

packages/google-api-core/google/api_core/gapic_v1/client_utils.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from google.auth.exceptions import MutualTLSChannelError # type: ignore
2020

21+
from google.api_core.universe import get_universe_domain # noqa: F401
22+
2123

2224
def get_default_mtls_endpoint(api_endpoint: Optional[str]) -> Optional[str]:
2325
"""Converts api endpoint to mTLS endpoint.
@@ -106,29 +108,3 @@ def get_api_endpoint(
106108
return default_mtls_endpoint
107109
else:
108110
return default_endpoint_template.format(UNIVERSE_DOMAIN=universe_domain)
109-
110-
111-
def get_universe_domain(
112-
*potential_universes: Optional[str],
113-
default_universe: str = "googleapis.com",
114-
) -> str:
115-
"""Return the universe domain used by the client.
116-
117-
Args:
118-
*potential_universes (Optional[str]): Potential universe domains in order of preference.
119-
default_universe (str): The default universe domain.
120-
121-
Returns:
122-
str: The universe domain to be used by the client.
123-
124-
Raises:
125-
ValueError: If the resolved universe domain is an empty string.
126-
"""
127-
resolved = next(
128-
(x.strip() for x in potential_universes if x is not None),
129-
default_universe,
130-
)
131-
132-
if not resolved:
133-
raise ValueError("Universe Domain cannot be an empty string.")
134-
return resolved

packages/google-api-core/tests/unit/gapic/test_client_utils.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from google.api_core.gapic_v1.client_utils import (
1919
get_api_endpoint,
2020
get_default_mtls_endpoint,
21-
get_universe_domain,
2221
)
2322

2423

@@ -160,40 +159,3 @@ def test_get_api_endpoint(
160159
)
161160
== expected
162161
)
163-
164-
165-
def test_get_universe_domain():
166-
# When universe_domain is provided
167-
assert get_universe_domain("foo.com", default_universe="default.com") == "foo.com"
168-
assert (
169-
get_universe_domain(" foo.com ", default_universe="default.com") == "foo.com"
170-
)
171-
172-
# When universe_domain is None, falls back to default_universe
173-
assert get_universe_domain(None, default_universe="default.com") == "default.com"
174-
175-
# When multiple potential universes are provided, resolves in order of preference
176-
assert (
177-
get_universe_domain("foo.com", "bar.com", default_universe="default.com")
178-
== "foo.com"
179-
)
180-
assert (
181-
get_universe_domain(None, "bar.com", default_universe="default.com")
182-
== "bar.com"
183-
)
184-
assert (
185-
get_universe_domain(None, None, default_universe="default.com") == "default.com"
186-
)
187-
188-
# ValueError raised when resolved value is empty string
189-
with pytest.raises(ValueError) as excinfo:
190-
get_universe_domain("", default_universe="default.com")
191-
assert str(excinfo.value) == "Universe Domain cannot be an empty string."
192-
193-
with pytest.raises(ValueError) as excinfo:
194-
get_universe_domain(" ", default_universe="default.com")
195-
assert str(excinfo.value) == "Universe Domain cannot be an empty string."
196-
197-
with pytest.raises(ValueError) as excinfo:
198-
get_universe_domain(None, "", default_universe="default.com")
199-
assert str(excinfo.value) == "Universe Domain cannot be an empty string."

0 commit comments

Comments
 (0)