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

Commit 66f14c9

Browse files
fix: enable self signed jwt for grpc (#58)
PiperOrigin-RevId: 386504689 Source-Link: googleapis/googleapis@762094a Source-Link: https://github.com/googleapis/googleapis-gen/commit/6bfc480e1a161d5de121c2bcc3745885d33b265a
1 parent 6c54ae1 commit 66f14c9

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/gkehub_v1/services/gke_hub/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ def __init__(
379379
client_cert_source_for_mtls=client_cert_source_func,
380380
quota_project_id=client_options.quota_project_id,
381381
client_info=client_info,
382+
always_use_jwt_access=(
383+
Transport == type(self).get_transport_class("grpc")
384+
or Transport == type(self).get_transport_class("grpc_asyncio")
385+
),
382386
)
383387

384388
def list_memberships(

tests/unit/gapic/gkehub_v1/test_gke_hub.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,28 @@ def test_gke_hub_client_from_service_account_info(client_class):
118118
assert client.transport._host == "gkehub.googleapis.com:443"
119119

120120

121-
@pytest.mark.parametrize("client_class", [GkeHubClient, GkeHubAsyncClient,])
122-
def test_gke_hub_client_service_account_always_use_jwt(client_class):
123-
with mock.patch.object(
124-
service_account.Credentials, "with_always_use_jwt_access", create=True
125-
) as use_jwt:
126-
creds = service_account.Credentials(None, None, None)
127-
client = client_class(credentials=creds)
128-
use_jwt.assert_not_called()
129-
130-
131121
@pytest.mark.parametrize(
132122
"transport_class,transport_name",
133123
[
134124
(transports.GkeHubGrpcTransport, "grpc"),
135125
(transports.GkeHubGrpcAsyncIOTransport, "grpc_asyncio"),
136126
],
137127
)
138-
def test_gke_hub_client_service_account_always_use_jwt_true(
139-
transport_class, transport_name
140-
):
128+
def test_gke_hub_client_service_account_always_use_jwt(transport_class, transport_name):
141129
with mock.patch.object(
142130
service_account.Credentials, "with_always_use_jwt_access", create=True
143131
) as use_jwt:
144132
creds = service_account.Credentials(None, None, None)
145133
transport = transport_class(credentials=creds, always_use_jwt_access=True)
146134
use_jwt.assert_called_once_with(True)
147135

136+
with mock.patch.object(
137+
service_account.Credentials, "with_always_use_jwt_access", create=True
138+
) as use_jwt:
139+
creds = service_account.Credentials(None, None, None)
140+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
141+
use_jwt.assert_not_called()
142+
148143

149144
@pytest.mark.parametrize("client_class", [GkeHubClient, GkeHubAsyncClient,])
150145
def test_gke_hub_client_from_service_account_file(client_class):
@@ -213,6 +208,7 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_
213208
client_cert_source_for_mtls=None,
214209
quota_project_id=None,
215210
client_info=transports.base.DEFAULT_CLIENT_INFO,
211+
always_use_jwt_access=True,
216212
)
217213

218214
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -229,6 +225,7 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_
229225
client_cert_source_for_mtls=None,
230226
quota_project_id=None,
231227
client_info=transports.base.DEFAULT_CLIENT_INFO,
228+
always_use_jwt_access=True,
232229
)
233230

234231
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -245,6 +242,7 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_
245242
client_cert_source_for_mtls=None,
246243
quota_project_id=None,
247244
client_info=transports.base.DEFAULT_CLIENT_INFO,
245+
always_use_jwt_access=True,
248246
)
249247

250248
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -273,6 +271,7 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_
273271
client_cert_source_for_mtls=None,
274272
quota_project_id="octopus",
275273
client_info=transports.base.DEFAULT_CLIENT_INFO,
274+
always_use_jwt_access=True,
276275
)
277276

278277

@@ -335,6 +334,7 @@ def test_gke_hub_client_mtls_env_auto(
335334
client_cert_source_for_mtls=expected_client_cert_source,
336335
quota_project_id=None,
337336
client_info=transports.base.DEFAULT_CLIENT_INFO,
337+
always_use_jwt_access=True,
338338
)
339339

340340
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -368,6 +368,7 @@ def test_gke_hub_client_mtls_env_auto(
368368
client_cert_source_for_mtls=expected_client_cert_source,
369369
quota_project_id=None,
370370
client_info=transports.base.DEFAULT_CLIENT_INFO,
371+
always_use_jwt_access=True,
371372
)
372373

373374
# Check the case client_cert_source and ADC client cert are not provided.
@@ -389,6 +390,7 @@ def test_gke_hub_client_mtls_env_auto(
389390
client_cert_source_for_mtls=None,
390391
quota_project_id=None,
391392
client_info=transports.base.DEFAULT_CLIENT_INFO,
393+
always_use_jwt_access=True,
392394
)
393395

394396

@@ -415,6 +417,7 @@ def test_gke_hub_client_client_options_scopes(
415417
client_cert_source_for_mtls=None,
416418
quota_project_id=None,
417419
client_info=transports.base.DEFAULT_CLIENT_INFO,
420+
always_use_jwt_access=True,
418421
)
419422

420423

@@ -441,6 +444,7 @@ def test_gke_hub_client_client_options_credentials_file(
441444
client_cert_source_for_mtls=None,
442445
quota_project_id=None,
443446
client_info=transports.base.DEFAULT_CLIENT_INFO,
447+
always_use_jwt_access=True,
444448
)
445449

446450

@@ -458,6 +462,7 @@ def test_gke_hub_client_client_options_from_dict():
458462
client_cert_source_for_mtls=None,
459463
quota_project_id=None,
460464
client_info=transports.base.DEFAULT_CLIENT_INFO,
465+
always_use_jwt_access=True,
461466
)
462467

463468

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy