Skip to content
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

feat: adds support for audience in client_options #379

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions google/api_core/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class ClientOptions(object):
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".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

language.googleapis.com is used as an example here.


Raises:
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
Expand All @@ -85,6 +90,7 @@ def __init__(
credentials_file=None,
scopes=None,
api_key=None,
api_audience=None,
):
if client_cert_source and client_encrypted_cert_source:
raise ValueError(
Expand All @@ -99,6 +105,7 @@ def __init__(
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
4 changes: 4 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 @@ -114,6 +116,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 @@ -126,6 +129,7 @@ def test_from_dict():
"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