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

Commit bf4130e

Browse files
fix(deps): require google-api-core >= 2.8.0 (#315)
- [ ] 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 971a802 commit bf4130e

File tree

8 files changed

+70
-22
lines changed

8 files changed

+70
-22
lines changed

google/cloud/secretmanager_v1/services/secret_manager_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ def __init__(
472472
quota_project_id=client_options.quota_project_id,
473473
client_info=client_info,
474474
always_use_jwt_access=True,
475+
api_audience=client_options.api_audience,
475476
)
476477

477478
def list_secrets(

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

Lines changed: 2 additions & 0 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
) -> None:
7071
"""Instantiate the transport.
7172
@@ -161,6 +162,7 @@ def __init__(
161162
quota_project_id=quota_project_id,
162163
client_info=client_info,
163164
always_use_jwt_access=always_use_jwt_access,
165+
api_audience=api_audience,
164166
)
165167

166168
if not self._grpc_channel:

google/cloud/secretmanager_v1/services/secret_manager_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(
111111
quota_project_id=None,
112112
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
113113
always_use_jwt_access: Optional[bool] = False,
114+
api_audience: Optional[str] = None,
114115
) -> None:
115116
"""Instantiate the transport.
116117
@@ -206,6 +207,7 @@ def __init__(
206207
quota_project_id=quota_project_id,
207208
client_info=client_info,
208209
always_use_jwt_access=always_use_jwt_access,
210+
api_audience=api_audience,
209211
)
210212

211213
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 = "2.11.1"
2525
release_status = "Development Status :: 5 - Production/Stable"
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
"grpc-google-iam-v1 >= 0.12.4, <1.0.0dev",
3229
"proto-plus >= 1.15.0, <2.0.0dev",
3330
"protobuf >= 3.19.0, <4.0.0dev",

testing/constraints-3.6.txt

Lines changed: 0 additions & 12 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
grpc-google-iam-v1==0.12.4
1010
proto-plus==1.15.0
1111
libcst==0.2.5

tests/unit/gapic/secretmanager_v1/test_secret_manager_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def test_secret_manager_service_client_client_options(
239239
quota_project_id=None,
240240
client_info=transports.base.DEFAULT_CLIENT_INFO,
241241
always_use_jwt_access=True,
242+
api_audience=None,
242243
)
243244

244245
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -256,6 +257,7 @@ def test_secret_manager_service_client_client_options(
256257
quota_project_id=None,
257258
client_info=transports.base.DEFAULT_CLIENT_INFO,
258259
always_use_jwt_access=True,
260+
api_audience=None,
259261
)
260262

261263
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -273,6 +275,7 @@ def test_secret_manager_service_client_client_options(
273275
quota_project_id=None,
274276
client_info=transports.base.DEFAULT_CLIENT_INFO,
275277
always_use_jwt_access=True,
278+
api_audience=None,
276279
)
277280

278281
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -302,6 +305,25 @@ def test_secret_manager_service_client_client_options(
302305
quota_project_id="octopus",
303306
client_info=transports.base.DEFAULT_CLIENT_INFO,
304307
always_use_jwt_access=True,
308+
api_audience=None,
309+
)
310+
# Check the case api_endpoint is provided
311+
options = client_options.ClientOptions(
312+
api_audience="https://language.googleapis.com"
313+
)
314+
with mock.patch.object(transport_class, "__init__") as patched:
315+
patched.return_value = None
316+
client = client_class(client_options=options, transport=transport_name)
317+
patched.assert_called_once_with(
318+
credentials=None,
319+
credentials_file=None,
320+
host=client.DEFAULT_ENDPOINT,
321+
scopes=None,
322+
client_cert_source_for_mtls=None,
323+
quota_project_id=None,
324+
client_info=transports.base.DEFAULT_CLIENT_INFO,
325+
always_use_jwt_access=True,
326+
api_audience="https://language.googleapis.com",
305327
)
306328

307329

@@ -379,6 +401,7 @@ def test_secret_manager_service_client_mtls_env_auto(
379401
quota_project_id=None,
380402
client_info=transports.base.DEFAULT_CLIENT_INFO,
381403
always_use_jwt_access=True,
404+
api_audience=None,
382405
)
383406

384407
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -413,6 +436,7 @@ def test_secret_manager_service_client_mtls_env_auto(
413436
quota_project_id=None,
414437
client_info=transports.base.DEFAULT_CLIENT_INFO,
415438
always_use_jwt_access=True,
439+
api_audience=None,
416440
)
417441

418442
# Check the case client_cert_source and ADC client cert are not provided.
@@ -435,6 +459,7 @@ def test_secret_manager_service_client_mtls_env_auto(
435459
quota_project_id=None,
436460
client_info=transports.base.DEFAULT_CLIENT_INFO,
437461
always_use_jwt_access=True,
462+
api_audience=None,
438463
)
439464

440465

@@ -553,6 +578,7 @@ def test_secret_manager_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_secret_manager_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_secret_manager_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_secret_manager_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.
@@ -4797,6 +4826,28 @@ def test_secret_manager_service_transport_auth_adc(transport_class):
47974826
)
47984827

47994828

4829+
@pytest.mark.parametrize(
4830+
"transport_class",
4831+
[
4832+
transports.SecretManagerServiceGrpcTransport,
4833+
transports.SecretManagerServiceGrpcAsyncIOTransport,
4834+
],
4835+
)
4836+
def test_secret_manager_service_transport_auth_gdch_credentials(transport_class):
4837+
host = "https://language.com"
4838+
api_audience_tests = [None, "https://language2.com"]
4839+
api_audience_expect = [host, "https://language2.com"]
4840+
for t, e in zip(api_audience_tests, api_audience_expect):
4841+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
4842+
gdch_mock = mock.MagicMock()
4843+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
4844+
return_value=gdch_mock
4845+
)
4846+
adc.return_value = (gdch_mock, None)
4847+
transport_class(host=host, api_audience=t)
4848+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
4849+
4850+
48004851
@pytest.mark.parametrize(
48014852
"transport_class,grpc_helpers",
48024853
[
@@ -5318,4 +5369,5 @@ def test_api_key_credentials(client_class, transport_class):
53185369
quota_project_id=None,
53195370
client_info=transports.base.DEFAULT_CLIENT_INFO,
53205371
always_use_jwt_access=True,
5372+
api_audience=None,
53215373
)

0 commit comments

Comments
 (0)