Skip to content

Commit

Permalink
feat: add universe_domain attribute to ClientOptions (#546)
Browse files Browse the repository at this point in the history
* feat: add universe_domain option for TPC

* test: update options to include universe domain

* update the docstring

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Update google/api_core/client_options.py

Co-authored-by: Anthonios Partheniou <partheniou@google.com>

* Update client_options.py

---------

Co-authored-by: omair <omairn@google.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
4 people committed Nov 20, 2023
1 parent fc12b40 commit 3069ef4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 3069ef4

Please sign in to comment.