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

Commit af598f0

Browse files
fix(deps): require google-api-core >= 2.8.0 (#154)
- [ ] 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 57b848a commit af598f0

File tree

8 files changed

+70
-34
lines changed

8 files changed

+70
-34
lines changed

google/cloud/apigateway_v1/services/api_gateway_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def __init__(
526526
quota_project_id=client_options.quota_project_id,
527527
client_info=client_info,
528528
always_use_jwt_access=True,
529+
api_audience=client_options.api_audience,
529530
)
530531

531532
def list_gateways(

google/cloud/apigateway_v1/services/api_gateway_service/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/apigateway_v1/services/api_gateway_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6161
always_use_jwt_access: Optional[bool] = False,
62+
api_audience: Optional[str] = None,
6263
) -> None:
6364
"""Instantiate the transport.
6465
@@ -155,6 +156,7 @@ def __init__(
155156
quota_project_id=quota_project_id,
156157
client_info=client_info,
157158
always_use_jwt_access=always_use_jwt_access,
159+
api_audience=api_audience,
158160
)
159161

160162
if not self._grpc_channel:

google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(
104104
quota_project_id=None,
105105
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
106106
always_use_jwt_access: Optional[bool] = False,
107+
api_audience: Optional[str] = None,
107108
) -> None:
108109
"""Instantiate the transport.
109110
@@ -200,6 +201,7 @@ def __init__(
200201
quota_project_id=quota_project_id,
201202
client_info=client_info,
202203
always_use_jwt_access=always_use_jwt_access,
204+
api_audience=api_audience,
203205
)
204206

205207
if not self._grpc_channel:

setup.py

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

testing/constraints-3.6.txt

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

testing/constraints-3.7.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
#
2020
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
2121
# Then this file should have foo==1.14.0
22-
google-api-core==1.31.5
22+
google-api-core==2.8.0
2323
proto-plus==1.15.0
2424
protobuf==3.19.0

tests/unit/gapic/apigateway_v1/test_api_gateway_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def test_api_gateway_service_client_client_options(
240240
quota_project_id=None,
241241
client_info=transports.base.DEFAULT_CLIENT_INFO,
242242
always_use_jwt_access=True,
243+
api_audience=None,
243244
)
244245

245246
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -257,6 +258,7 @@ def test_api_gateway_service_client_client_options(
257258
quota_project_id=None,
258259
client_info=transports.base.DEFAULT_CLIENT_INFO,
259260
always_use_jwt_access=True,
261+
api_audience=None,
260262
)
261263

262264
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -274,6 +276,7 @@ def test_api_gateway_service_client_client_options(
274276
quota_project_id=None,
275277
client_info=transports.base.DEFAULT_CLIENT_INFO,
276278
always_use_jwt_access=True,
279+
api_audience=None,
277280
)
278281

279282
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -303,6 +306,25 @@ def test_api_gateway_service_client_client_options(
303306
quota_project_id="octopus",
304307
client_info=transports.base.DEFAULT_CLIENT_INFO,
305308
always_use_jwt_access=True,
309+
api_audience=None,
310+
)
311+
# Check the case api_endpoint is provided
312+
options = client_options.ClientOptions(
313+
api_audience="https://language.googleapis.com"
314+
)
315+
with mock.patch.object(transport_class, "__init__") as patched:
316+
patched.return_value = None
317+
client = client_class(client_options=options, transport=transport_name)
318+
patched.assert_called_once_with(
319+
credentials=None,
320+
credentials_file=None,
321+
host=client.DEFAULT_ENDPOINT,
322+
scopes=None,
323+
client_cert_source_for_mtls=None,
324+
quota_project_id=None,
325+
client_info=transports.base.DEFAULT_CLIENT_INFO,
326+
always_use_jwt_access=True,
327+
api_audience="https://language.googleapis.com",
306328
)
307329

308330

@@ -380,6 +402,7 @@ def test_api_gateway_service_client_mtls_env_auto(
380402
quota_project_id=None,
381403
client_info=transports.base.DEFAULT_CLIENT_INFO,
382404
always_use_jwt_access=True,
405+
api_audience=None,
383406
)
384407

385408
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -414,6 +437,7 @@ def test_api_gateway_service_client_mtls_env_auto(
414437
quota_project_id=None,
415438
client_info=transports.base.DEFAULT_CLIENT_INFO,
416439
always_use_jwt_access=True,
440+
api_audience=None,
417441
)
418442

419443
# Check the case client_cert_source and ADC client cert are not provided.
@@ -436,6 +460,7 @@ def test_api_gateway_service_client_mtls_env_auto(
436460
quota_project_id=None,
437461
client_info=transports.base.DEFAULT_CLIENT_INFO,
438462
always_use_jwt_access=True,
463+
api_audience=None,
439464
)
440465

441466

@@ -550,6 +575,7 @@ def test_api_gateway_service_client_client_options_scopes(
550575
quota_project_id=None,
551576
client_info=transports.base.DEFAULT_CLIENT_INFO,
552577
always_use_jwt_access=True,
578+
api_audience=None,
553579
)
554580

555581

@@ -588,6 +614,7 @@ def test_api_gateway_service_client_client_options_credentials_file(
588614
quota_project_id=None,
589615
client_info=transports.base.DEFAULT_CLIENT_INFO,
590616
always_use_jwt_access=True,
617+
api_audience=None,
591618
)
592619

593620

@@ -608,6 +635,7 @@ def test_api_gateway_service_client_client_options_from_dict():
608635
quota_project_id=None,
609636
client_info=transports.base.DEFAULT_CLIENT_INFO,
610637
always_use_jwt_access=True,
638+
api_audience=None,
611639
)
612640

613641

@@ -646,6 +674,7 @@ def test_api_gateway_service_client_create_channel_credentials_file(
646674
quota_project_id=None,
647675
client_info=transports.base.DEFAULT_CLIENT_INFO,
648676
always_use_jwt_access=True,
677+
api_audience=None,
649678
)
650679

651680
# test that the credentials from file are saved and used as the credentials.
@@ -5085,6 +5114,28 @@ def test_api_gateway_service_transport_auth_adc(transport_class):
50855114
)
50865115

50875116

5117+
@pytest.mark.parametrize(
5118+
"transport_class",
5119+
[
5120+
transports.ApiGatewayServiceGrpcTransport,
5121+
transports.ApiGatewayServiceGrpcAsyncIOTransport,
5122+
],
5123+
)
5124+
def test_api_gateway_service_transport_auth_gdch_credentials(transport_class):
5125+
host = "https://language.com"
5126+
api_audience_tests = [None, "https://language2.com"]
5127+
api_audience_expect = [host, "https://language2.com"]
5128+
for t, e in zip(api_audience_tests, api_audience_expect):
5129+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
5130+
gdch_mock = mock.MagicMock()
5131+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
5132+
return_value=gdch_mock
5133+
)
5134+
adc.return_value = (gdch_mock, None)
5135+
transport_class(host=host, api_audience=t)
5136+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
5137+
5138+
50885139
@pytest.mark.parametrize(
50895140
"transport_class,grpc_helpers",
50905141
[
@@ -5709,4 +5760,5 @@ def test_api_key_credentials(client_class, transport_class):
57095760
quota_project_id=None,
57105761
client_info=transports.base.DEFAULT_CLIENT_INFO,
57115762
always_use_jwt_access=True,
5763+
api_audience=None,
57125764
)

0 commit comments

Comments
 (0)