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

Commit d79eaa7

Browse files
1 parent 082622c commit d79eaa7

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

google/cloud/managedidentities_v1/services/managed_identities_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ def __init__(
387387
client_cert_source_for_mtls=client_cert_source_func,
388388
quota_project_id=client_options.quota_project_id,
389389
client_info=client_info,
390+
always_use_jwt_access=(
391+
Transport == type(self).get_transport_class("grpc")
392+
or Transport == type(self).get_transport_class("grpc_asyncio")
393+
),
390394
)
391395

392396
def create_microsoft_ad_domain(

tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,14 @@ def test_managed_identities_service_client_from_service_account_info(client_clas
133133
assert client.transport._host == "managedidentities.googleapis.com:443"
134134

135135

136-
@pytest.mark.parametrize(
137-
"client_class",
138-
[ManagedIdentitiesServiceClient, ManagedIdentitiesServiceAsyncClient,],
139-
)
140-
def test_managed_identities_service_client_service_account_always_use_jwt(client_class):
141-
with mock.patch.object(
142-
service_account.Credentials, "with_always_use_jwt_access", create=True
143-
) as use_jwt:
144-
creds = service_account.Credentials(None, None, None)
145-
client = client_class(credentials=creds)
146-
use_jwt.assert_not_called()
147-
148-
149136
@pytest.mark.parametrize(
150137
"transport_class,transport_name",
151138
[
152139
(transports.ManagedIdentitiesServiceGrpcTransport, "grpc"),
153140
(transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, "grpc_asyncio"),
154141
],
155142
)
156-
def test_managed_identities_service_client_service_account_always_use_jwt_true(
143+
def test_managed_identities_service_client_service_account_always_use_jwt(
157144
transport_class, transport_name
158145
):
159146
with mock.patch.object(
@@ -163,6 +150,13 @@ def test_managed_identities_service_client_service_account_always_use_jwt_true(
163150
transport = transport_class(credentials=creds, always_use_jwt_access=True)
164151
use_jwt.assert_called_once_with(True)
165152

153+
with mock.patch.object(
154+
service_account.Credentials, "with_always_use_jwt_access", create=True
155+
) as use_jwt:
156+
creds = service_account.Credentials(None, None, None)
157+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
158+
use_jwt.assert_not_called()
159+
166160

167161
@pytest.mark.parametrize(
168162
"client_class",
@@ -252,6 +246,7 @@ def test_managed_identities_service_client_client_options(
252246
client_cert_source_for_mtls=None,
253247
quota_project_id=None,
254248
client_info=transports.base.DEFAULT_CLIENT_INFO,
249+
always_use_jwt_access=True,
255250
)
256251

257252
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -268,6 +263,7 @@ def test_managed_identities_service_client_client_options(
268263
client_cert_source_for_mtls=None,
269264
quota_project_id=None,
270265
client_info=transports.base.DEFAULT_CLIENT_INFO,
266+
always_use_jwt_access=True,
271267
)
272268

273269
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -284,6 +280,7 @@ def test_managed_identities_service_client_client_options(
284280
client_cert_source_for_mtls=None,
285281
quota_project_id=None,
286282
client_info=transports.base.DEFAULT_CLIENT_INFO,
283+
always_use_jwt_access=True,
287284
)
288285

289286
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -312,6 +309,7 @@ def test_managed_identities_service_client_client_options(
312309
client_cert_source_for_mtls=None,
313310
quota_project_id="octopus",
314311
client_info=transports.base.DEFAULT_CLIENT_INFO,
312+
always_use_jwt_access=True,
315313
)
316314

317315

@@ -388,6 +386,7 @@ def test_managed_identities_service_client_mtls_env_auto(
388386
client_cert_source_for_mtls=expected_client_cert_source,
389387
quota_project_id=None,
390388
client_info=transports.base.DEFAULT_CLIENT_INFO,
389+
always_use_jwt_access=True,
391390
)
392391

393392
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -421,6 +420,7 @@ def test_managed_identities_service_client_mtls_env_auto(
421420
client_cert_source_for_mtls=expected_client_cert_source,
422421
quota_project_id=None,
423422
client_info=transports.base.DEFAULT_CLIENT_INFO,
423+
always_use_jwt_access=True,
424424
)
425425

426426
# Check the case client_cert_source and ADC client cert are not provided.
@@ -442,6 +442,7 @@ def test_managed_identities_service_client_mtls_env_auto(
442442
client_cert_source_for_mtls=None,
443443
quota_project_id=None,
444444
client_info=transports.base.DEFAULT_CLIENT_INFO,
445+
always_use_jwt_access=True,
445446
)
446447

447448

@@ -476,6 +477,7 @@ def test_managed_identities_service_client_client_options_scopes(
476477
client_cert_source_for_mtls=None,
477478
quota_project_id=None,
478479
client_info=transports.base.DEFAULT_CLIENT_INFO,
480+
always_use_jwt_access=True,
479481
)
480482

481483

@@ -510,6 +512,7 @@ def test_managed_identities_service_client_client_options_credentials_file(
510512
client_cert_source_for_mtls=None,
511513
quota_project_id=None,
512514
client_info=transports.base.DEFAULT_CLIENT_INFO,
515+
always_use_jwt_access=True,
513516
)
514517

515518

@@ -529,6 +532,7 @@ def test_managed_identities_service_client_client_options_from_dict():
529532
client_cert_source_for_mtls=None,
530533
quota_project_id=None,
531534
client_info=transports.base.DEFAULT_CLIENT_INFO,
535+
always_use_jwt_access=True,
532536
)
533537

534538

0 commit comments

Comments
 (0)