Skip to content

feat: add universe_domain argument to ClientOptions #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 20, 2023
7 changes: 7 additions & 0 deletions google/api_core/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class ClientOptions(object):
authentication flows. Audience is typically a resource identifier.
If not set, the service endpoint value will be used as a default.
An example of a valid ``api_audience`` is: "https://language.googleapis.com".
universe_domain (Optional[str]): The desired universe domain. This must match
the one in credentials. If not set, the default universe domain is
`googleapis.com`. If both `api_endpoint` and `universe_domain` are set,
then `api_endpoint` is used as the service endpoint. If `api_endpoint` is
not specified, the format will be `{service}.{universe_domain}`.

Raises:
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
Expand All @@ -91,6 +96,7 @@ def __init__(
scopes=None,
api_key=None,
api_audience=None,
universe_domain=None,
):
if client_cert_source and client_encrypted_cert_source:
raise ValueError(
Expand All @@ -106,6 +112,7 @@ def __init__(
self.scopes = scopes
self.api_key = api_key
self.api_audience = api_audience
self.universe_domain = universe_domain

def __repr__(self):
return "ClientOptions: " + repr(self.__dict__)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_constructor():
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
api_audience="foo2.googleapis.com",
universe_domain="googleapis.com",
)

assert options.api_endpoint == "foo.googleapis.com"
Expand All @@ -49,6 +50,7 @@ def test_constructor():
"https://www.googleapis.com/auth/cloud-platform.read-only",
]
assert options.api_audience == "foo2.googleapis.com"
assert options.universe_domain == "googleapis.com"


def test_constructor_with_encrypted_cert_source():
Expand Down Expand Up @@ -110,6 +112,7 @@ def test_from_dict():
options = client_options.from_dict(
{
"api_endpoint": "foo.googleapis.com",
"universe_domain": "googleapis.com",
"client_cert_source": get_client_cert,
"quota_project_id": "quote-proj",
"credentials_file": "path/to/credentials.json",
Expand All @@ -122,6 +125,7 @@ def test_from_dict():
)

assert options.api_endpoint == "foo.googleapis.com"
assert options.universe_domain == "googleapis.com"
assert options.client_cert_source() == (b"cert", b"key")
assert options.quota_project_id == "quote-proj"
assert options.credentials_file == "path/to/credentials.json"
Expand All @@ -148,6 +152,7 @@ def test_repr():
expected_keys = set(
[
"api_endpoint",
"universe_domain",
"client_cert_source",
"client_encrypted_cert_source",
"quota_project_id",
Expand Down