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

Commit e82c63f

Browse files
fix(deps): require google-api-core >= 2.8.0 (#343)
- [ ] 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 724935c commit e82c63f

File tree

8 files changed

+70
-20
lines changed

8 files changed

+70
-20
lines changed

google/cloud/iot_v1/services/device_manager/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ def __init__(
454454
quota_project_id=client_options.quota_project_id,
455455
client_info=client_info,
456456
always_use_jwt_access=True,
457+
api_audience=client_options.api_audience,
457458
)
458459

459460
def create_device_registry(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
quota_project_id: Optional[str] = None,
6464
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6565
always_use_jwt_access: Optional[bool] = False,
66+
api_audience: Optional[str] = None,
6667
) -> None:
6768
"""Instantiate the transport.
6869
@@ -158,6 +159,7 @@ def __init__(
158159
quota_project_id=quota_project_id,
159160
client_info=client_info,
160161
always_use_jwt_access=always_use_jwt_access,
162+
api_audience=api_audience,
161163
)
162164

163165
if not self._grpc_channel:

google/cloud/iot_v1/services/device_manager/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
quota_project_id=None,
109109
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
110110
always_use_jwt_access: Optional[bool] = False,
111+
api_audience: Optional[str] = None,
111112
) -> None:
112113
"""Instantiate the transport.
113114
@@ -203,6 +204,7 @@ def __init__(
203204
quota_project_id=quota_project_id,
204205
client_info=client_info,
205206
always_use_jwt_access=always_use_jwt_access,
207+
api_audience=api_audience,
206208
)
207209

208210
if not self._grpc_channel:

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
version = "2.5.1"
2323
release_status = "Development Status :: 5 - Production/Stable"
2424
dependencies = [
25-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
26-
# Until this issue is closed
27-
# https://github.com/googleapis/google-cloud-python/issues/10566
28-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
25+
"google-api-core[grpc] >= 2.8.0, <3.0.0dev",
2926
"grpc-google-iam-v1 >= 0.12.4, <1.0.0dev",
3027
"proto-plus >= 1.15.0, <2.0.0dev",
3128
"protobuf >= 3.19.0, <4.0.0dev",

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
@@ -4,7 +4,7 @@
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==2.8.0
88
proto-plus==1.15.0
99
grpc-google-iam-v1==0.12.4
1010
protobuf==3.19.0

tests/unit/gapic/iot_v1/test_device_manager.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def test_device_manager_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_device_manager_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_device_manager_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_device_manager_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

@@ -363,6 +385,7 @@ def test_device_manager_client_mtls_env_auto(
363385
quota_project_id=None,
364386
client_info=transports.base.DEFAULT_CLIENT_INFO,
365387
always_use_jwt_access=True,
388+
api_audience=None,
366389
)
367390

368391
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -397,6 +420,7 @@ def test_device_manager_client_mtls_env_auto(
397420
quota_project_id=None,
398421
client_info=transports.base.DEFAULT_CLIENT_INFO,
399422
always_use_jwt_access=True,
423+
api_audience=None,
400424
)
401425

402426
# Check the case client_cert_source and ADC client cert are not provided.
@@ -419,6 +443,7 @@ def test_device_manager_client_mtls_env_auto(
419443
quota_project_id=None,
420444
client_info=transports.base.DEFAULT_CLIENT_INFO,
421445
always_use_jwt_access=True,
446+
api_audience=None,
422447
)
423448

424449

@@ -533,6 +558,7 @@ def test_device_manager_client_client_options_scopes(
533558
quota_project_id=None,
534559
client_info=transports.base.DEFAULT_CLIENT_INFO,
535560
always_use_jwt_access=True,
561+
api_audience=None,
536562
)
537563

538564

@@ -571,6 +597,7 @@ def test_device_manager_client_client_options_credentials_file(
571597
quota_project_id=None,
572598
client_info=transports.base.DEFAULT_CLIENT_INFO,
573599
always_use_jwt_access=True,
600+
api_audience=None,
574601
)
575602

576603

@@ -591,6 +618,7 @@ def test_device_manager_client_client_options_from_dict():
591618
quota_project_id=None,
592619
client_info=transports.base.DEFAULT_CLIENT_INFO,
593620
always_use_jwt_access=True,
621+
api_audience=None,
594622
)
595623

596624

@@ -629,6 +657,7 @@ def test_device_manager_client_create_channel_credentials_file(
629657
quota_project_id=None,
630658
client_info=transports.base.DEFAULT_CLIENT_INFO,
631659
always_use_jwt_access=True,
660+
api_audience=None,
632661
)
633662

634663
# test that the credentials from file are saved and used as the credentials.
@@ -6064,6 +6093,28 @@ def test_device_manager_transport_auth_adc(transport_class):
60646093
)
60656094

60666095

6096+
@pytest.mark.parametrize(
6097+
"transport_class",
6098+
[
6099+
transports.DeviceManagerGrpcTransport,
6100+
transports.DeviceManagerGrpcAsyncIOTransport,
6101+
],
6102+
)
6103+
def test_device_manager_transport_auth_gdch_credentials(transport_class):
6104+
host = "https://language.com"
6105+
api_audience_tests = [None, "https://language2.com"]
6106+
api_audience_expect = [host, "https://language2.com"]
6107+
for t, e in zip(api_audience_tests, api_audience_expect):
6108+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
6109+
gdch_mock = mock.MagicMock()
6110+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
6111+
return_value=gdch_mock
6112+
)
6113+
adc.return_value = (gdch_mock, None)
6114+
transport_class(host=host, api_audience=t)
6115+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
6116+
6117+
60676118
@pytest.mark.parametrize(
60686119
"transport_class,grpc_helpers",
60696120
[
@@ -6562,4 +6613,5 @@ def test_api_key_credentials(client_class, transport_class):
65626613
quota_project_id=None,
65636614
client_info=transports.base.DEFAULT_CLIENT_INFO,
65646615
always_use_jwt_access=True,
6616+
api_audience=None,
65656617
)

0 commit comments

Comments
 (0)