Skip to content

Commit 4ab6cf2

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#362)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 459095142 Source-Link: googleapis/googleapis@4f1be99 Source-Link: googleapis/googleapis-gen@ae686d9 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWU2ODZkOWNkZTRmYzNlMzZkMGFjMDJlZmI4NjQzYjE1ODkwYzFlZCJ9 feat: add audience parameter PiperOrigin-RevId: 456827138 Source-Link: googleapis/googleapis@23f1a15 Source-Link: googleapis/googleapis-gen@4075a85 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDA3NWE4NTE0ZjY3NjY5MWVjMTU2Njg4YTViYmYxODNhYTk4OTNjZSJ9
1 parent 60d35b7 commit 4ab6cf2

File tree

8 files changed

+70
-21
lines changed

8 files changed

+70
-21
lines changed

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def __init__(
473473
quota_project_id=client_options.quota_project_id,
474474
client_info=client_info,
475475
always_use_jwt_access=True,
476+
api_audience=client_options.api_audience,
476477
)
477478

478479
def get_data_source(

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_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 = {

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_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
@@ -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:

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_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
@@ -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:

packages/google-cloud-bigquery-datatransfer/setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
# 'Development Status :: 5 - Production/Stable'
2929
release_status = "Development Status :: 5 - Production/Stable"
3030
dependencies = (
31-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
32-
# Until this issue is closed
33-
# https://github.com/googleapis/google-cloud-python/issues/10566
34-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
31+
"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.*",
3532
"proto-plus >= 1.15.0, <2.0.0dev",
3633
"protobuf >= 3.19.0, <4.0.0dev",
3734
)

packages/google-cloud-bigquery-datatransfer/testing/constraints-3.6.txt

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

packages/google-cloud-bigquery-datatransfer/testing/constraints-3.7.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
77
# Then this file should have foo==1.14.0
8-
google-api-core==1.31.5
8+
google-api-core==1.32.0
99
proto-plus==1.15.0
1010
libcst==0.2.5
1111
protobuf==3.19.0

packages/google-cloud-bigquery-datatransfer/tests/unit/gapic/bigquery_datatransfer_v1/test_data_transfer_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def test_data_transfer_service_client_client_options(
237237
quota_project_id=None,
238238
client_info=transports.base.DEFAULT_CLIENT_INFO,
239239
always_use_jwt_access=True,
240+
api_audience=None,
240241
)
241242

242243
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -254,6 +255,7 @@ def test_data_transfer_service_client_client_options(
254255
quota_project_id=None,
255256
client_info=transports.base.DEFAULT_CLIENT_INFO,
256257
always_use_jwt_access=True,
258+
api_audience=None,
257259
)
258260

259261
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -271,6 +273,7 @@ def test_data_transfer_service_client_client_options(
271273
quota_project_id=None,
272274
client_info=transports.base.DEFAULT_CLIENT_INFO,
273275
always_use_jwt_access=True,
276+
api_audience=None,
274277
)
275278

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

305327

@@ -377,6 +399,7 @@ def test_data_transfer_service_client_mtls_env_auto(
377399
quota_project_id=None,
378400
client_info=transports.base.DEFAULT_CLIENT_INFO,
379401
always_use_jwt_access=True,
402+
api_audience=None,
380403
)
381404

382405
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -411,6 +434,7 @@ def test_data_transfer_service_client_mtls_env_auto(
411434
quota_project_id=None,
412435
client_info=transports.base.DEFAULT_CLIENT_INFO,
413436
always_use_jwt_access=True,
437+
api_audience=None,
414438
)
415439

416440
# Check the case client_cert_source and ADC client cert are not provided.
@@ -433,6 +457,7 @@ def test_data_transfer_service_client_mtls_env_auto(
433457
quota_project_id=None,
434458
client_info=transports.base.DEFAULT_CLIENT_INFO,
435459
always_use_jwt_access=True,
460+
api_audience=None,
436461
)
437462

438463

@@ -551,6 +576,7 @@ def test_data_transfer_service_client_client_options_scopes(
551576
quota_project_id=None,
552577
client_info=transports.base.DEFAULT_CLIENT_INFO,
553578
always_use_jwt_access=True,
579+
api_audience=None,
554580
)
555581

556582

@@ -589,6 +615,7 @@ def test_data_transfer_service_client_client_options_credentials_file(
589615
quota_project_id=None,
590616
client_info=transports.base.DEFAULT_CLIENT_INFO,
591617
always_use_jwt_access=True,
618+
api_audience=None,
592619
)
593620

594621

@@ -609,6 +636,7 @@ def test_data_transfer_service_client_client_options_from_dict():
609636
quota_project_id=None,
610637
client_info=transports.base.DEFAULT_CLIENT_INFO,
611638
always_use_jwt_access=True,
639+
api_audience=None,
612640
)
613641

614642

@@ -647,6 +675,7 @@ def test_data_transfer_service_client_create_channel_credentials_file(
647675
quota_project_id=None,
648676
client_info=transports.base.DEFAULT_CLIENT_INFO,
649677
always_use_jwt_access=True,
678+
api_audience=None,
650679
)
651680

652681
# test that the credentials from file are saved and used as the credentials.
@@ -5389,6 +5418,28 @@ def test_data_transfer_service_transport_auth_adc(transport_class):
53895418
)
53905419

53915420

5421+
@pytest.mark.parametrize(
5422+
"transport_class",
5423+
[
5424+
transports.DataTransferServiceGrpcTransport,
5425+
transports.DataTransferServiceGrpcAsyncIOTransport,
5426+
],
5427+
)
5428+
def test_data_transfer_service_transport_auth_gdch_credentials(transport_class):
5429+
host = "https://language.com"
5430+
api_audience_tests = [None, "https://language2.com"]
5431+
api_audience_expect = [host, "https://language2.com"]
5432+
for t, e in zip(api_audience_tests, api_audience_expect):
5433+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
5434+
gdch_mock = mock.MagicMock()
5435+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
5436+
return_value=gdch_mock
5437+
)
5438+
adc.return_value = (gdch_mock, None)
5439+
transport_class(host=host, api_audience=t)
5440+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
5441+
5442+
53925443
@pytest.mark.parametrize(
53935444
"transport_class,grpc_helpers",
53945445
[
@@ -5908,4 +5959,5 @@ def test_api_key_credentials(client_class, transport_class):
59085959
quota_project_id=None,
59095960
client_info=transports.base.DEFAULT_CLIENT_INFO,
59105961
always_use_jwt_access=True,
5962+
api_audience=None,
59115963
)

0 commit comments

Comments
 (0)