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

Commit 2b17d6a

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#48)
- [ ] 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 c77923d commit 2b17d6a

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

google/cloud/optimization_v1/services/fleet_routing/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def __init__(
425425
quota_project_id=client_options.quota_project_id,
426426
client_info=client_info,
427427
always_use_jwt_access=True,
428+
api_audience=client_options.api_audience,
428429
)
429430

430431
def optimize_tours(

google/cloud/optimization_v1/services/fleet_routing/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/optimization_v1/services/fleet_routing/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def __init__(
8282
quota_project_id: Optional[str] = None,
8383
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
8484
always_use_jwt_access: Optional[bool] = False,
85+
api_audience: Optional[str] = None,
8586
) -> None:
8687
"""Instantiate the transport.
8788
@@ -178,6 +179,7 @@ def __init__(
178179
quota_project_id=quota_project_id,
179180
client_info=client_info,
180181
always_use_jwt_access=always_use_jwt_access,
182+
api_audience=api_audience,
181183
)
182184

183185
if not self._grpc_channel:

google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(
127127
quota_project_id=None,
128128
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
129129
always_use_jwt_access: Optional[bool] = False,
130+
api_audience: Optional[str] = None,
130131
) -> None:
131132
"""Instantiate the transport.
132133
@@ -223,6 +224,7 @@ def __init__(
223224
quota_project_id=quota_project_id,
224225
client_info=client_info,
225226
always_use_jwt_access=always_use_jwt_access,
227+
api_audience=api_audience,
226228
)
227229

228230
if not self._grpc_channel:

setup.py

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

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==1.32.0
88
proto-plus==1.15.0
99
protobuf==3.19.0

tests/unit/gapic/optimization_v1/test_fleet_routing.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def test_fleet_routing_client_client_options(
227227
quota_project_id=None,
228228
client_info=transports.base.DEFAULT_CLIENT_INFO,
229229
always_use_jwt_access=True,
230+
api_audience=None,
230231
)
231232

232233
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -244,6 +245,7 @@ def test_fleet_routing_client_client_options(
244245
quota_project_id=None,
245246
client_info=transports.base.DEFAULT_CLIENT_INFO,
246247
always_use_jwt_access=True,
248+
api_audience=None,
247249
)
248250

249251
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -261,6 +263,7 @@ def test_fleet_routing_client_client_options(
261263
quota_project_id=None,
262264
client_info=transports.base.DEFAULT_CLIENT_INFO,
263265
always_use_jwt_access=True,
266+
api_audience=None,
264267
)
265268

266269
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -290,6 +293,25 @@ def test_fleet_routing_client_client_options(
290293
quota_project_id="octopus",
291294
client_info=transports.base.DEFAULT_CLIENT_INFO,
292295
always_use_jwt_access=True,
296+
api_audience=None,
297+
)
298+
# Check the case api_endpoint is provided
299+
options = client_options.ClientOptions(
300+
api_audience="https://language.googleapis.com"
301+
)
302+
with mock.patch.object(transport_class, "__init__") as patched:
303+
patched.return_value = None
304+
client = client_class(client_options=options, transport=transport_name)
305+
patched.assert_called_once_with(
306+
credentials=None,
307+
credentials_file=None,
308+
host=client.DEFAULT_ENDPOINT,
309+
scopes=None,
310+
client_cert_source_for_mtls=None,
311+
quota_project_id=None,
312+
client_info=transports.base.DEFAULT_CLIENT_INFO,
313+
always_use_jwt_access=True,
314+
api_audience="https://language.googleapis.com",
293315
)
294316

295317

@@ -355,6 +377,7 @@ def test_fleet_routing_client_mtls_env_auto(
355377
quota_project_id=None,
356378
client_info=transports.base.DEFAULT_CLIENT_INFO,
357379
always_use_jwt_access=True,
380+
api_audience=None,
358381
)
359382

360383
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -389,6 +412,7 @@ def test_fleet_routing_client_mtls_env_auto(
389412
quota_project_id=None,
390413
client_info=transports.base.DEFAULT_CLIENT_INFO,
391414
always_use_jwt_access=True,
415+
api_audience=None,
392416
)
393417

394418
# Check the case client_cert_source and ADC client cert are not provided.
@@ -411,6 +435,7 @@ def test_fleet_routing_client_mtls_env_auto(
411435
quota_project_id=None,
412436
client_info=transports.base.DEFAULT_CLIENT_INFO,
413437
always_use_jwt_access=True,
438+
api_audience=None,
414439
)
415440

416441

@@ -521,6 +546,7 @@ def test_fleet_routing_client_client_options_scopes(
521546
quota_project_id=None,
522547
client_info=transports.base.DEFAULT_CLIENT_INFO,
523548
always_use_jwt_access=True,
549+
api_audience=None,
524550
)
525551

526552

@@ -559,6 +585,7 @@ def test_fleet_routing_client_client_options_credentials_file(
559585
quota_project_id=None,
560586
client_info=transports.base.DEFAULT_CLIENT_INFO,
561587
always_use_jwt_access=True,
588+
api_audience=None,
562589
)
563590

564591

@@ -577,6 +604,7 @@ def test_fleet_routing_client_client_options_from_dict():
577604
quota_project_id=None,
578605
client_info=transports.base.DEFAULT_CLIENT_INFO,
579606
always_use_jwt_access=True,
607+
api_audience=None,
580608
)
581609

582610

@@ -615,6 +643,7 @@ def test_fleet_routing_client_create_channel_credentials_file(
615643
quota_project_id=None,
616644
client_info=transports.base.DEFAULT_CLIENT_INFO,
617645
always_use_jwt_access=True,
646+
api_audience=None,
618647
)
619648

620649
# test that the credentials from file are saved and used as the credentials.
@@ -1180,6 +1209,28 @@ def test_fleet_routing_transport_auth_adc(transport_class):
11801209
)
11811210

11821211

1212+
@pytest.mark.parametrize(
1213+
"transport_class",
1214+
[
1215+
transports.FleetRoutingGrpcTransport,
1216+
transports.FleetRoutingGrpcAsyncIOTransport,
1217+
],
1218+
)
1219+
def test_fleet_routing_transport_auth_gdch_credentials(transport_class):
1220+
host = "https://language.com"
1221+
api_audience_tests = [None, "https://language2.com"]
1222+
api_audience_expect = [host, "https://language2.com"]
1223+
for t, e in zip(api_audience_tests, api_audience_expect):
1224+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
1225+
gdch_mock = mock.MagicMock()
1226+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
1227+
return_value=gdch_mock
1228+
)
1229+
adc.return_value = (gdch_mock, None)
1230+
transport_class(host=host, api_audience=t)
1231+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
1232+
1233+
11831234
@pytest.mark.parametrize(
11841235
"transport_class,grpc_helpers",
11851236
[
@@ -1645,4 +1696,5 @@ def test_api_key_credentials(client_class, transport_class):
16451696
quota_project_id=None,
16461697
client_info=transports.base.DEFAULT_CLIENT_INFO,
16471698
always_use_jwt_access=True,
1699+
api_audience=None,
16481700
)

0 commit comments

Comments
 (0)