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

Commit 9091e3f

Browse files
1 parent c356de8 commit 9091e3f

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ def __init__(
334334
client_cert_source_for_mtls=client_cert_source_func,
335335
quota_project_id=client_options.quota_project_id,
336336
client_info=client_info,
337+
always_use_jwt_access=(
338+
Transport == type(self).get_transport_class("grpc")
339+
or Transport == type(self).get_transport_class("grpc_asyncio")
340+
),
337341
)
338342

339343
def get_resource(

tests/unit/gapic/gateway_v1beta1/test_gateway_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,14 @@ def test_gateway_service_client_from_service_account_info(client_class):
122122
assert client.transport._host == "connectgateway.googleapis.com:443"
123123

124124

125-
@pytest.mark.parametrize(
126-
"client_class", [GatewayServiceClient, GatewayServiceAsyncClient,]
127-
)
128-
def test_gateway_service_client_service_account_always_use_jwt(client_class):
129-
with mock.patch.object(
130-
service_account.Credentials, "with_always_use_jwt_access", create=True
131-
) as use_jwt:
132-
creds = service_account.Credentials(None, None, None)
133-
client = client_class(credentials=creds)
134-
use_jwt.assert_not_called()
135-
136-
137125
@pytest.mark.parametrize(
138126
"transport_class,transport_name",
139127
[
140128
(transports.GatewayServiceGrpcTransport, "grpc"),
141129
(transports.GatewayServiceGrpcAsyncIOTransport, "grpc_asyncio"),
142130
],
143131
)
144-
def test_gateway_service_client_service_account_always_use_jwt_true(
132+
def test_gateway_service_client_service_account_always_use_jwt(
145133
transport_class, transport_name
146134
):
147135
with mock.patch.object(
@@ -151,6 +139,13 @@ def test_gateway_service_client_service_account_always_use_jwt_true(
151139
transport = transport_class(credentials=creds, always_use_jwt_access=True)
152140
use_jwt.assert_called_once_with(True)
153141

142+
with mock.patch.object(
143+
service_account.Credentials, "with_always_use_jwt_access", create=True
144+
) as use_jwt:
145+
creds = service_account.Credentials(None, None, None)
146+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
147+
use_jwt.assert_not_called()
148+
154149

155150
@pytest.mark.parametrize(
156151
"client_class", [GatewayServiceClient, GatewayServiceAsyncClient,]
@@ -231,6 +226,7 @@ def test_gateway_service_client_client_options(
231226
client_cert_source_for_mtls=None,
232227
quota_project_id=None,
233228
client_info=transports.base.DEFAULT_CLIENT_INFO,
229+
always_use_jwt_access=True,
234230
)
235231

236232
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -247,6 +243,7 @@ def test_gateway_service_client_client_options(
247243
client_cert_source_for_mtls=None,
248244
quota_project_id=None,
249245
client_info=transports.base.DEFAULT_CLIENT_INFO,
246+
always_use_jwt_access=True,
250247
)
251248

252249
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -263,6 +260,7 @@ def test_gateway_service_client_client_options(
263260
client_cert_source_for_mtls=None,
264261
quota_project_id=None,
265262
client_info=transports.base.DEFAULT_CLIENT_INFO,
263+
always_use_jwt_access=True,
266264
)
267265

268266
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -291,6 +289,7 @@ def test_gateway_service_client_client_options(
291289
client_cert_source_for_mtls=None,
292290
quota_project_id="octopus",
293291
client_info=transports.base.DEFAULT_CLIENT_INFO,
292+
always_use_jwt_access=True,
294293
)
295294

296295

@@ -357,6 +356,7 @@ def test_gateway_service_client_mtls_env_auto(
357356
client_cert_source_for_mtls=expected_client_cert_source,
358357
quota_project_id=None,
359358
client_info=transports.base.DEFAULT_CLIENT_INFO,
359+
always_use_jwt_access=True,
360360
)
361361

362362
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -390,6 +390,7 @@ def test_gateway_service_client_mtls_env_auto(
390390
client_cert_source_for_mtls=expected_client_cert_source,
391391
quota_project_id=None,
392392
client_info=transports.base.DEFAULT_CLIENT_INFO,
393+
always_use_jwt_access=True,
393394
)
394395

395396
# Check the case client_cert_source and ADC client cert are not provided.
@@ -411,6 +412,7 @@ def test_gateway_service_client_mtls_env_auto(
411412
client_cert_source_for_mtls=None,
412413
quota_project_id=None,
413414
client_info=transports.base.DEFAULT_CLIENT_INFO,
415+
always_use_jwt_access=True,
414416
)
415417

416418

@@ -441,6 +443,7 @@ def test_gateway_service_client_client_options_scopes(
441443
client_cert_source_for_mtls=None,
442444
quota_project_id=None,
443445
client_info=transports.base.DEFAULT_CLIENT_INFO,
446+
always_use_jwt_access=True,
444447
)
445448

446449

@@ -471,6 +474,7 @@ def test_gateway_service_client_client_options_credentials_file(
471474
client_cert_source_for_mtls=None,
472475
quota_project_id=None,
473476
client_info=transports.base.DEFAULT_CLIENT_INFO,
477+
always_use_jwt_access=True,
474478
)
475479

476480

@@ -490,6 +494,7 @@ def test_gateway_service_client_client_options_from_dict():
490494
client_cert_source_for_mtls=None,
491495
quota_project_id=None,
492496
client_info=transports.base.DEFAULT_CLIENT_INFO,
497+
always_use_jwt_access=True,
493498
)
494499

495500

0 commit comments

Comments
 (0)