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

Commit f5ffbce

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

File tree

8 files changed

+70
-20
lines changed

8 files changed

+70
-20
lines changed

google/cloud/essential_contacts_v1/services/essential_contacts_service/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 create_contact(

google/cloud/essential_contacts_v1/services/essential_contacts_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/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
quota_project_id: Optional[str] = None,
5959
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6060
always_use_jwt_access: Optional[bool] = False,
61+
api_audience: Optional[str] = None,
6162
) -> None:
6263
"""Instantiate the transport.
6364
@@ -153,6 +154,7 @@ def __init__(
153154
quota_project_id=quota_project_id,
154155
client_info=client_info,
155156
always_use_jwt_access=always_use_jwt_access,
157+
api_audience=api_audience,
156158
)
157159

158160
if not self._grpc_channel:

google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(
103103
quota_project_id=None,
104104
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
105105
always_use_jwt_access: Optional[bool] = False,
106+
api_audience: Optional[str] = None,
106107
) -> None:
107108
"""Instantiate the transport.
108109
@@ -198,6 +199,7 @@ def __init__(
198199
quota_project_id=quota_project_id,
199200
client_info=client_info,
200201
always_use_jwt_access=always_use_jwt_access,
202+
api_audience=api_audience,
201203
)
202204

203205
if not self._grpc_channel:

setup.py

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

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

tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py

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

@@ -555,6 +580,7 @@ def test_essential_contacts_service_client_client_options_scopes(
555580
quota_project_id=None,
556581
client_info=transports.base.DEFAULT_CLIENT_INFO,
557582
always_use_jwt_access=True,
583+
api_audience=None,
558584
)
559585

560586

@@ -593,6 +619,7 @@ def test_essential_contacts_service_client_client_options_credentials_file(
593619
quota_project_id=None,
594620
client_info=transports.base.DEFAULT_CLIENT_INFO,
595621
always_use_jwt_access=True,
622+
api_audience=None,
596623
)
597624

598625

@@ -613,6 +640,7 @@ def test_essential_contacts_service_client_client_options_from_dict():
613640
quota_project_id=None,
614641
client_info=transports.base.DEFAULT_CLIENT_INFO,
615642
always_use_jwt_access=True,
643+
api_audience=None,
616644
)
617645

618646

@@ -651,6 +679,7 @@ def test_essential_contacts_service_client_create_channel_credentials_file(
651679
quota_project_id=None,
652680
client_info=transports.base.DEFAULT_CLIENT_INFO,
653681
always_use_jwt_access=True,
682+
api_audience=None,
654683
)
655684

656685
# test that the credentials from file are saved and used as the credentials.
@@ -2799,6 +2828,28 @@ def test_essential_contacts_service_transport_auth_adc(transport_class):
27992828
)
28002829

28012830

2831+
@pytest.mark.parametrize(
2832+
"transport_class",
2833+
[
2834+
transports.EssentialContactsServiceGrpcTransport,
2835+
transports.EssentialContactsServiceGrpcAsyncIOTransport,
2836+
],
2837+
)
2838+
def test_essential_contacts_service_transport_auth_gdch_credentials(transport_class):
2839+
host = "https://language.com"
2840+
api_audience_tests = [None, "https://language2.com"]
2841+
api_audience_expect = [host, "https://language2.com"]
2842+
for t, e in zip(api_audience_tests, api_audience_expect):
2843+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
2844+
gdch_mock = mock.MagicMock()
2845+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
2846+
return_value=gdch_mock
2847+
)
2848+
adc.return_value = (gdch_mock, None)
2849+
transport_class(host=host, api_audience=t)
2850+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
2851+
2852+
28022853
@pytest.mark.parametrize(
28032854
"transport_class,grpc_helpers",
28042855
[
@@ -3274,4 +3325,5 @@ def test_api_key_credentials(client_class, transport_class):
32743325
quota_project_id=None,
32753326
client_info=transports.base.DEFAULT_CLIENT_INFO,
32763327
always_use_jwt_access=True,
3328+
api_audience=None,
32773329
)

0 commit comments

Comments
 (0)