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

Commit dd8b006

Browse files
1 parent a813d93 commit dd8b006

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

google/cloud/redis_v1/services/cloud_redis/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ def __init__(
368368
client_cert_source_for_mtls=client_cert_source_func,
369369
quota_project_id=client_options.quota_project_id,
370370
client_info=client_info,
371+
always_use_jwt_access=(
372+
Transport == type(self).get_transport_class("grpc")
373+
or Transport == type(self).get_transport_class("grpc_asyncio")
374+
),
371375
)
372376

373377
def list_instances(

google/cloud/redis_v1beta1/services/cloud_redis/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ def __init__(
369369
client_cert_source_for_mtls=client_cert_source_func,
370370
quota_project_id=client_options.quota_project_id,
371371
client_info=client_info,
372+
always_use_jwt_access=(
373+
Transport == type(self).get_transport_class("grpc")
374+
or Transport == type(self).get_transport_class("grpc_asyncio")
375+
),
372376
)
373377

374378
def list_instances(

tests/unit/gapic/redis_v1/test_cloud_redis.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,14 @@ def test_cloud_redis_client_from_service_account_info(client_class):
119119
assert client.transport._host == "redis.googleapis.com:443"
120120

121121

122-
@pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,])
123-
def test_cloud_redis_client_service_account_always_use_jwt(client_class):
124-
with mock.patch.object(
125-
service_account.Credentials, "with_always_use_jwt_access", create=True
126-
) as use_jwt:
127-
creds = service_account.Credentials(None, None, None)
128-
client = client_class(credentials=creds)
129-
use_jwt.assert_not_called()
130-
131-
132122
@pytest.mark.parametrize(
133123
"transport_class,transport_name",
134124
[
135125
(transports.CloudRedisGrpcTransport, "grpc"),
136126
(transports.CloudRedisGrpcAsyncIOTransport, "grpc_asyncio"),
137127
],
138128
)
139-
def test_cloud_redis_client_service_account_always_use_jwt_true(
129+
def test_cloud_redis_client_service_account_always_use_jwt(
140130
transport_class, transport_name
141131
):
142132
with mock.patch.object(
@@ -146,6 +136,13 @@ def test_cloud_redis_client_service_account_always_use_jwt_true(
146136
transport = transport_class(credentials=creds, always_use_jwt_access=True)
147137
use_jwt.assert_called_once_with(True)
148138

139+
with mock.patch.object(
140+
service_account.Credentials, "with_always_use_jwt_access", create=True
141+
) as use_jwt:
142+
creds = service_account.Credentials(None, None, None)
143+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
144+
use_jwt.assert_not_called()
145+
149146

150147
@pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,])
151148
def test_cloud_redis_client_from_service_account_file(client_class):
@@ -222,6 +219,7 @@ def test_cloud_redis_client_client_options(
222219
client_cert_source_for_mtls=None,
223220
quota_project_id=None,
224221
client_info=transports.base.DEFAULT_CLIENT_INFO,
222+
always_use_jwt_access=True,
225223
)
226224

227225
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -238,6 +236,7 @@ def test_cloud_redis_client_client_options(
238236
client_cert_source_for_mtls=None,
239237
quota_project_id=None,
240238
client_info=transports.base.DEFAULT_CLIENT_INFO,
239+
always_use_jwt_access=True,
241240
)
242241

243242
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -254,6 +253,7 @@ def test_cloud_redis_client_client_options(
254253
client_cert_source_for_mtls=None,
255254
quota_project_id=None,
256255
client_info=transports.base.DEFAULT_CLIENT_INFO,
256+
always_use_jwt_access=True,
257257
)
258258

259259
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -282,6 +282,7 @@ def test_cloud_redis_client_client_options(
282282
client_cert_source_for_mtls=None,
283283
quota_project_id="octopus",
284284
client_info=transports.base.DEFAULT_CLIENT_INFO,
285+
always_use_jwt_access=True,
285286
)
286287

287288

@@ -346,6 +347,7 @@ def test_cloud_redis_client_mtls_env_auto(
346347
client_cert_source_for_mtls=expected_client_cert_source,
347348
quota_project_id=None,
348349
client_info=transports.base.DEFAULT_CLIENT_INFO,
350+
always_use_jwt_access=True,
349351
)
350352

351353
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -379,6 +381,7 @@ def test_cloud_redis_client_mtls_env_auto(
379381
client_cert_source_for_mtls=expected_client_cert_source,
380382
quota_project_id=None,
381383
client_info=transports.base.DEFAULT_CLIENT_INFO,
384+
always_use_jwt_access=True,
382385
)
383386

384387
# Check the case client_cert_source and ADC client cert are not provided.
@@ -400,6 +403,7 @@ def test_cloud_redis_client_mtls_env_auto(
400403
client_cert_source_for_mtls=None,
401404
quota_project_id=None,
402405
client_info=transports.base.DEFAULT_CLIENT_INFO,
406+
always_use_jwt_access=True,
403407
)
404408

405409

@@ -430,6 +434,7 @@ def test_cloud_redis_client_client_options_scopes(
430434
client_cert_source_for_mtls=None,
431435
quota_project_id=None,
432436
client_info=transports.base.DEFAULT_CLIENT_INFO,
437+
always_use_jwt_access=True,
433438
)
434439

435440

@@ -460,6 +465,7 @@ def test_cloud_redis_client_client_options_credentials_file(
460465
client_cert_source_for_mtls=None,
461466
quota_project_id=None,
462467
client_info=transports.base.DEFAULT_CLIENT_INFO,
468+
always_use_jwt_access=True,
463469
)
464470

465471

@@ -477,6 +483,7 @@ def test_cloud_redis_client_client_options_from_dict():
477483
client_cert_source_for_mtls=None,
478484
quota_project_id=None,
479485
client_info=transports.base.DEFAULT_CLIENT_INFO,
486+
always_use_jwt_access=True,
480487
)
481488

482489

tests/unit/gapic/redis_v1beta1/test_cloud_redis.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,14 @@ def test_cloud_redis_client_from_service_account_info(client_class):
120120
assert client.transport._host == "redis.googleapis.com:443"
121121

122122

123-
@pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,])
124-
def test_cloud_redis_client_service_account_always_use_jwt(client_class):
125-
with mock.patch.object(
126-
service_account.Credentials, "with_always_use_jwt_access", create=True
127-
) as use_jwt:
128-
creds = service_account.Credentials(None, None, None)
129-
client = client_class(credentials=creds)
130-
use_jwt.assert_not_called()
131-
132-
133123
@pytest.mark.parametrize(
134124
"transport_class,transport_name",
135125
[
136126
(transports.CloudRedisGrpcTransport, "grpc"),
137127
(transports.CloudRedisGrpcAsyncIOTransport, "grpc_asyncio"),
138128
],
139129
)
140-
def test_cloud_redis_client_service_account_always_use_jwt_true(
130+
def test_cloud_redis_client_service_account_always_use_jwt(
141131
transport_class, transport_name
142132
):
143133
with mock.patch.object(
@@ -147,6 +137,13 @@ def test_cloud_redis_client_service_account_always_use_jwt_true(
147137
transport = transport_class(credentials=creds, always_use_jwt_access=True)
148138
use_jwt.assert_called_once_with(True)
149139

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

151148
@pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,])
152149
def test_cloud_redis_client_from_service_account_file(client_class):
@@ -223,6 +220,7 @@ def test_cloud_redis_client_client_options(
223220
client_cert_source_for_mtls=None,
224221
quota_project_id=None,
225222
client_info=transports.base.DEFAULT_CLIENT_INFO,
223+
always_use_jwt_access=True,
226224
)
227225

228226
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -239,6 +237,7 @@ def test_cloud_redis_client_client_options(
239237
client_cert_source_for_mtls=None,
240238
quota_project_id=None,
241239
client_info=transports.base.DEFAULT_CLIENT_INFO,
240+
always_use_jwt_access=True,
242241
)
243242

244243
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -255,6 +254,7 @@ def test_cloud_redis_client_client_options(
255254
client_cert_source_for_mtls=None,
256255
quota_project_id=None,
257256
client_info=transports.base.DEFAULT_CLIENT_INFO,
257+
always_use_jwt_access=True,
258258
)
259259

260260
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -283,6 +283,7 @@ def test_cloud_redis_client_client_options(
283283
client_cert_source_for_mtls=None,
284284
quota_project_id="octopus",
285285
client_info=transports.base.DEFAULT_CLIENT_INFO,
286+
always_use_jwt_access=True,
286287
)
287288

288289

@@ -347,6 +348,7 @@ def test_cloud_redis_client_mtls_env_auto(
347348
client_cert_source_for_mtls=expected_client_cert_source,
348349
quota_project_id=None,
349350
client_info=transports.base.DEFAULT_CLIENT_INFO,
351+
always_use_jwt_access=True,
350352
)
351353

352354
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -380,6 +382,7 @@ def test_cloud_redis_client_mtls_env_auto(
380382
client_cert_source_for_mtls=expected_client_cert_source,
381383
quota_project_id=None,
382384
client_info=transports.base.DEFAULT_CLIENT_INFO,
385+
always_use_jwt_access=True,
383386
)
384387

385388
# Check the case client_cert_source and ADC client cert are not provided.
@@ -401,6 +404,7 @@ def test_cloud_redis_client_mtls_env_auto(
401404
client_cert_source_for_mtls=None,
402405
quota_project_id=None,
403406
client_info=transports.base.DEFAULT_CLIENT_INFO,
407+
always_use_jwt_access=True,
404408
)
405409

406410

@@ -431,6 +435,7 @@ def test_cloud_redis_client_client_options_scopes(
431435
client_cert_source_for_mtls=None,
432436
quota_project_id=None,
433437
client_info=transports.base.DEFAULT_CLIENT_INFO,
438+
always_use_jwt_access=True,
434439
)
435440

436441

@@ -461,6 +466,7 @@ def test_cloud_redis_client_client_options_credentials_file(
461466
client_cert_source_for_mtls=None,
462467
quota_project_id=None,
463468
client_info=transports.base.DEFAULT_CLIENT_INFO,
469+
always_use_jwt_access=True,
464470
)
465471

466472

@@ -478,6 +484,7 @@ def test_cloud_redis_client_client_options_from_dict():
478484
client_cert_source_for_mtls=None,
479485
quota_project_id=None,
480486
client_info=transports.base.DEFAULT_CLIENT_INFO,
487+
always_use_jwt_access=True,
481488
)
482489

483490

0 commit comments

Comments
 (0)