From 5478ec8dedecda61bf615d0e5dfc5eaf010cc9fd Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Fri, 13 May 2022 21:07:28 -0700 Subject: [PATCH 1/3] feat: adds support for audience in client_options. --- google/api_core/client_options.py | 2 ++ tests/unit/test_client_options.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py index 4a2a84a4..b251d9e7 100644 --- a/google/api_core/client_options.py +++ b/google/api_core/client_options.py @@ -85,6 +85,7 @@ def __init__( credentials_file=None, scopes=None, api_key=None, + audience=None, ): if client_cert_source and client_encrypted_cert_source: raise ValueError( @@ -99,6 +100,7 @@ def __init__( self.credentials_file = credentials_file self.scopes = scopes self.api_key = api_key + self.audience = 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 334b8c1f..2c45054b 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", ], + 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.audience == "foo2.googleapis.com" def test_constructor_with_encrypted_cert_source(): @@ -114,6 +116,7 @@ def test_from_dict(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ], + "audience": "foo2.googleapis.com", } ) @@ -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.audience == "foo2.googleapis.com" def test_from_dict_bad_argument(): From 68d14a6f725d10735f17010a144e7e17ea6e5a77 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Fri, 13 May 2022 21:11:42 -0700 Subject: [PATCH 2/3] chore: adds docstring for audience. --- google/api_core/client_options.py | 1 + 1 file changed, 1 insertion(+) diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py index b251d9e7..b62321c9 100644 --- a/google/api_core/client_options.py +++ b/google/api_core/client_options.py @@ -70,6 +70,7 @@ 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. + audience (Optional[str]): The desired API audience. Raises: ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source`` From 788c7042842c4caa34083b4cf575780933fda2dd Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Tue, 17 May 2022 13:29:15 -0700 Subject: [PATCH 3/3] chore: address pr feedback. --- google/api_core/client_options.py | 10 +++++++--- tests/unit/test_client_options.py | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py index b62321c9..ee9f28a9 100644 --- a/google/api_core/client_options.py +++ b/google/api_core/client_options.py @@ -70,7 +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. - audience (Optional[str]): The desired API audience. + 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`` @@ -86,7 +90,7 @@ def __init__( credentials_file=None, scopes=None, api_key=None, - audience=None, + api_audience=None, ): if client_cert_source and client_encrypted_cert_source: raise ValueError( @@ -101,7 +105,7 @@ def __init__( self.credentials_file = credentials_file self.scopes = scopes self.api_key = api_key - self.audience = audience + 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 2c45054b..d56a1b3a 100644 --- a/tests/unit/test_client_options.py +++ b/tests/unit/test_client_options.py @@ -36,7 +36,7 @@ def test_constructor(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ], - audience="foo2.googleapis.com", + api_audience="foo2.googleapis.com", ) assert options.api_endpoint == "foo.googleapis.com" @@ -47,7 +47,7 @@ def test_constructor(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ] - assert options.audience == "foo2.googleapis.com" + assert options.api_audience == "foo2.googleapis.com" def test_constructor_with_encrypted_cert_source(): @@ -116,7 +116,7 @@ def test_from_dict(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ], - "audience": "foo2.googleapis.com", + "api_audience": "foo2.googleapis.com", } ) @@ -129,7 +129,7 @@ def test_from_dict(): "https://www.googleapis.com/auth/cloud-platform.read-only", ] assert options.api_key is None - assert options.audience == "foo2.googleapis.com" + assert options.api_audience == "foo2.googleapis.com" def test_from_dict_bad_argument():