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

Commit f8824ce

Browse files
fix(deps): require google-api-core >= 2.8.0 (#74)
* 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 a4e7d42 commit f8824ce

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

google/cloud/video/live_stream_v1/services/livestream_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def __init__(
484484
quota_project_id=client_options.quota_project_id,
485485
client_info=client_info,
486486
always_use_jwt_access=True,
487+
api_audience=client_options.api_audience,
487488
)
488489

489490
def create_channel(

google/cloud/video/live_stream_v1/services/livestream_service/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
quota_project_id: Optional[str] = None,
5757
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
5858
always_use_jwt_access: Optional[bool] = False,
59+
api_audience: Optional[str] = None,
5960
**kwargs,
6061
) -> None:
6162
"""Instantiate the transport.
@@ -83,11 +84,6 @@ def __init__(
8384
be used for service account credentials.
8485
"""
8586

86-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
87-
if ":" not in host:
88-
host += ":443"
89-
self._host = host
90-
9187
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9288

9389
# Save the scopes.
@@ -108,6 +104,11 @@ def __init__(
108104
credentials, _ = google.auth.default(
109105
**scopes_kwargs, quota_project_id=quota_project_id
110106
)
107+
# Don't apply audience if the credentials file passed from user.
108+
if hasattr(credentials, "with_gdch_audience"):
109+
credentials = credentials.with_gdch_audience(
110+
api_audience if api_audience else host
111+
)
111112

112113
# If the credentials are service account credentials, then always try to use self signed JWT.
113114
if (
@@ -120,6 +121,11 @@ def __init__(
120121
# Save the credentials.
121122
self._credentials = credentials
122123

124+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
125+
if ":" not in host:
126+
host += ":443"
127+
self._host = host
128+
123129
def _prep_wrapped_messages(self, client_info):
124130
# Precompute the wrapped methods.
125131
self._wrapped_methods = {

google/cloud/video/live_stream_v1/services/livestream_service/transports/grpc.py

Lines changed: 2 additions & 0 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
) -> None:
6869
"""Instantiate the transport.
6970
@@ -160,6 +161,7 @@ def __init__(
160161
quota_project_id=quota_project_id,
161162
client_info=client_info,
162163
always_use_jwt_access=always_use_jwt_access,
164+
api_audience=api_audience,
163165
)
164166

165167
if not self._grpc_channel:

google/cloud/video/live_stream_v1/services/livestream_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(
109109
quota_project_id=None,
110110
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
111111
always_use_jwt_access: Optional[bool] = False,
112+
api_audience: Optional[str] = None,
112113
) -> None:
113114
"""Instantiate the transport.
114115
@@ -205,6 +206,7 @@ def __init__(
205206
quota_project_id=quota_project_id,
206207
client_info=client_info,
207208
always_use_jwt_access=always_use_jwt_access,
209+
api_audience=api_audience,
208210
)
209211

210212
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
version = "0.1.5"
2626
release_status = "Development Status :: 4 - Beta"
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 & 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==2.8.0
88
proto-plus==1.15.0
99
protobuf==3.19.0

tests/unit/gapic/live_stream_v1/test_livestream_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def test_livestream_service_client_client_options(
243243
quota_project_id=None,
244244
client_info=transports.base.DEFAULT_CLIENT_INFO,
245245
always_use_jwt_access=True,
246+
api_audience=None,
246247
)
247248

248249
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -260,6 +261,7 @@ def test_livestream_service_client_client_options(
260261
quota_project_id=None,
261262
client_info=transports.base.DEFAULT_CLIENT_INFO,
262263
always_use_jwt_access=True,
264+
api_audience=None,
263265
)
264266

265267
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -277,6 +279,7 @@ def test_livestream_service_client_client_options(
277279
quota_project_id=None,
278280
client_info=transports.base.DEFAULT_CLIENT_INFO,
279281
always_use_jwt_access=True,
282+
api_audience=None,
280283
)
281284

282285
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -306,6 +309,25 @@ def test_livestream_service_client_client_options(
306309
quota_project_id="octopus",
307310
client_info=transports.base.DEFAULT_CLIENT_INFO,
308311
always_use_jwt_access=True,
312+
api_audience=None,
313+
)
314+
# Check the case api_endpoint is provided
315+
options = client_options.ClientOptions(
316+
api_audience="https://language.googleapis.com"
317+
)
318+
with mock.patch.object(transport_class, "__init__") as patched:
319+
patched.return_value = None
320+
client = client_class(client_options=options, transport=transport_name)
321+
patched.assert_called_once_with(
322+
credentials=None,
323+
credentials_file=None,
324+
host=client.DEFAULT_ENDPOINT,
325+
scopes=None,
326+
client_cert_source_for_mtls=None,
327+
quota_project_id=None,
328+
client_info=transports.base.DEFAULT_CLIENT_INFO,
329+
always_use_jwt_access=True,
330+
api_audience="https://language.googleapis.com",
309331
)
310332

311333

@@ -383,6 +405,7 @@ def test_livestream_service_client_mtls_env_auto(
383405
quota_project_id=None,
384406
client_info=transports.base.DEFAULT_CLIENT_INFO,
385407
always_use_jwt_access=True,
408+
api_audience=None,
386409
)
387410

388411
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -417,6 +440,7 @@ def test_livestream_service_client_mtls_env_auto(
417440
quota_project_id=None,
418441
client_info=transports.base.DEFAULT_CLIENT_INFO,
419442
always_use_jwt_access=True,
443+
api_audience=None,
420444
)
421445

422446
# Check the case client_cert_source and ADC client cert are not provided.
@@ -439,6 +463,7 @@ def test_livestream_service_client_mtls_env_auto(
439463
quota_project_id=None,
440464
client_info=transports.base.DEFAULT_CLIENT_INFO,
441465
always_use_jwt_access=True,
466+
api_audience=None,
442467
)
443468

444469

@@ -553,6 +578,7 @@ def test_livestream_service_client_client_options_scopes(
553578
quota_project_id=None,
554579
client_info=transports.base.DEFAULT_CLIENT_INFO,
555580
always_use_jwt_access=True,
581+
api_audience=None,
556582
)
557583

558584

@@ -591,6 +617,7 @@ def test_livestream_service_client_client_options_credentials_file(
591617
quota_project_id=None,
592618
client_info=transports.base.DEFAULT_CLIENT_INFO,
593619
always_use_jwt_access=True,
620+
api_audience=None,
594621
)
595622

596623

@@ -611,6 +638,7 @@ def test_livestream_service_client_client_options_from_dict():
611638
quota_project_id=None,
612639
client_info=transports.base.DEFAULT_CLIENT_INFO,
613640
always_use_jwt_access=True,
641+
api_audience=None,
614642
)
615643

616644

@@ -649,6 +677,7 @@ def test_livestream_service_client_create_channel_credentials_file(
649677
quota_project_id=None,
650678
client_info=transports.base.DEFAULT_CLIENT_INFO,
651679
always_use_jwt_access=True,
680+
api_audience=None,
652681
)
653682

654683
# test that the credentials from file are saved and used as the credentials.
@@ -5253,6 +5282,28 @@ def test_livestream_service_transport_auth_adc(transport_class):
52535282
)
52545283

52555284

5285+
@pytest.mark.parametrize(
5286+
"transport_class",
5287+
[
5288+
transports.LivestreamServiceGrpcTransport,
5289+
transports.LivestreamServiceGrpcAsyncIOTransport,
5290+
],
5291+
)
5292+
def test_livestream_service_transport_auth_gdch_credentials(transport_class):
5293+
host = "https://language.com"
5294+
api_audience_tests = [None, "https://language2.com"]
5295+
api_audience_expect = [host, "https://language2.com"]
5296+
for t, e in zip(api_audience_tests, api_audience_expect):
5297+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
5298+
gdch_mock = mock.MagicMock()
5299+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
5300+
return_value=gdch_mock
5301+
)
5302+
adc.return_value = (gdch_mock, None)
5303+
transport_class(host=host, api_audience=t)
5304+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
5305+
5306+
52565307
@pytest.mark.parametrize(
52575308
"transport_class,grpc_helpers",
52585309
[
@@ -5813,4 +5864,5 @@ def test_api_key_credentials(client_class, transport_class):
58135864
quota_project_id=None,
58145865
client_info=transports.base.DEFAULT_CLIENT_INFO,
58155866
always_use_jwt_access=True,
5867+
api_audience=None,
58165868
)

0 commit comments

Comments
 (0)