Skip to content

Commit

Permalink
feat: adds support for audience in client_options (#379)
Browse files Browse the repository at this point in the history
feat: adds support for audience in client_options.
  • Loading branch information
atulep authored and parthea committed Jul 13, 2022
1 parent 1e2f148 commit 2556b7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions google/api_core/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class ClientOptions(object):
quota belongs to.
credentials_file (Optional[str]): A path to a file storing credentials.
scopes (Optional[Sequence[str]]): OAuth access token override scopes.
api_key (Optional[str]): Google API key. ``credentials_file`` and
``api_key`` are mutually exclusive.
api_audience (Optional[str]): The intended audience for the API calls
to the service that will be set when using certain 3rd party
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".
Raises:
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
Expand All @@ -81,6 +88,8 @@ def __init__(
quota_project_id=None,
credentials_file=None,
scopes=None,
api_key=None,
api_audience=None,
):
if client_cert_source and client_encrypted_cert_source:
raise ValueError(
Expand All @@ -92,6 +101,8 @@ def __init__(
self.quota_project_id = quota_project_id
self.credentials_file = credentials_file
self.scopes = scopes
self.api_key = api_key
self.api_audience = api_audience

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 @@ -36,6 +36,7 @@ def test_constructor():
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
api_audience="foo2.googleapis.com",
)

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


def test_constructor_with_encrypted_cert_source():
Expand Down Expand Up @@ -83,6 +85,7 @@ def test_from_dict():
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
"api_audience": "foo2.googleapis.com",
}
)

Expand All @@ -94,6 +97,8 @@ def test_from_dict():
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
]
assert options.api_key is None
assert options.api_audience == "foo2.googleapis.com"


def test_from_dict_bad_argument():
Expand Down

0 comments on commit 2556b7d

Please sign in to comment.