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

Commit 4d6cfed

Browse files
fix(deps): require google-api-core >= 2.8.0 (#249)
* 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 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: use gapic-generator-python 1.1.1 PiperOrigin-RevId: 459095142 Source-Link: googleapis/googleapis@4f1be99 Source-Link: https://github.com/googleapis/googleapis-gen/commit/ae686d9cde4fc3e36d0ac02efb8643b15890c1ed Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWU2ODZkOWNkZTRmYzNlMzZkMGFjMDJlZmI4NjQzYjE1ODkwYzFlZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix(deps): require google-api-core 2.8.0 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 8b1fdd2 commit 4d6cfed

File tree

8 files changed

+70
-21
lines changed

8 files changed

+70
-21
lines changed

google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ def __init__(
587587
quota_project_id=client_options.quota_project_id,
588588
client_info=client_info,
589589
always_use_jwt_access=True,
590+
api_audience=client_options.api_audience,
590591
)
591592

592593
def create_dataset(

google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
quota_project_id: Optional[str] = None,
6767
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6868
always_use_jwt_access: Optional[bool] = False,
69+
api_audience: Optional[str] = None,
6970
**kwargs,
7071
) -> None:
7172
"""Instantiate the transport.
@@ -93,11 +94,6 @@ def __init__(
9394
be used for service account credentials.
9495
"""
9596

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

10399
# Save the scopes.
@@ -118,6 +114,11 @@ def __init__(
118114
credentials, _ = google.auth.default(
119115
**scopes_kwargs, quota_project_id=quota_project_id
120116
)
117+
# Don't apply audience if the credentials file passed from user.
118+
if hasattr(credentials, "with_gdch_audience"):
119+
credentials = credentials.with_gdch_audience(
120+
api_audience if api_audience else host
121+
)
121122

122123
# If the credentials are service account credentials, then always try to use self signed JWT.
123124
if (
@@ -130,6 +131,11 @@ def __init__(
130131
# Save the credentials.
131132
self._credentials = credentials
132133

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

google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(
6969
quota_project_id: Optional[str] = None,
7070
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7171
always_use_jwt_access: Optional[bool] = False,
72+
api_audience: Optional[str] = None,
7273
) -> None:
7374
"""Instantiate the transport.
7475
@@ -165,6 +166,7 @@ def __init__(
165166
quota_project_id=quota_project_id,
166167
client_info=client_info,
167168
always_use_jwt_access=always_use_jwt_access,
169+
api_audience=api_audience,
168170
)
169171

170172
if not self._grpc_channel:

google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def __init__(
114114
quota_project_id=None,
115115
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
116116
always_use_jwt_access: Optional[bool] = False,
117+
api_audience: Optional[str] = None,
117118
) -> None:
118119
"""Instantiate the transport.
119120
@@ -210,6 +211,7 @@ def __init__(
210211
quota_project_id=quota_project_id,
211212
client_info=client_info,
212213
always_use_jwt_access=always_use_jwt_access,
214+
api_audience=api_audience,
213215
)
214216

215217
if not self._grpc_channel:

setup.py

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

testing/constraints-3.6.txt

Lines changed: 0 additions & 11 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,7 +5,7 @@
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
libcst==0.2.5
1010
proto-plus==1.15.0
1111
protobuf==3.19.0

tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def test_data_labeling_service_client_client_options(
261261
quota_project_id=None,
262262
client_info=transports.base.DEFAULT_CLIENT_INFO,
263263
always_use_jwt_access=True,
264+
api_audience=None,
264265
)
265266

266267
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -278,6 +279,7 @@ def test_data_labeling_service_client_client_options(
278279
quota_project_id=None,
279280
client_info=transports.base.DEFAULT_CLIENT_INFO,
280281
always_use_jwt_access=True,
282+
api_audience=None,
281283
)
282284

283285
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -295,6 +297,7 @@ def test_data_labeling_service_client_client_options(
295297
quota_project_id=None,
296298
client_info=transports.base.DEFAULT_CLIENT_INFO,
297299
always_use_jwt_access=True,
300+
api_audience=None,
298301
)
299302

300303
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -324,6 +327,25 @@ def test_data_labeling_service_client_client_options(
324327
quota_project_id="octopus",
325328
client_info=transports.base.DEFAULT_CLIENT_INFO,
326329
always_use_jwt_access=True,
330+
api_audience=None,
331+
)
332+
# Check the case api_endpoint is provided
333+
options = client_options.ClientOptions(
334+
api_audience="https://language.googleapis.com"
335+
)
336+
with mock.patch.object(transport_class, "__init__") as patched:
337+
patched.return_value = None
338+
client = client_class(client_options=options, transport=transport_name)
339+
patched.assert_called_once_with(
340+
credentials=None,
341+
credentials_file=None,
342+
host=client.DEFAULT_ENDPOINT,
343+
scopes=None,
344+
client_cert_source_for_mtls=None,
345+
quota_project_id=None,
346+
client_info=transports.base.DEFAULT_CLIENT_INFO,
347+
always_use_jwt_access=True,
348+
api_audience="https://language.googleapis.com",
327349
)
328350

329351

@@ -401,6 +423,7 @@ def test_data_labeling_service_client_mtls_env_auto(
401423
quota_project_id=None,
402424
client_info=transports.base.DEFAULT_CLIENT_INFO,
403425
always_use_jwt_access=True,
426+
api_audience=None,
404427
)
405428

406429
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -435,6 +458,7 @@ def test_data_labeling_service_client_mtls_env_auto(
435458
quota_project_id=None,
436459
client_info=transports.base.DEFAULT_CLIENT_INFO,
437460
always_use_jwt_access=True,
461+
api_audience=None,
438462
)
439463

440464
# Check the case client_cert_source and ADC client cert are not provided.
@@ -457,6 +481,7 @@ def test_data_labeling_service_client_mtls_env_auto(
457481
quota_project_id=None,
458482
client_info=transports.base.DEFAULT_CLIENT_INFO,
459483
always_use_jwt_access=True,
484+
api_audience=None,
460485
)
461486

462487

@@ -575,6 +600,7 @@ def test_data_labeling_service_client_client_options_scopes(
575600
quota_project_id=None,
576601
client_info=transports.base.DEFAULT_CLIENT_INFO,
577602
always_use_jwt_access=True,
603+
api_audience=None,
578604
)
579605

580606

@@ -613,6 +639,7 @@ def test_data_labeling_service_client_client_options_credentials_file(
613639
quota_project_id=None,
614640
client_info=transports.base.DEFAULT_CLIENT_INFO,
615641
always_use_jwt_access=True,
642+
api_audience=None,
616643
)
617644

618645

@@ -633,6 +660,7 @@ def test_data_labeling_service_client_client_options_from_dict():
633660
quota_project_id=None,
634661
client_info=transports.base.DEFAULT_CLIENT_INFO,
635662
always_use_jwt_access=True,
663+
api_audience=None,
636664
)
637665

638666

@@ -671,6 +699,7 @@ def test_data_labeling_service_client_create_channel_credentials_file(
671699
quota_project_id=None,
672700
client_info=transports.base.DEFAULT_CLIENT_INFO,
673701
always_use_jwt_access=True,
702+
api_audience=None,
674703
)
675704

676705
# test that the credentials from file are saved and used as the credentials.
@@ -11184,6 +11213,28 @@ def test_data_labeling_service_transport_auth_adc(transport_class):
1118411213
)
1118511214

1118611215

11216+
@pytest.mark.parametrize(
11217+
"transport_class",
11218+
[
11219+
transports.DataLabelingServiceGrpcTransport,
11220+
transports.DataLabelingServiceGrpcAsyncIOTransport,
11221+
],
11222+
)
11223+
def test_data_labeling_service_transport_auth_gdch_credentials(transport_class):
11224+
host = "https://language.com"
11225+
api_audience_tests = [None, "https://language2.com"]
11226+
api_audience_expect = [host, "https://language2.com"]
11227+
for t, e in zip(api_audience_tests, api_audience_expect):
11228+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
11229+
gdch_mock = mock.MagicMock()
11230+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
11231+
return_value=gdch_mock
11232+
)
11233+
adc.return_value = (gdch_mock, None)
11234+
transport_class(host=host, api_audience=t)
11235+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
11236+
11237+
1118711238
@pytest.mark.parametrize(
1118811239
"transport_class,grpc_helpers",
1118911240
[
@@ -11870,4 +11921,5 @@ def test_api_key_credentials(client_class, transport_class):
1187011921
quota_project_id=None,
1187111922
client_info=transports.base.DEFAULT_CLIENT_INFO,
1187211923
always_use_jwt_access=True,
11924+
api_audience=None,
1187311925
)

0 commit comments

Comments
 (0)