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

Commit a7340c7

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#120)
- [ ] 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 79b43bd commit a7340c7

File tree

8 files changed

+78
-18
lines changed

8 files changed

+78
-18
lines changed

google/cloud/vpcaccess_v1/services/vpc_access_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def __init__(
432432
quota_project_id=client_options.quota_project_id,
433433
client_info=client_info,
434434
always_use_jwt_access=True,
435+
api_audience=client_options.api_audience,
435436
)
436437

437438
def create_connector(

google/cloud/vpcaccess_v1/services/vpc_access_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/vpcaccess_v1/services/vpc_access_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
quota_project_id: Optional[str] = None,
6161
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6262
always_use_jwt_access: Optional[bool] = False,
63+
api_audience: Optional[str] = None,
6364
) -> None:
6465
"""Instantiate the transport.
6566
@@ -156,6 +157,7 @@ def __init__(
156157
quota_project_id=quota_project_id,
157158
client_info=client_info,
158159
always_use_jwt_access=always_use_jwt_access,
160+
api_audience=api_audience,
159161
)
160162

161163
if not self._grpc_channel:

google/cloud/vpcaccess_v1/services/vpc_access_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
quota_project_id=None,
106106
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
107107
always_use_jwt_access: Optional[bool] = False,
108+
api_audience: Optional[str] = None,
108109
) -> None:
109110
"""Instantiate the transport.
110111
@@ -201,6 +202,7 @@ def __init__(
201202
quota_project_id=quota_project_id,
202203
client_info=client_info,
203204
always_use_jwt_access=always_use_jwt_access,
205+
api_audience=api_audience,
204206
)
205207

206208
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
release_status = "Development Status :: 5 - Production/Stable"
2626
url = "https://github.com/googleapis/python-vpc-access"
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] >= 1.32.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*",
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This constraints file is used to check that lower bounds
2+
# are correct in setup.py
3+
# List all library dependencies and extras in this file.
4+
# Pin the version to the lower bound.
5+
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
6+
# Then this file should have google-cloud-foo==1.14.0
7+
google-api-core==1.32.0
8+
proto-plus==1.15.0
9+
protobuf==3.19.0

tests/unit/gapic/vpcaccess_v1/test_vpc_access_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def test_vpc_access_service_client_client_options(
238238
quota_project_id=None,
239239
client_info=transports.base.DEFAULT_CLIENT_INFO,
240240
always_use_jwt_access=True,
241+
api_audience=None,
241242
)
242243

243244
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -255,6 +256,7 @@ def test_vpc_access_service_client_client_options(
255256
quota_project_id=None,
256257
client_info=transports.base.DEFAULT_CLIENT_INFO,
257258
always_use_jwt_access=True,
259+
api_audience=None,
258260
)
259261

260262
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -272,6 +274,7 @@ def test_vpc_access_service_client_client_options(
272274
quota_project_id=None,
273275
client_info=transports.base.DEFAULT_CLIENT_INFO,
274276
always_use_jwt_access=True,
277+
api_audience=None,
275278
)
276279

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

306328

@@ -378,6 +400,7 @@ def test_vpc_access_service_client_mtls_env_auto(
378400
quota_project_id=None,
379401
client_info=transports.base.DEFAULT_CLIENT_INFO,
380402
always_use_jwt_access=True,
403+
api_audience=None,
381404
)
382405

383406
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -412,6 +435,7 @@ def test_vpc_access_service_client_mtls_env_auto(
412435
quota_project_id=None,
413436
client_info=transports.base.DEFAULT_CLIENT_INFO,
414437
always_use_jwt_access=True,
438+
api_audience=None,
415439
)
416440

417441
# Check the case client_cert_source and ADC client cert are not provided.
@@ -434,6 +458,7 @@ def test_vpc_access_service_client_mtls_env_auto(
434458
quota_project_id=None,
435459
client_info=transports.base.DEFAULT_CLIENT_INFO,
436460
always_use_jwt_access=True,
461+
api_audience=None,
437462
)
438463

439464

@@ -548,6 +573,7 @@ def test_vpc_access_service_client_client_options_scopes(
548573
quota_project_id=None,
549574
client_info=transports.base.DEFAULT_CLIENT_INFO,
550575
always_use_jwt_access=True,
576+
api_audience=None,
551577
)
552578

553579

@@ -586,6 +612,7 @@ def test_vpc_access_service_client_client_options_credentials_file(
586612
quota_project_id=None,
587613
client_info=transports.base.DEFAULT_CLIENT_INFO,
588614
always_use_jwt_access=True,
615+
api_audience=None,
589616
)
590617

591618

@@ -606,6 +633,7 @@ def test_vpc_access_service_client_client_options_from_dict():
606633
quota_project_id=None,
607634
client_info=transports.base.DEFAULT_CLIENT_INFO,
608635
always_use_jwt_access=True,
636+
api_audience=None,
609637
)
610638

611639

@@ -644,6 +672,7 @@ def test_vpc_access_service_client_create_channel_credentials_file(
644672
quota_project_id=None,
645673
client_info=transports.base.DEFAULT_CLIENT_INFO,
646674
always_use_jwt_access=True,
675+
api_audience=None,
647676
)
648677

649678
# test that the credentials from file are saved and used as the credentials.
@@ -2050,6 +2079,28 @@ def test_vpc_access_service_transport_auth_adc(transport_class):
20502079
)
20512080

20522081

2082+
@pytest.mark.parametrize(
2083+
"transport_class",
2084+
[
2085+
transports.VpcAccessServiceGrpcTransport,
2086+
transports.VpcAccessServiceGrpcAsyncIOTransport,
2087+
],
2088+
)
2089+
def test_vpc_access_service_transport_auth_gdch_credentials(transport_class):
2090+
host = "https://language.com"
2091+
api_audience_tests = [None, "https://language2.com"]
2092+
api_audience_expect = [host, "https://language2.com"]
2093+
for t, e in zip(api_audience_tests, api_audience_expect):
2094+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
2095+
gdch_mock = mock.MagicMock()
2096+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
2097+
return_value=gdch_mock
2098+
)
2099+
adc.return_value = (gdch_mock, None)
2100+
transport_class(host=host, api_audience=t)
2101+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
2102+
2103+
20532104
@pytest.mark.parametrize(
20542105
"transport_class,grpc_helpers",
20552106
[
@@ -2552,4 +2603,5 @@ def test_api_key_credentials(client_class, transport_class):
25522603
quota_project_id=None,
25532604
client_info=transports.base.DEFAULT_CLIENT_INFO,
25542605
always_use_jwt_access=True,
2606+
api_audience=None,
25552607
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy