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

Commit 0dd5a10

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#229)
- [ ] 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 1ac3780 commit 0dd5a10

File tree

8 files changed

+70
-21
lines changed

8 files changed

+70
-21
lines changed

google/cloud/bigquery_connection_v1/services/connection_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_connection(

google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py

Lines changed: 11 additions & 5 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
**kwargs,
6566
) -> None:
6667
"""Instantiate the transport.
@@ -88,11 +89,6 @@ def __init__(
8889
be used for service account credentials.
8990
"""
9091

91-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
92-
if ":" not in host:
93-
host += ":443"
94-
self._host = host
95-
9692
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9793

9894
# Save the scopes.
@@ -113,6 +109,11 @@ def __init__(
113109
credentials, _ = google.auth.default(
114110
**scopes_kwargs, quota_project_id=quota_project_id
115111
)
112+
# Don't apply audience if the credentials file passed from user.
113+
if hasattr(credentials, "with_gdch_audience"):
114+
credentials = credentials.with_gdch_audience(
115+
api_audience if api_audience else host
116+
)
116117

117118
# If the credentials are service account credentials, then always try to use self signed JWT.
118119
if (
@@ -125,6 +126,11 @@ def __init__(
125126
# Save the credentials.
126127
self._credentials = credentials
127128

129+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
130+
if ":" not in host:
131+
host += ":443"
132+
self._host = host
133+
128134
def _prep_wrapped_messages(self, client_info):
129135
# Precompute the wrapped methods.
130136
self._wrapped_methods = {

google/cloud/bigquery_connection_v1/services/connection_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
@@ -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/bigquery_connection_v1/services/connection_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
@@ -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
@@ -45,10 +45,7 @@
4545
platforms="Posix; MacOS X; Windows",
4646
include_package_data=True,
4747
install_requires=(
48-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
49-
# Until this issue is closed
50-
# https://github.com/googleapis/google-cloud-python/issues/10566
51-
"google-api-core >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
48+
"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.*",
5249
"proto-plus >= 1.15.0, <2.0.0dev",
5350
"protobuf >= 3.19.0, <4.0.0dev",
5451
"grpc-google-iam-v1 >= 0.12.4, <1.0.0dev",

testing/constraints-3.6.txt

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

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
grpc-google-iam-v1==0.12.4
1111
protobuf==3.19.0

tests/unit/gapic/bigquery_connection_v1/test_connection_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def test_connection_service_client_client_options(
234234
quota_project_id=None,
235235
client_info=transports.base.DEFAULT_CLIENT_INFO,
236236
always_use_jwt_access=True,
237+
api_audience=None,
237238
)
238239

239240
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -251,6 +252,7 @@ def test_connection_service_client_client_options(
251252
quota_project_id=None,
252253
client_info=transports.base.DEFAULT_CLIENT_INFO,
253254
always_use_jwt_access=True,
255+
api_audience=None,
254256
)
255257

256258
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -268,6 +270,7 @@ def test_connection_service_client_client_options(
268270
quota_project_id=None,
269271
client_info=transports.base.DEFAULT_CLIENT_INFO,
270272
always_use_jwt_access=True,
273+
api_audience=None,
271274
)
272275

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

302324

@@ -374,6 +396,7 @@ def test_connection_service_client_mtls_env_auto(
374396
quota_project_id=None,
375397
client_info=transports.base.DEFAULT_CLIENT_INFO,
376398
always_use_jwt_access=True,
399+
api_audience=None,
377400
)
378401

379402
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -408,6 +431,7 @@ def test_connection_service_client_mtls_env_auto(
408431
quota_project_id=None,
409432
client_info=transports.base.DEFAULT_CLIENT_INFO,
410433
always_use_jwt_access=True,
434+
api_audience=None,
411435
)
412436

413437
# Check the case client_cert_source and ADC client cert are not provided.
@@ -430,6 +454,7 @@ def test_connection_service_client_mtls_env_auto(
430454
quota_project_id=None,
431455
client_info=transports.base.DEFAULT_CLIENT_INFO,
432456
always_use_jwt_access=True,
457+
api_audience=None,
433458
)
434459

435460

@@ -544,6 +569,7 @@ def test_connection_service_client_client_options_scopes(
544569
quota_project_id=None,
545570
client_info=transports.base.DEFAULT_CLIENT_INFO,
546571
always_use_jwt_access=True,
572+
api_audience=None,
547573
)
548574

549575

@@ -582,6 +608,7 @@ def test_connection_service_client_client_options_credentials_file(
582608
quota_project_id=None,
583609
client_info=transports.base.DEFAULT_CLIENT_INFO,
584610
always_use_jwt_access=True,
611+
api_audience=None,
585612
)
586613

587614

@@ -602,6 +629,7 @@ def test_connection_service_client_client_options_from_dict():
602629
quota_project_id=None,
603630
client_info=transports.base.DEFAULT_CLIENT_INFO,
604631
always_use_jwt_access=True,
632+
api_audience=None,
605633
)
606634

607635

@@ -640,6 +668,7 @@ def test_connection_service_client_create_channel_credentials_file(
640668
quota_project_id=None,
641669
client_info=transports.base.DEFAULT_CLIENT_INFO,
642670
always_use_jwt_access=True,
671+
api_audience=None,
643672
)
644673

645674
# test that the credentials from file are saved and used as the credentials.
@@ -3171,6 +3200,28 @@ def test_connection_service_transport_auth_adc(transport_class):
31713200
)
31723201

31733202

3203+
@pytest.mark.parametrize(
3204+
"transport_class",
3205+
[
3206+
transports.ConnectionServiceGrpcTransport,
3207+
transports.ConnectionServiceGrpcAsyncIOTransport,
3208+
],
3209+
)
3210+
def test_connection_service_transport_auth_gdch_credentials(transport_class):
3211+
host = "https://language.com"
3212+
api_audience_tests = [None, "https://language2.com"]
3213+
api_audience_expect = [host, "https://language2.com"]
3214+
for t, e in zip(api_audience_tests, api_audience_expect):
3215+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
3216+
gdch_mock = mock.MagicMock()
3217+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
3218+
return_value=gdch_mock
3219+
)
3220+
adc.return_value = (gdch_mock, None)
3221+
transport_class(host=host, api_audience=t)
3222+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
3223+
3224+
31743225
@pytest.mark.parametrize(
31753226
"transport_class,grpc_helpers",
31763227
[
@@ -3647,4 +3698,5 @@ def test_api_key_credentials(client_class, transport_class):
36473698
quota_project_id=None,
36483699
client_info=transports.base.DEFAULT_CLIENT_INFO,
36493700
always_use_jwt_access=True,
3701+
api_audience=None,
36503702
)

0 commit comments

Comments
 (0)