Content-Length: 1060518 | pFad | https://github.com/googleapis/python-kms/commit/06a4096a61c8b2ed14ccbf88f386203e2c8dc54e

25 fix(deps): require google-api-core >= 2.8.0 (#311) · googleapis/python-kms@06a4096 · GitHub
Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 06a4096

Browse files
fix(deps): require google-api-core >= 2.8.0 (#311)
- [ ] 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 28d244f commit 06a4096

File tree

13 files changed

+138
-27
lines changed

13 files changed

+138
-27
lines changed

google/cloud/kms_v1/services/ekm_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ def __init__(
462462
quota_project_id=client_options.quota_project_id,
463463
client_info=client_info,
464464
always_use_jwt_access=True,
465+
api_audience=client_options.api_audience,
465466
)
466467

467468
def list_ekm_connections(

google/cloud/kms_v1/services/ekm_service/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6161
always_use_jwt_access: Optional[bool] = False,
62+
api_audience: Optional[str] = None,
6263
**kwargs,
6364
) -> None:
6465
"""Instantiate the transport.
@@ -86,11 +87,6 @@ def __init__(
8687
be used for service account credentials.
8788
"""
8889

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

9692
# Save the scopes.
@@ -111,6 +107,11 @@ def __init__(
111107
credentials, _ = google.auth.default(
112108
**scopes_kwargs, quota_project_id=quota_project_id
113109
)
110+
# Don't apply audience if the credentials file passed from user.
111+
if hasattr(credentials, "with_gdch_audience"):
112+
credentials = credentials.with_gdch_audience(
113+
api_audience if api_audience else host
114+
)
114115

115116
# If the credentials are service account credentials, then always try to use self signed JWT.
116117
if (
@@ -123,6 +124,11 @@ def __init__(
123124
# Save the credentials.
124125
self._credentials = credentials
125126

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

google/cloud/kms_v1/services/ekm_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
quota_project_id: Optional[str] = None,
6666
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6767
always_use_jwt_access: Optional[bool] = False,
68+
api_audience: Optional[str] = None,
6869
) -> None:
6970
"""Instantiate the transport.
7071
@@ -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/kms_v1/services/ekm_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(
110110
quota_project_id=None,
111111
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
112112
always_use_jwt_access: Optional[bool] = False,
113+
api_audience: Optional[str] = None,
113114
) -> None:
114115
"""Instantiate the transport.
115116
@@ -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:

google/cloud/kms_v1/services/key_management_service/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ def __init__(
549549
quota_project_id=client_options.quota_project_id,
550550
client_info=client_info,
551551
always_use_jwt_access=True,
552+
api_audience=client_options.api_audience,
552553
)
553554

554555
def list_key_rings(

google/cloud/kms_v1/services/key_management_service/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
quota_project_id: Optional[str] = None,
6161
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6262
always_use_jwt_access: Optional[bool] = False,
63+
api_audience: Optional[str] = None,
6364
**kwargs,
6465
) -> None:
6566
"""Instantiate the transport.
@@ -87,11 +88,6 @@ def __init__(
8788
be used for service account credentials.
8889
"""
8990

90-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
91-
if ":" not in host:
92-
host += ":443"
93-
self._host = host
94-
9591
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9692

9793
# Save the scopes.
@@ -112,6 +108,11 @@ def __init__(
112108
credentials, _ = google.auth.default(
113109
**scopes_kwargs, quota_project_id=quota_project_id
114110
)
111+
# Don't apply audience if the credentials file passed from user.
112+
if hasattr(credentials, "with_gdch_audience"):
113+
credentials = credentials.with_gdch_audience(
114+
api_audience if api_audience else host
115+
)
115116

116117
# If the credentials are service account credentials, then always try to use self signed JWT.
117118
if (
@@ -124,6 +125,11 @@ def __init__(
124125
# Save the credentials.
125126
self._credentials = credentials
126127

128+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
129+
if ":" not in host:
130+
host += ":443"
131+
self._host = host
132+
127133
def _prep_wrapped_messages(self, client_info):
128134
# Precompute the wrapped methods.
129135
self._wrapped_methods = {

google/cloud/kms_v1/services/key_management_service/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(
7272
quota_project_id: Optional[str] = None,
7373
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7474
always_use_jwt_access: Optional[bool] = False,
75+
api_audience: Optional[str] = None,
7576
) -> None:
7677
"""Instantiate the transport.
7778
@@ -167,6 +168,7 @@ def __init__(
167168
quota_project_id=quota_project_id,
168169
client_info=client_info,
169170
always_use_jwt_access=always_use_jwt_access,
171+
api_audience=api_audience,
170172
)
171173

172174
if not self._grpc_channel:

google/cloud/kms_v1/services/key_management_service/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(
117117
quota_project_id=None,
118118
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
119119
always_use_jwt_access: Optional[bool] = False,
120+
api_audience: Optional[str] = None,
120121
) -> None:
121122
"""Instantiate the transport.
122123
@@ -212,6 +213,7 @@ def __init__(
212213
quota_project_id=quota_project_id,
213214
client_info=client_info,
214215
always_use_jwt_access=always_use_jwt_access,
216+
api_audience=api_audience,
215217
)
216218

217219
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.2"
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/kms_v1/test_ekm_service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def test_ekm_service_client_client_options(
224224
quota_project_id=None,
225225
client_info=transports.base.DEFAULT_CLIENT_INFO,
226226
always_use_jwt_access=True,
227+
api_audience=None,
227228
)
228229

229230
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -241,6 +242,7 @@ def test_ekm_service_client_client_options(
241242
quota_project_id=None,
242243
client_info=transports.base.DEFAULT_CLIENT_INFO,
243244
always_use_jwt_access=True,
245+
api_audience=None,
244246
)
245247

246248
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -258,6 +260,7 @@ def test_ekm_service_client_client_options(
258260
quota_project_id=None,
259261
client_info=transports.base.DEFAULT_CLIENT_INFO,
260262
always_use_jwt_access=True,
263+
api_audience=None,
261264
)
262265

263266
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -287,6 +290,25 @@ def test_ekm_service_client_client_options(
287290
quota_project_id="octopus",
288291
client_info=transports.base.DEFAULT_CLIENT_INFO,
289292
always_use_jwt_access=True,
293+
api_audience=None,
294+
)
295+
# Check the case api_endpoint is provided
296+
options = client_options.ClientOptions(
297+
api_audience="https://language.googleapis.com"
298+
)
299+
with mock.patch.object(transport_class, "__init__") as patched:
300+
patched.return_value = None
301+
client = client_class(client_options=options, transport=transport_name)
302+
patched.assert_called_once_with(
303+
credentials=None,
304+
credentials_file=None,
305+
host=client.DEFAULT_ENDPOINT,
306+
scopes=None,
307+
client_cert_source_for_mtls=None,
308+
quota_project_id=None,
309+
client_info=transports.base.DEFAULT_CLIENT_INFO,
310+
always_use_jwt_access=True,
311+
api_audience="https://language.googleapis.com",
290312
)
291313

292314

@@ -352,6 +374,7 @@ def test_ekm_service_client_mtls_env_auto(
352374
quota_project_id=None,
353375
client_info=transports.base.DEFAULT_CLIENT_INFO,
354376
always_use_jwt_access=True,
377+
api_audience=None,
355378
)
356379

357380
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -386,6 +409,7 @@ def test_ekm_service_client_mtls_env_auto(
386409
quota_project_id=None,
387410
client_info=transports.base.DEFAULT_CLIENT_INFO,
388411
always_use_jwt_access=True,
412+
api_audience=None,
389413
)
390414

391415
# Check the case client_cert_source and ADC client cert are not provided.
@@ -408,6 +432,7 @@ def test_ekm_service_client_mtls_env_auto(
408432
quota_project_id=None,
409433
client_info=transports.base.DEFAULT_CLIENT_INFO,
410434
always_use_jwt_access=True,
435+
api_audience=None,
411436
)
412437

413438

@@ -518,6 +543,7 @@ def test_ekm_service_client_client_options_scopes(
518543
quota_project_id=None,
519544
client_info=transports.base.DEFAULT_CLIENT_INFO,
520545
always_use_jwt_access=True,
546+
api_audience=None,
521547
)
522548

523549

@@ -551,6 +577,7 @@ def test_ekm_service_client_client_options_credentials_file(
551577
quota_project_id=None,
552578
client_info=transports.base.DEFAULT_CLIENT_INFO,
553579
always_use_jwt_access=True,
580+
api_audience=None,
554581
)
555582

556583

@@ -569,6 +596,7 @@ def test_ekm_service_client_client_options_from_dict():
569596
quota_project_id=None,
570597
client_info=transports.base.DEFAULT_CLIENT_INFO,
571598
always_use_jwt_access=True,
599+
api_audience=None,
572600
)
573601

574602

@@ -602,6 +630,7 @@ def test_ekm_service_client_create_channel_credentials_file(
602630
quota_project_id=None,
603631
client_info=transports.base.DEFAULT_CLIENT_INFO,
604632
always_use_jwt_access=True,
633+
api_audience=None,
605634
)
606635

607636
# test that the credentials from file are saved and used as the credentials.
@@ -2096,6 +2125,28 @@ def test_ekm_service_transport_auth_adc(transport_class):
20962125
)
20972126

20982127

2128+
@pytest.mark.parametrize(
2129+
"transport_class",
2130+
[
2131+
transports.EkmServiceGrpcTransport,
2132+
transports.EkmServiceGrpcAsyncIOTransport,
2133+
],
2134+
)
2135+
def test_ekm_service_transport_auth_gdch_credentials(transport_class):
2136+
host = "https://language.com"
2137+
api_audience_tests = [None, "https://language2.com"]
2138+
api_audience_expect = [host, "https://language2.com"]
2139+
for t, e in zip(api_audience_tests, api_audience_expect):
2140+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
2141+
gdch_mock = mock.MagicMock()
2142+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
2143+
return_value=gdch_mock
2144+
)
2145+
adc.return_value = (gdch_mock, None)
2146+
transport_class(host=host, api_audience=t)
2147+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
2148+
2149+
20992150
@pytest.mark.parametrize(
21002151
"transport_class,grpc_helpers",
21012152
[
@@ -3093,4 +3144,5 @@ def test_api_key_credentials(client_class, transport_class):
30933144
quota_project_id=None,
30943145
client_info=transports.base.DEFAULT_CLIENT_INFO,
30953146
always_use_jwt_access=True,
3147+
api_audience=None,
30963148
)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-kms/commit/06a4096a61c8b2ed14ccbf88f386203e2c8dc54e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy