Skip to content

Commit 2556b7d

Browse files
atulepparthea
authored andcommitted
feat: adds support for audience in client_options (#379)
feat: adds support for audience in client_options.
1 parent 1e2f148 commit 2556b7d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

google/api_core/client_options.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class ClientOptions(object):
6767
quota belongs to.
6868
credentials_file (Optional[str]): A path to a file storing credentials.
6969
scopes (Optional[Sequence[str]]): OAuth access token override scopes.
70+
api_key (Optional[str]): Google API key. ``credentials_file`` and
71+
``api_key`` are mutually exclusive.
72+
api_audience (Optional[str]): The intended audience for the API calls
73+
to the service that will be set when using certain 3rd party
74+
authentication flows. Audience is typically a resource identifier.
75+
If not set, the service endpoint value will be used as a default.
76+
An example of a valid ``api_audience`` is: "https://language.googleapis.com".
7077
7178
Raises:
7279
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
@@ -81,6 +88,8 @@ def __init__(
8188
quota_project_id=None,
8289
credentials_file=None,
8390
scopes=None,
91+
api_key=None,
92+
api_audience=None,
8493
):
8594
if client_cert_source and client_encrypted_cert_source:
8695
raise ValueError(
@@ -92,6 +101,8 @@ def __init__(
92101
self.quota_project_id = quota_project_id
93102
self.credentials_file = credentials_file
94103
self.scopes = scopes
104+
self.api_key = api_key
105+
self.api_audience = api_audience
95106

96107
def __repr__(self):
97108
return "ClientOptions: " + repr(self.__dict__)

tests/unit/test_client_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_constructor():
3636
"https://www.googleapis.com/auth/cloud-platform",
3737
"https://www.googleapis.com/auth/cloud-platform.read-only",
3838
],
39+
api_audience="foo2.googleapis.com",
3940
)
4041

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

5052

5153
def test_constructor_with_encrypted_cert_source():
@@ -83,6 +85,7 @@ def test_from_dict():
8385
"https://www.googleapis.com/auth/cloud-platform",
8486
"https://www.googleapis.com/auth/cloud-platform.read-only",
8587
],
88+
"api_audience": "foo2.googleapis.com",
8689
}
8790
)
8891

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

98103

99104
def test_from_dict_bad_argument():

0 commit comments

Comments
 (0)