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

Commit cf60a2a

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#37)
- [ ] 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 cf37bdb commit cf60a2a

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

google/cloud/bare_metal_solution_v2/services/bare_metal_solution/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ def __init__(
558558
quota_project_id=client_options.quota_project_id,
559559
client_info=client_info,
560560
always_use_jwt_access=True,
561+
api_audience=client_options.api_audience,
561562
)
562563

563564
def list_instances(

google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
quota_project_id: Optional[str] = None,
6565
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6666
always_use_jwt_access: Optional[bool] = False,
67+
api_audience: Optional[str] = None,
6768
**kwargs,
6869
) -> None:
6970
"""Instantiate the transport.
@@ -91,11 +92,6 @@ def __init__(
9192
be used for service account credentials.
9293
"""
9394

94-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
95-
if ":" not in host:
96-
host += ":443"
97-
self._host = host
98-
9995
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
10096

10197
# Save the scopes.
@@ -116,6 +112,11 @@ def __init__(
116112
credentials, _ = google.auth.default(
117113
**scopes_kwargs, quota_project_id=quota_project_id
118114
)
115+
# Don't apply audience if the credentials file passed from user.
116+
if hasattr(credentials, "with_gdch_audience"):
117+
credentials = credentials.with_gdch_audience(
118+
api_audience if api_audience else host
119+
)
119120

120121
# If the credentials are service account credentials, then always try to use self signed JWT.
121122
if (
@@ -128,6 +129,11 @@ def __init__(
128129
# Save the credentials.
129130
self._credentials = credentials
130131

132+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
133+
if ":" not in host:
134+
host += ":443"
135+
self._host = host
136+
131137
def _prep_wrapped_messages(self, client_info):
132138
# Precompute the wrapped methods.
133139
self._wrapped_methods = {

google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
quota_project_id: Optional[str] = None,
7777
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7878
always_use_jwt_access: Optional[bool] = False,
79+
api_audience: Optional[str] = None,
7980
) -> None:
8081
"""Instantiate the transport.
8182
@@ -172,6 +173,7 @@ def __init__(
172173
quota_project_id=quota_project_id,
173174
client_info=client_info,
174175
always_use_jwt_access=always_use_jwt_access,
176+
api_audience=api_audience,
175177
)
176178

177179
if not self._grpc_channel:

google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def __init__(
121121
quota_project_id=None,
122122
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
123123
always_use_jwt_access: Optional[bool] = False,
124+
api_audience: Optional[str] = None,
124125
) -> None:
125126
"""Instantiate the transport.
126127
@@ -217,6 +218,7 @@ def __init__(
217218
quota_project_id=quota_project_id,
218219
client_info=client_info,
219220
always_use_jwt_access=always_use_jwt_access,
221+
api_audience=api_audience,
220222
)
221223

222224
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-bare-metal-solution"
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/bare_metal_solution_v2/test_bare_metal_solution.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def test_bare_metal_solution_client_client_options(
249249
quota_project_id=None,
250250
client_info=transports.base.DEFAULT_CLIENT_INFO,
251251
always_use_jwt_access=True,
252+
api_audience=None,
252253
)
253254

254255
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -266,6 +267,7 @@ def test_bare_metal_solution_client_client_options(
266267
quota_project_id=None,
267268
client_info=transports.base.DEFAULT_CLIENT_INFO,
268269
always_use_jwt_access=True,
270+
api_audience=None,
269271
)
270272

271273
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -283,6 +285,7 @@ def test_bare_metal_solution_client_client_options(
283285
quota_project_id=None,
284286
client_info=transports.base.DEFAULT_CLIENT_INFO,
285287
always_use_jwt_access=True,
288+
api_audience=None,
286289
)
287290

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

317339

@@ -389,6 +411,7 @@ def test_bare_metal_solution_client_mtls_env_auto(
389411
quota_project_id=None,
390412
client_info=transports.base.DEFAULT_CLIENT_INFO,
391413
always_use_jwt_access=True,
414+
api_audience=None,
392415
)
393416

394417
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -423,6 +446,7 @@ def test_bare_metal_solution_client_mtls_env_auto(
423446
quota_project_id=None,
424447
client_info=transports.base.DEFAULT_CLIENT_INFO,
425448
always_use_jwt_access=True,
449+
api_audience=None,
426450
)
427451

428452
# Check the case client_cert_source and ADC client cert are not provided.
@@ -445,6 +469,7 @@ def test_bare_metal_solution_client_mtls_env_auto(
445469
quota_project_id=None,
446470
client_info=transports.base.DEFAULT_CLIENT_INFO,
447471
always_use_jwt_access=True,
472+
api_audience=None,
448473
)
449474

450475

@@ -559,6 +584,7 @@ def test_bare_metal_solution_client_client_options_scopes(
559584
quota_project_id=None,
560585
client_info=transports.base.DEFAULT_CLIENT_INFO,
561586
always_use_jwt_access=True,
587+
api_audience=None,
562588
)
563589

564590

@@ -597,6 +623,7 @@ def test_bare_metal_solution_client_client_options_credentials_file(
597623
quota_project_id=None,
598624
client_info=transports.base.DEFAULT_CLIENT_INFO,
599625
always_use_jwt_access=True,
626+
api_audience=None,
600627
)
601628

602629

@@ -617,6 +644,7 @@ def test_bare_metal_solution_client_client_options_from_dict():
617644
quota_project_id=None,
618645
client_info=transports.base.DEFAULT_CLIENT_INFO,
619646
always_use_jwt_access=True,
647+
api_audience=None,
620648
)
621649

622650

@@ -655,6 +683,7 @@ def test_bare_metal_solution_client_create_channel_credentials_file(
655683
quota_project_id=None,
656684
client_info=transports.base.DEFAULT_CLIENT_INFO,
657685
always_use_jwt_access=True,
686+
api_audience=None,
658687
)
659688

660689
# test that the credentials from file are saved and used as the credentials.
@@ -6685,6 +6714,28 @@ def test_bare_metal_solution_transport_auth_adc(transport_class):
66856714
)
66866715

66876716

6717+
@pytest.mark.parametrize(
6718+
"transport_class",
6719+
[
6720+
transports.BareMetalSolutionGrpcTransport,
6721+
transports.BareMetalSolutionGrpcAsyncIOTransport,
6722+
],
6723+
)
6724+
def test_bare_metal_solution_transport_auth_gdch_credentials(transport_class):
6725+
host = "https://language.com"
6726+
api_audience_tests = [None, "https://language2.com"]
6727+
api_audience_expect = [host, "https://language2.com"]
6728+
for t, e in zip(api_audience_tests, api_audience_expect):
6729+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
6730+
gdch_mock = mock.MagicMock()
6731+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
6732+
return_value=gdch_mock
6733+
)
6734+
adc.return_value = (gdch_mock, None)
6735+
transport_class(host=host, api_audience=t)
6736+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
6737+
6738+
66886739
@pytest.mark.parametrize(
66896740
"transport_class,grpc_helpers",
66906741
[
@@ -7329,4 +7380,5 @@ def test_api_key_credentials(client_class, transport_class):
73297380
quota_project_id=None,
73307381
client_info=transports.base.DEFAULT_CLIENT_INFO,
73317382
always_use_jwt_access=True,
7383+
api_audience=None,
73327384
)

0 commit comments

Comments
 (0)