Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 6f977e1

Browse files
fix(deps): require google-api-core >= 2.8.0 (#59)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 459095142 Source-Link: googleapis/googleapis@4f1be99 Source-Link: https://github.com/googleapis/googleapis-gen/commit/ae686d9cde4fc3e36d0ac02efb8643b15890c1ed Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWU2ODZkOWNkZTRmYzNlMzZkMGFjMDJlZmI4NjQzYjE1ODkwYzFlZCJ9 feat: add audience parameter PiperOrigin-RevId: 456827138 Source-Link: googleapis/googleapis@23f1a15 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4075a8514f676691ec156688a5bbf183aa9893ce Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDA3NWE4NTE0ZjY3NjY5MWVjMTU2Njg4YTViYmYxODNhYTk4OTNjZSJ9
1 parent 62079cc commit 6f977e1

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

google/cloud/ids_v1/services/ids/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ def __init__(
428428
quota_project_id=client_options.quota_project_id,
429429
client_info=client_info,
430430
always_use_jwt_access=True,
431+
api_audience=client_options.api_audience,
431432
)
432433

433434
def list_endpoints(

google/cloud/ids_v1/services/ids/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(
5555
quota_project_id: Optional[str] = None,
5656
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
5757
always_use_jwt_access: Optional[bool] = False,
58+
api_audience: Optional[str] = None,
5859
**kwargs,
5960
) -> None:
6061
"""Instantiate the transport.
@@ -82,11 +83,6 @@ def __init__(
8283
be used for service account credentials.
8384
"""
8485

85-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
86-
if ":" not in host:
87-
host += ":443"
88-
self._host = host
89-
9086
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9187

9288
# Save the scopes.
@@ -107,6 +103,11 @@ def __init__(
107103
credentials, _ = google.auth.default(
108104
**scopes_kwargs, quota_project_id=quota_project_id
109105
)
106+
# Don't apply audience if the credentials file passed from user.
107+
if hasattr(credentials, "with_gdch_audience"):
108+
credentials = credentials.with_gdch_audience(
109+
api_audience if api_audience else host
110+
)
110111

111112
# If the credentials are service account credentials, then always try to use self signed JWT.
112113
if (
@@ -119,6 +120,11 @@ def __init__(
119120
# Save the credentials.
120121
self._credentials = credentials
121122

123+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
124+
if ":" not in host:
125+
host += ":443"
126+
self._host = host
127+
122128
def _prep_wrapped_messages(self, client_info):
123129
# Precompute the wrapped methods.
124130
self._wrapped_methods = {

google/cloud/ids_v1/services/ids/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
quota_project_id: Optional[str] = None,
5959
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6060
always_use_jwt_access: Optional[bool] = False,
61+
api_audience: Optional[str] = None,
6162
) -> None:
6263
"""Instantiate the transport.
6364
@@ -154,6 +155,7 @@ def __init__(
154155
quota_project_id=quota_project_id,
155156
client_info=client_info,
156157
always_use_jwt_access=always_use_jwt_access,
158+
api_audience=api_audience,
157159
)
158160

159161
if not self._grpc_channel:

google/cloud/ids_v1/services/ids/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(
103103
quota_project_id=None,
104104
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
105105
always_use_jwt_access: Optional[bool] = False,
106+
api_audience: Optional[str] = None,
106107
) -> None:
107108
"""Instantiate the transport.
108109
@@ -199,6 +200,7 @@ def __init__(
199200
quota_project_id=quota_project_id,
200201
client_info=client_info,
201202
always_use_jwt_access=always_use_jwt_access,
203+
api_audience=api_audience,
202204
)
203205

204206
if not self._grpc_channel:

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
url = "https://github.com/googleapis/python-ids"
2626
release_status = "Development Status :: 5 - Production/Stable"
2727
dependencies = [
28-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
29-
# Until this issue is closed
30-
# https://github.com/googleapis/google-cloud-python/issues/10566
31-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
28+
"google-api-core[grpc] >= 2.8.0, <3.0.0dev",
3229
"proto-plus >= 1.15.0, <2.0.0dev",
3330
"protobuf >= 3.19.0, <4.0.0dev",
3431
]

testing/constraints-3.6.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

testing/constraints-3.7.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
# Pin the version to the lower bound.
55
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
66
# Then this file should have google-cloud-foo==1.14.0
7-
google-api-core==1.31.5
7+
google-api-core==2.8.0
88
proto-plus==1.15.0
99
protobuf==3.19.0

tests/unit/gapic/ids_v1/test_ids.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def test_ids_client_client_options(client_class, transport_class, transport_name
211211
quota_project_id=None,
212212
client_info=transports.base.DEFAULT_CLIENT_INFO,
213213
always_use_jwt_access=True,
214+
api_audience=None,
214215
)
215216

216217
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -228,6 +229,7 @@ def test_ids_client_client_options(client_class, transport_class, transport_name
228229
quota_project_id=None,
229230
client_info=transports.base.DEFAULT_CLIENT_INFO,
230231
always_use_jwt_access=True,
232+
api_audience=None,
231233
)
232234

233235
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -245,6 +247,7 @@ def test_ids_client_client_options(client_class, transport_class, transport_name
245247
quota_project_id=None,
246248
client_info=transports.base.DEFAULT_CLIENT_INFO,
247249
always_use_jwt_access=True,
250+
api_audience=None,
248251
)
249252

250253
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -274,6 +277,25 @@ def test_ids_client_client_options(client_class, transport_class, transport_name
274277
quota_project_id="octopus",
275278
client_info=transports.base.DEFAULT_CLIENT_INFO,
276279
always_use_jwt_access=True,
280+
api_audience=None,
281+
)
282+
# Check the case api_endpoint is provided
283+
options = client_options.ClientOptions(
284+
api_audience="https://language.googleapis.com"
285+
)
286+
with mock.patch.object(transport_class, "__init__") as patched:
287+
patched.return_value = None
288+
client = client_class(client_options=options, transport=transport_name)
289+
patched.assert_called_once_with(
290+
credentials=None,
291+
credentials_file=None,
292+
host=client.DEFAULT_ENDPOINT,
293+
scopes=None,
294+
client_cert_source_for_mtls=None,
295+
quota_project_id=None,
296+
client_info=transports.base.DEFAULT_CLIENT_INFO,
297+
always_use_jwt_access=True,
298+
api_audience="https://language.googleapis.com",
277299
)
278300

279301

@@ -325,6 +347,7 @@ def test_ids_client_mtls_env_auto(
325347
quota_project_id=None,
326348
client_info=transports.base.DEFAULT_CLIENT_INFO,
327349
always_use_jwt_access=True,
350+
api_audience=None,
328351
)
329352

330353
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -359,6 +382,7 @@ def test_ids_client_mtls_env_auto(
359382
quota_project_id=None,
360383
client_info=transports.base.DEFAULT_CLIENT_INFO,
361384
always_use_jwt_access=True,
385+
api_audience=None,
362386
)
363387

364388
# Check the case client_cert_source and ADC client cert are not provided.
@@ -381,6 +405,7 @@ def test_ids_client_mtls_env_auto(
381405
quota_project_id=None,
382406
client_info=transports.base.DEFAULT_CLIENT_INFO,
383407
always_use_jwt_access=True,
408+
api_audience=None,
384409
)
385410

386411

@@ -483,6 +508,7 @@ def test_ids_client_client_options_scopes(
483508
quota_project_id=None,
484509
client_info=transports.base.DEFAULT_CLIENT_INFO,
485510
always_use_jwt_access=True,
511+
api_audience=None,
486512
)
487513

488514

@@ -516,6 +542,7 @@ def test_ids_client_client_options_credentials_file(
516542
quota_project_id=None,
517543
client_info=transports.base.DEFAULT_CLIENT_INFO,
518544
always_use_jwt_access=True,
545+
api_audience=None,
519546
)
520547

521548

@@ -534,6 +561,7 @@ def test_ids_client_client_options_from_dict():
534561
quota_project_id=None,
535562
client_info=transports.base.DEFAULT_CLIENT_INFO,
536563
always_use_jwt_access=True,
564+
api_audience=None,
537565
)
538566

539567

@@ -567,6 +595,7 @@ def test_ids_client_create_channel_credentials_file(
567595
quota_project_id=None,
568596
client_info=transports.base.DEFAULT_CLIENT_INFO,
569597
always_use_jwt_access=True,
598+
api_audience=None,
570599
)
571600

572601
# test that the credentials from file are saved and used as the credentials.
@@ -1977,6 +2006,28 @@ def test_ids_transport_auth_adc(transport_class):
19772006
)
19782007

19792008

2009+
@pytest.mark.parametrize(
2010+
"transport_class",
2011+
[
2012+
transports.IDSGrpcTransport,
2013+
transports.IDSGrpcAsyncIOTransport,
2014+
],
2015+
)
2016+
def test_ids_transport_auth_gdch_credentials(transport_class):
2017+
host = "https://language.com"
2018+
api_audience_tests = [None, "https://language2.com"]
2019+
api_audience_expect = [host, "https://language2.com"]
2020+
for t, e in zip(api_audience_tests, api_audience_expect):
2021+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
2022+
gdch_mock = mock.MagicMock()
2023+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
2024+
return_value=gdch_mock
2025+
)
2026+
adc.return_value = (gdch_mock, None)
2027+
transport_class(host=host, api_audience=t)
2028+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
2029+
2030+
19802031
@pytest.mark.parametrize(
19812032
"transport_class,grpc_helpers",
19822033
[
@@ -2459,4 +2510,5 @@ def test_api_key_credentials(client_class, transport_class):
24592510
quota_project_id=None,
24602511
client_info=transports.base.DEFAULT_CLIENT_INFO,
24612512
always_use_jwt_access=True,
2513+
api_audience=None,
24622514
)

0 commit comments

Comments
 (0)