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

Commit f019b54

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

File tree

8 files changed

+70
-21
lines changed

8 files changed

+70
-21
lines changed

google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ def __init__(
593593
quota_project_id=client_options.quota_project_id,
594594
client_info=client_info,
595595
always_use_jwt_access=True,
596+
api_audience=client_options.api_audience,
596597
)
597598

598599
def create_build(

google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py

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

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

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

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

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

google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
quota_project_id: Optional[str] = None,
6969
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7070
always_use_jwt_access: Optional[bool] = False,
71+
api_audience: Optional[str] = None,
7172
) -> None:
7273
"""Instantiate the transport.
7374
@@ -164,6 +165,7 @@ def __init__(
164165
quota_project_id=quota_project_id,
165166
client_info=client_info,
166167
always_use_jwt_access=always_use_jwt_access,
168+
api_audience=api_audience,
167169
)
168170

169171
if not self._grpc_channel:

google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def __init__(
113113
quota_project_id=None,
114114
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
115115
always_use_jwt_access: Optional[bool] = False,
116+
api_audience: Optional[str] = None,
116117
) -> None:
117118
"""Instantiate the transport.
118119
@@ -209,6 +210,7 @@ def __init__(
209210
quota_project_id=quota_project_id,
210211
client_info=client_info,
211212
always_use_jwt_access=always_use_jwt_access,
213+
api_audience=api_audience,
212214
)
213215

214216
if not self._grpc_channel:

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
# 'Development Status :: 5 - Production/Stable'
2929
release_status = "Development Status :: 5 - Production/Stable"
3030
dependencies = [
31-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
32-
# Until this issue is closed
33-
# https://github.com/googleapis/google-cloud-python/issues/10566
34-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
31+
"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.*",
3532
"proto-plus >= 1.15.0, <2.0.0dev",
3633
"protobuf >= 3.19.0, <4.0.0dev",
3734
]

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

tests/unit/gapic/cloudbuild_v1/test_cloud_build.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def test_cloud_build_client_client_options(
231231
quota_project_id=None,
232232
client_info=transports.base.DEFAULT_CLIENT_INFO,
233233
always_use_jwt_access=True,
234+
api_audience=None,
234235
)
235236

236237
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -248,6 +249,7 @@ def test_cloud_build_client_client_options(
248249
quota_project_id=None,
249250
client_info=transports.base.DEFAULT_CLIENT_INFO,
250251
always_use_jwt_access=True,
252+
api_audience=None,
251253
)
252254

253255
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -265,6 +267,7 @@ def test_cloud_build_client_client_options(
265267
quota_project_id=None,
266268
client_info=transports.base.DEFAULT_CLIENT_INFO,
267269
always_use_jwt_access=True,
270+
api_audience=None,
268271
)
269272

270273
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -294,6 +297,25 @@ def test_cloud_build_client_client_options(
294297
quota_project_id="octopus",
295298
client_info=transports.base.DEFAULT_CLIENT_INFO,
296299
always_use_jwt_access=True,
300+
api_audience=None,
301+
)
302+
# Check the case api_endpoint is provided
303+
options = client_options.ClientOptions(
304+
api_audience="https://language.googleapis.com"
305+
)
306+
with mock.patch.object(transport_class, "__init__") as patched:
307+
patched.return_value = None
308+
client = client_class(client_options=options, transport=transport_name)
309+
patched.assert_called_once_with(
310+
credentials=None,
311+
credentials_file=None,
312+
host=client.DEFAULT_ENDPOINT,
313+
scopes=None,
314+
client_cert_source_for_mtls=None,
315+
quota_project_id=None,
316+
client_info=transports.base.DEFAULT_CLIENT_INFO,
317+
always_use_jwt_access=True,
318+
api_audience="https://language.googleapis.com",
297319
)
298320

299321

@@ -359,6 +381,7 @@ def test_cloud_build_client_mtls_env_auto(
359381
quota_project_id=None,
360382
client_info=transports.base.DEFAULT_CLIENT_INFO,
361383
always_use_jwt_access=True,
384+
api_audience=None,
362385
)
363386

364387
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -393,6 +416,7 @@ def test_cloud_build_client_mtls_env_auto(
393416
quota_project_id=None,
394417
client_info=transports.base.DEFAULT_CLIENT_INFO,
395418
always_use_jwt_access=True,
419+
api_audience=None,
396420
)
397421

398422
# Check the case client_cert_source and ADC client cert are not provided.
@@ -415,6 +439,7 @@ def test_cloud_build_client_mtls_env_auto(
415439
quota_project_id=None,
416440
client_info=transports.base.DEFAULT_CLIENT_INFO,
417441
always_use_jwt_access=True,
442+
api_audience=None,
418443
)
419444

420445

@@ -525,6 +550,7 @@ def test_cloud_build_client_client_options_scopes(
525550
quota_project_id=None,
526551
client_info=transports.base.DEFAULT_CLIENT_INFO,
527552
always_use_jwt_access=True,
553+
api_audience=None,
528554
)
529555

530556

@@ -558,6 +584,7 @@ def test_cloud_build_client_client_options_credentials_file(
558584
quota_project_id=None,
559585
client_info=transports.base.DEFAULT_CLIENT_INFO,
560586
always_use_jwt_access=True,
587+
api_audience=None,
561588
)
562589

563590

@@ -576,6 +603,7 @@ def test_cloud_build_client_client_options_from_dict():
576603
quota_project_id=None,
577604
client_info=transports.base.DEFAULT_CLIENT_INFO,
578605
always_use_jwt_access=True,
606+
api_audience=None,
579607
)
580608

581609

@@ -609,6 +637,7 @@ def test_cloud_build_client_create_channel_credentials_file(
609637
quota_project_id=None,
610638
client_info=transports.base.DEFAULT_CLIENT_INFO,
611639
always_use_jwt_access=True,
640+
api_audience=None,
612641
)
613642

614643
# test that the credentials from file are saved and used as the credentials.
@@ -6034,6 +6063,28 @@ def test_cloud_build_transport_auth_adc(transport_class):
60346063
)
60356064

60366065

6066+
@pytest.mark.parametrize(
6067+
"transport_class",
6068+
[
6069+
transports.CloudBuildGrpcTransport,
6070+
transports.CloudBuildGrpcAsyncIOTransport,
6071+
],
6072+
)
6073+
def test_cloud_build_transport_auth_gdch_credentials(transport_class):
6074+
host = "https://language.com"
6075+
api_audience_tests = [None, "https://language2.com"]
6076+
api_audience_expect = [host, "https://language2.com"]
6077+
for t, e in zip(api_audience_tests, api_audience_expect):
6078+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
6079+
gdch_mock = mock.MagicMock()
6080+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
6081+
return_value=gdch_mock
6082+
)
6083+
adc.return_value = (gdch_mock, None)
6084+
transport_class(host=host, api_audience=t)
6085+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
6086+
6087+
60376088
@pytest.mark.parametrize(
60386089
"transport_class,grpc_helpers",
60396090
[
@@ -6720,4 +6771,5 @@ def test_api_key_credentials(client_class, transport_class):
67206771
quota_project_id=None,
67216772
client_info=transports.base.DEFAULT_CLIENT_INFO,
67226773
always_use_jwt_access=True,
6774+
api_audience=None,
67236775
)

0 commit comments

Comments
 (0)