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

Commit 43557a9

Browse files
fix(deps): require google-api-core >= 2.8.0 (#101)
- [ ] 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 3d6833b commit 43557a9

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

google/cloud/storage_transfer_v1/services/storage_transfer_service/client.py

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

436437
def get_google_service_account(

google/cloud/storage_transfer_v1/services/storage_transfer_service/transports/base.py

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

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

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

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

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

google/cloud/storage_transfer_v1/services/storage_transfer_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(
6161
quota_project_id: Optional[str] = None,
6262
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6363
always_use_jwt_access: Optional[bool] = False,
64+
api_audience: Optional[str] = None,
6465
) -> None:
6566
"""Instantiate the transport.
6667
@@ -157,6 +158,7 @@ def __init__(
157158
quota_project_id=quota_project_id,
158159
client_info=client_info,
159160
always_use_jwt_access=always_use_jwt_access,
161+
api_audience=api_audience,
160162
)
161163

162164
if not self._grpc_channel:

google/cloud/storage_transfer_v1/services/storage_transfer_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(
106106
quota_project_id=None,
107107
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
108108
always_use_jwt_access: Optional[bool] = False,
109+
api_audience: Optional[str] = None,
109110
) -> None:
110111
"""Instantiate the transport.
111112
@@ -202,6 +203,7 @@ def __init__(
202203
quota_project_id=quota_project_id,
203204
client_info=client_info,
204205
always_use_jwt_access=always_use_jwt_access,
206+
api_audience=api_audience,
205207
)
206208

207209
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
version = "1.3.1"
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/storage_transfer_v1/test_storage_transfer_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def test_storage_transfer_service_client_client_options(
247247
quota_project_id=None,
248248
client_info=transports.base.DEFAULT_CLIENT_INFO,
249249
always_use_jwt_access=True,
250+
api_audience=None,
250251
)
251252

252253
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -264,6 +265,7 @@ def test_storage_transfer_service_client_client_options(
264265
quota_project_id=None,
265266
client_info=transports.base.DEFAULT_CLIENT_INFO,
266267
always_use_jwt_access=True,
268+
api_audience=None,
267269
)
268270

269271
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -281,6 +283,7 @@ def test_storage_transfer_service_client_client_options(
281283
quota_project_id=None,
282284
client_info=transports.base.DEFAULT_CLIENT_INFO,
283285
always_use_jwt_access=True,
286+
api_audience=None,
284287
)
285288

286289
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -310,6 +313,25 @@ def test_storage_transfer_service_client_client_options(
310313
quota_project_id="octopus",
311314
client_info=transports.base.DEFAULT_CLIENT_INFO,
312315
always_use_jwt_access=True,
316+
api_audience=None,
317+
)
318+
# Check the case api_endpoint is provided
319+
options = client_options.ClientOptions(
320+
api_audience="https://language.googleapis.com"
321+
)
322+
with mock.patch.object(transport_class, "__init__") as patched:
323+
patched.return_value = None
324+
client = client_class(client_options=options, transport=transport_name)
325+
patched.assert_called_once_with(
326+
credentials=None,
327+
credentials_file=None,
328+
host=client.DEFAULT_ENDPOINT,
329+
scopes=None,
330+
client_cert_source_for_mtls=None,
331+
quota_project_id=None,
332+
client_info=transports.base.DEFAULT_CLIENT_INFO,
333+
always_use_jwt_access=True,
334+
api_audience="https://language.googleapis.com",
313335
)
314336

315337

@@ -387,6 +409,7 @@ def test_storage_transfer_service_client_mtls_env_auto(
387409
quota_project_id=None,
388410
client_info=transports.base.DEFAULT_CLIENT_INFO,
389411
always_use_jwt_access=True,
412+
api_audience=None,
390413
)
391414

392415
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -421,6 +444,7 @@ def test_storage_transfer_service_client_mtls_env_auto(
421444
quota_project_id=None,
422445
client_info=transports.base.DEFAULT_CLIENT_INFO,
423446
always_use_jwt_access=True,
447+
api_audience=None,
424448
)
425449

426450
# Check the case client_cert_source and ADC client cert are not provided.
@@ -443,6 +467,7 @@ def test_storage_transfer_service_client_mtls_env_auto(
443467
quota_project_id=None,
444468
client_info=transports.base.DEFAULT_CLIENT_INFO,
445469
always_use_jwt_access=True,
470+
api_audience=None,
446471
)
447472

448473

@@ -563,6 +588,7 @@ def test_storage_transfer_service_client_client_options_scopes(
563588
quota_project_id=None,
564589
client_info=transports.base.DEFAULT_CLIENT_INFO,
565590
always_use_jwt_access=True,
591+
api_audience=None,
566592
)
567593

568594

@@ -601,6 +627,7 @@ def test_storage_transfer_service_client_client_options_credentials_file(
601627
quota_project_id=None,
602628
client_info=transports.base.DEFAULT_CLIENT_INFO,
603629
always_use_jwt_access=True,
630+
api_audience=None,
604631
)
605632

606633

@@ -621,6 +648,7 @@ def test_storage_transfer_service_client_client_options_from_dict():
621648
quota_project_id=None,
622649
client_info=transports.base.DEFAULT_CLIENT_INFO,
623650
always_use_jwt_access=True,
651+
api_audience=None,
624652
)
625653

626654

@@ -659,6 +687,7 @@ def test_storage_transfer_service_client_create_channel_credentials_file(
659687
quota_project_id=None,
660688
client_info=transports.base.DEFAULT_CLIENT_INFO,
661689
always_use_jwt_access=True,
690+
api_audience=None,
662691
)
663692

664693
# test that the credentials from file are saved and used as the credentials.
@@ -3709,6 +3738,28 @@ def test_storage_transfer_service_transport_auth_adc(transport_class):
37093738
)
37103739

37113740

3741+
@pytest.mark.parametrize(
3742+
"transport_class",
3743+
[
3744+
transports.StorageTransferServiceGrpcTransport,
3745+
transports.StorageTransferServiceGrpcAsyncIOTransport,
3746+
],
3747+
)
3748+
def test_storage_transfer_service_transport_auth_gdch_credentials(transport_class):
3749+
host = "https://language.com"
3750+
api_audience_tests = [None, "https://language2.com"]
3751+
api_audience_expect = [host, "https://language2.com"]
3752+
for t, e in zip(api_audience_tests, api_audience_expect):
3753+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
3754+
gdch_mock = mock.MagicMock()
3755+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
3756+
return_value=gdch_mock
3757+
)
3758+
adc.return_value = (gdch_mock, None)
3759+
transport_class(host=host, api_audience=t)
3760+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
3761+
3762+
37123763
@pytest.mark.parametrize(
37133764
"transport_class,grpc_helpers",
37143765
[
@@ -4215,4 +4266,5 @@ def test_api_key_credentials(client_class, transport_class):
42154266
quota_project_id=None,
42164267
client_info=transports.base.DEFAULT_CLIENT_INFO,
42174268
always_use_jwt_access=True,
4269+
api_audience=None,
42184270
)

0 commit comments

Comments
 (0)