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

Commit 900311d

Browse files
fix(deps): require google-api-core >= 2.8.0 (#114)
- [ ] 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 8cb5409 commit 900311d

File tree

8 files changed

+70
-20
lines changed

8 files changed

+70
-20
lines changed

google/cloud/shell_v1/services/cloud_shell_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def __init__(
430430
quota_project_id=client_options.quota_project_id,
431431
client_info=client_info,
432432
always_use_jwt_access=True,
433+
api_audience=client_options.api_audience,
433434
)
434435

435436
def get_environment(

google/cloud/shell_v1/services/cloud_shell_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 = {

google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
quota_project_id: Optional[str] = None,
6666
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6767
always_use_jwt_access: Optional[bool] = False,
68+
api_audience: Optional[str] = None,
6869
) -> None:
6970
"""Instantiate the transport.
7071
@@ -161,6 +162,7 @@ def __init__(
161162
quota_project_id=quota_project_id,
162163
client_info=client_info,
163164
always_use_jwt_access=always_use_jwt_access,
165+
api_audience=api_audience,
164166
)
165167

166168
if not self._grpc_channel:

google/cloud/shell_v1/services/cloud_shell_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(
110110
quota_project_id=None,
111111
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
112112
always_use_jwt_access: Optional[bool] = False,
113+
api_audience: Optional[str] = None,
113114
) -> None:
114115
"""Instantiate the transport.
115116
@@ -206,6 +207,7 @@ def __init__(
206207
quota_project_id=quota_project_id,
207208
client_info=client_info,
208209
always_use_jwt_access=always_use_jwt_access,
210+
api_audience=api_audience,
209211
)
210212

211213
if not self._grpc_channel:

setup.py

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

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==2.8.0
99
proto-plus==1.15.0
1010
protobuf==3.19.0

tests/unit/gapic/shell_v1/test_cloud_shell_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def test_cloud_shell_service_client_client_options(
238238
quota_project_id=None,
239239
client_info=transports.base.DEFAULT_CLIENT_INFO,
240240
always_use_jwt_access=True,
241+
api_audience=None,
241242
)
242243

243244
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -255,6 +256,7 @@ def test_cloud_shell_service_client_client_options(
255256
quota_project_id=None,
256257
client_info=transports.base.DEFAULT_CLIENT_INFO,
257258
always_use_jwt_access=True,
259+
api_audience=None,
258260
)
259261

260262
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -272,6 +274,7 @@ def test_cloud_shell_service_client_client_options(
272274
quota_project_id=None,
273275
client_info=transports.base.DEFAULT_CLIENT_INFO,
274276
always_use_jwt_access=True,
277+
api_audience=None,
275278
)
276279

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

306328

@@ -378,6 +400,7 @@ def test_cloud_shell_service_client_mtls_env_auto(
378400
quota_project_id=None,
379401
client_info=transports.base.DEFAULT_CLIENT_INFO,
380402
always_use_jwt_access=True,
403+
api_audience=None,
381404
)
382405

383406
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -412,6 +435,7 @@ def test_cloud_shell_service_client_mtls_env_auto(
412435
quota_project_id=None,
413436
client_info=transports.base.DEFAULT_CLIENT_INFO,
414437
always_use_jwt_access=True,
438+
api_audience=None,
415439
)
416440

417441
# Check the case client_cert_source and ADC client cert are not provided.
@@ -434,6 +458,7 @@ def test_cloud_shell_service_client_mtls_env_auto(
434458
quota_project_id=None,
435459
client_info=transports.base.DEFAULT_CLIENT_INFO,
436460
always_use_jwt_access=True,
461+
api_audience=None,
437462
)
438463

439464

@@ -548,6 +573,7 @@ def test_cloud_shell_service_client_client_options_scopes(
548573
quota_project_id=None,
549574
client_info=transports.base.DEFAULT_CLIENT_INFO,
550575
always_use_jwt_access=True,
576+
api_audience=None,
551577
)
552578

553579

@@ -586,6 +612,7 @@ def test_cloud_shell_service_client_client_options_credentials_file(
586612
quota_project_id=None,
587613
client_info=transports.base.DEFAULT_CLIENT_INFO,
588614
always_use_jwt_access=True,
615+
api_audience=None,
589616
)
590617

591618

@@ -606,6 +633,7 @@ def test_cloud_shell_service_client_client_options_from_dict():
606633
quota_project_id=None,
607634
client_info=transports.base.DEFAULT_CLIENT_INFO,
608635
always_use_jwt_access=True,
636+
api_audience=None,
609637
)
610638

611639

@@ -644,6 +672,7 @@ def test_cloud_shell_service_client_create_channel_credentials_file(
644672
quota_project_id=None,
645673
client_info=transports.base.DEFAULT_CLIENT_INFO,
646674
always_use_jwt_access=True,
675+
api_audience=None,
647676
)
648677

649678
# test that the credentials from file are saved and used as the credentials.
@@ -1773,6 +1802,28 @@ def test_cloud_shell_service_transport_auth_adc(transport_class):
17731802
)
17741803

17751804

1805+
@pytest.mark.parametrize(
1806+
"transport_class",
1807+
[
1808+
transports.CloudShellServiceGrpcTransport,
1809+
transports.CloudShellServiceGrpcAsyncIOTransport,
1810+
],
1811+
)
1812+
def test_cloud_shell_service_transport_auth_gdch_credentials(transport_class):
1813+
host = "https://language.com"
1814+
api_audience_tests = [None, "https://language2.com"]
1815+
api_audience_expect = [host, "https://language2.com"]
1816+
for t, e in zip(api_audience_tests, api_audience_expect):
1817+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
1818+
gdch_mock = mock.MagicMock()
1819+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
1820+
return_value=gdch_mock
1821+
)
1822+
adc.return_value = (gdch_mock, None)
1823+
transport_class(host=host, api_audience=t)
1824+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
1825+
1826+
17761827
@pytest.mark.parametrize(
17771828
"transport_class,grpc_helpers",
17781829
[
@@ -2277,4 +2328,5 @@ def test_api_key_credentials(client_class, transport_class):
22772328
quota_project_id=None,
22782329
client_info=transports.base.DEFAULT_CLIENT_INFO,
22792330
always_use_jwt_access=True,
2331+
api_audience=None,
22802332
)

0 commit comments

Comments
 (0)