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

Commit d40d70e

Browse files
1 parent de8e547 commit d40d70e

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/iam_credentials_v1/services/iam_credentials/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ def __init__(
355355
client_cert_source_for_mtls=client_cert_source_func,
356356
quota_project_id=client_options.quota_project_id,
357357
client_info=client_info,
358+
always_use_jwt_access=(
359+
Transport == type(self).get_transport_class("grpc")
360+
or Transport == type(self).get_transport_class("grpc_asyncio")
361+
),
358362
)
359363

360364
def generate_access_token(

tests/unit/gapic/credentials_v1/test_iam_credentials.py

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

125125

126-
@pytest.mark.parametrize(
127-
"client_class", [IAMCredentialsClient, IAMCredentialsAsyncClient,]
128-
)
129-
def test_iam_credentials_client_service_account_always_use_jwt(client_class):
130-
with mock.patch.object(
131-
service_account.Credentials, "with_always_use_jwt_access", create=True
132-
) as use_jwt:
133-
creds = service_account.Credentials(None, None, None)
134-
client = client_class(credentials=creds)
135-
use_jwt.assert_not_called()
136-
137-
138126
@pytest.mark.parametrize(
139127
"transport_class,transport_name",
140128
[
141129
(transports.IAMCredentialsGrpcTransport, "grpc"),
142130
(transports.IAMCredentialsGrpcAsyncIOTransport, "grpc_asyncio"),
143131
],
144132
)
145-
def test_iam_credentials_client_service_account_always_use_jwt_true(
133+
def test_iam_credentials_client_service_account_always_use_jwt(
146134
transport_class, transport_name
147135
):
148136
with mock.patch.object(
@@ -152,6 +140,13 @@ def test_iam_credentials_client_service_account_always_use_jwt_true(
152140
transport = transport_class(credentials=creds, always_use_jwt_access=True)
153141
use_jwt.assert_called_once_with(True)
154142

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

156151
@pytest.mark.parametrize(
157152
"client_class", [IAMCredentialsClient, IAMCredentialsAsyncClient,]
@@ -232,6 +227,7 @@ def test_iam_credentials_client_client_options(
232227
client_cert_source_for_mtls=None,
233228
quota_project_id=None,
234229
client_info=transports.base.DEFAULT_CLIENT_INFO,
230+
always_use_jwt_access=True,
235231
)
236232

237233
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -248,6 +244,7 @@ def test_iam_credentials_client_client_options(
248244
client_cert_source_for_mtls=None,
249245
quota_project_id=None,
250246
client_info=transports.base.DEFAULT_CLIENT_INFO,
247+
always_use_jwt_access=True,
251248
)
252249

253250
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -264,6 +261,7 @@ def test_iam_credentials_client_client_options(
264261
client_cert_source_for_mtls=None,
265262
quota_project_id=None,
266263
client_info=transports.base.DEFAULT_CLIENT_INFO,
264+
always_use_jwt_access=True,
267265
)
268266

269267
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -292,6 +290,7 @@ def test_iam_credentials_client_client_options(
292290
client_cert_source_for_mtls=None,
293291
quota_project_id="octopus",
294292
client_info=transports.base.DEFAULT_CLIENT_INFO,
293+
always_use_jwt_access=True,
295294
)
296295

297296

@@ -358,6 +357,7 @@ def test_iam_credentials_client_mtls_env_auto(
358357
client_cert_source_for_mtls=expected_client_cert_source,
359358
quota_project_id=None,
360359
client_info=transports.base.DEFAULT_CLIENT_INFO,
360+
always_use_jwt_access=True,
361361
)
362362

363363
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -391,6 +391,7 @@ def test_iam_credentials_client_mtls_env_auto(
391391
client_cert_source_for_mtls=expected_client_cert_source,
392392
quota_project_id=None,
393393
client_info=transports.base.DEFAULT_CLIENT_INFO,
394+
always_use_jwt_access=True,
394395
)
395396

396397
# Check the case client_cert_source and ADC client cert are not provided.
@@ -412,6 +413,7 @@ def test_iam_credentials_client_mtls_env_auto(
412413
client_cert_source_for_mtls=None,
413414
quota_project_id=None,
414415
client_info=transports.base.DEFAULT_CLIENT_INFO,
416+
always_use_jwt_access=True,
415417
)
416418

417419

@@ -442,6 +444,7 @@ def test_iam_credentials_client_client_options_scopes(
442444
client_cert_source_for_mtls=None,
443445
quota_project_id=None,
444446
client_info=transports.base.DEFAULT_CLIENT_INFO,
447+
always_use_jwt_access=True,
445448
)
446449

447450

@@ -472,6 +475,7 @@ def test_iam_credentials_client_client_options_credentials_file(
472475
client_cert_source_for_mtls=None,
473476
quota_project_id=None,
474477
client_info=transports.base.DEFAULT_CLIENT_INFO,
478+
always_use_jwt_access=True,
475479
)
476480

477481

@@ -491,6 +495,7 @@ def test_iam_credentials_client_client_options_from_dict():
491495
client_cert_source_for_mtls=None,
492496
quota_project_id=None,
493497
client_info=transports.base.DEFAULT_CLIENT_INFO,
498+
always_use_jwt_access=True,
494499
)
495500

496501

0 commit comments

Comments
 (0)