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

Commit 8b25cff

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#282)
- [ ] 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 1f6984a commit 8b25cff

File tree

8 files changed

+70
-20
lines changed

8 files changed

+70
-20
lines changed

google/cloud/bigquery_reservation_v1/services/reservation_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ def __init__(
516516
quota_project_id=client_options.quota_project_id,
517517
client_info=client_info,
518518
always_use_jwt_access=True,
519+
api_audience=client_options.api_audience,
519520
)
520521

521522
def create_reservation(

google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py

Lines changed: 11 additions & 5 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
**kwargs,
6364
) -> None:
6465
"""Instantiate the transport.
@@ -86,11 +87,6 @@ def __init__(
8687
be used for service account credentials.
8788
"""
8889

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

9692
# Save the scopes.
@@ -111,6 +107,11 @@ def __init__(
111107
credentials, _ = google.auth.default(
112108
**scopes_kwargs, quota_project_id=quota_project_id
113109
)
110+
# Don't apply audience if the credentials file passed from user.
111+
if hasattr(credentials, "with_gdch_audience"):
112+
credentials = credentials.with_gdch_audience(
113+
api_audience if api_audience else host
114+
)
114115

115116
# If the credentials are service account credentials, then always try to use self signed JWT.
116117
if (
@@ -123,6 +124,11 @@ def __init__(
123124
# Save the credentials.
124125
self._credentials = credentials
125126

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

google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(
7575
quota_project_id: Optional[str] = None,
7676
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7777
always_use_jwt_access: Optional[bool] = False,
78+
api_audience: Optional[str] = None,
7879
) -> None:
7980
"""Instantiate the transport.
8081
@@ -170,6 +171,7 @@ def __init__(
170171
quota_project_id=quota_project_id,
171172
client_info=client_info,
172173
always_use_jwt_access=always_use_jwt_access,
174+
api_audience=api_audience,
173175
)
174176

175177
if not self._grpc_channel:

google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(
120120
quota_project_id=None,
121121
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
122122
always_use_jwt_access: Optional[bool] = False,
123+
api_audience: Optional[str] = None,
123124
) -> None:
124125
"""Instantiate the transport.
125126
@@ -215,6 +216,7 @@ def __init__(
215216
quota_project_id=quota_project_id,
216217
client_info=client_info,
217218
always_use_jwt_access=always_use_jwt_access,
219+
api_audience=api_audience,
218220
)
219221

220222
if not self._grpc_channel:

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@
4747
platforms="Posix; MacOS X; Windows",
4848
include_package_data=True,
4949
install_requires=(
50-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
51-
# Until this issue is closed
52-
# https://github.com/googleapis/google-cloud-python/issues/10566
53-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
50+
"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.*",
5451
"proto-plus >= 1.15.0, <2.0.0dev",
5552
"protobuf >= 3.19.0, <4.0.0dev",
5653
),

testing/constraints-3.6.txt

Lines changed: 0 additions & 10 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,6 +5,6 @@
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
protobuf==3.19.0

tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def test_reservation_service_client_client_options(
233233
quota_project_id=None,
234234
client_info=transports.base.DEFAULT_CLIENT_INFO,
235235
always_use_jwt_access=True,
236+
api_audience=None,
236237
)
237238

238239
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -250,6 +251,7 @@ def test_reservation_service_client_client_options(
250251
quota_project_id=None,
251252
client_info=transports.base.DEFAULT_CLIENT_INFO,
252253
always_use_jwt_access=True,
254+
api_audience=None,
253255
)
254256

255257
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -267,6 +269,7 @@ def test_reservation_service_client_client_options(
267269
quota_project_id=None,
268270
client_info=transports.base.DEFAULT_CLIENT_INFO,
269271
always_use_jwt_access=True,
272+
api_audience=None,
270273
)
271274

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

301323

@@ -373,6 +395,7 @@ def test_reservation_service_client_mtls_env_auto(
373395
quota_project_id=None,
374396
client_info=transports.base.DEFAULT_CLIENT_INFO,
375397
always_use_jwt_access=True,
398+
api_audience=None,
376399
)
377400

378401
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -407,6 +430,7 @@ def test_reservation_service_client_mtls_env_auto(
407430
quota_project_id=None,
408431
client_info=transports.base.DEFAULT_CLIENT_INFO,
409432
always_use_jwt_access=True,
433+
api_audience=None,
410434
)
411435

412436
# Check the case client_cert_source and ADC client cert are not provided.
@@ -429,6 +453,7 @@ def test_reservation_service_client_mtls_env_auto(
429453
quota_project_id=None,
430454
client_info=transports.base.DEFAULT_CLIENT_INFO,
431455
always_use_jwt_access=True,
456+
api_audience=None,
432457
)
433458

434459

@@ -543,6 +568,7 @@ def test_reservation_service_client_client_options_scopes(
543568
quota_project_id=None,
544569
client_info=transports.base.DEFAULT_CLIENT_INFO,
545570
always_use_jwt_access=True,
571+
api_audience=None,
546572
)
547573

548574

@@ -581,6 +607,7 @@ def test_reservation_service_client_client_options_credentials_file(
581607
quota_project_id=None,
582608
client_info=transports.base.DEFAULT_CLIENT_INFO,
583609
always_use_jwt_access=True,
610+
api_audience=None,
584611
)
585612

586613

@@ -601,6 +628,7 @@ def test_reservation_service_client_client_options_from_dict():
601628
quota_project_id=None,
602629
client_info=transports.base.DEFAULT_CLIENT_INFO,
603630
always_use_jwt_access=True,
631+
api_audience=None,
604632
)
605633

606634

@@ -639,6 +667,7 @@ def test_reservation_service_client_create_channel_credentials_file(
639667
quota_project_id=None,
640668
client_info=transports.base.DEFAULT_CLIENT_INFO,
641669
always_use_jwt_access=True,
670+
api_audience=None,
642671
)
643672

644673
# test that the credentials from file are saved and used as the credentials.
@@ -7287,6 +7316,28 @@ def test_reservation_service_transport_auth_adc(transport_class):
72877316
)
72887317

72897318

7319+
@pytest.mark.parametrize(
7320+
"transport_class",
7321+
[
7322+
transports.ReservationServiceGrpcTransport,
7323+
transports.ReservationServiceGrpcAsyncIOTransport,
7324+
],
7325+
)
7326+
def test_reservation_service_transport_auth_gdch_credentials(transport_class):
7327+
host = "https://language.com"
7328+
api_audience_tests = [None, "https://language2.com"]
7329+
api_audience_expect = [host, "https://language2.com"]
7330+
for t, e in zip(api_audience_tests, api_audience_expect):
7331+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
7332+
gdch_mock = mock.MagicMock()
7333+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
7334+
return_value=gdch_mock
7335+
)
7336+
adc.return_value = (gdch_mock, None)
7337+
transport_class(host=host, api_audience=t)
7338+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
7339+
7340+
72907341
@pytest.mark.parametrize(
72917342
"transport_class,grpc_helpers",
72927343
[
@@ -7847,4 +7898,5 @@ def test_api_key_credentials(client_class, transport_class):
78477898
quota_project_id=None,
78487899
client_info=transports.base.DEFAULT_CLIENT_INFO,
78497900
always_use_jwt_access=True,
7901+
api_audience=None,
78507902
)

0 commit comments

Comments
 (0)