From f0666d9729139c639ea7e60686d269dd3393b06d Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Wed, 18 May 2022 12:03:14 -0700 Subject: [PATCH] feat: adds support for audience in client_options (#379) feat: adds support for audience in client_options. --- google/api_core/client_options.py | 7 +++++++ tests/unit/test_client_options.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py index bffb306f..0d9afc39 100644 --- a/google/api_core/client_options.py +++ b/google/api_core/client_options.py @@ -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". Raises: ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source`` @@ -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( @@ -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__) diff --git a/tests/unit/test_client_options.py b/tests/unit/test_client_options.py index fbff5457..40edcc19 100644 --- a/tests/unit/test_client_options.py +++ b/tests/unit/test_client_options.py @@ -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" @@ -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(): @@ -113,6 +115,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", } ) @@ -125,6 +128,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():