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

Commit 03bd652

Browse files
1 parent 69ef051 commit 03bd652

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/functions_v1/services/cloud_functions_service/client.py

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

361365
def list_functions(

tests/unit/gapic/functions_v1/test_cloud_functions_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,14 @@ def test_cloud_functions_service_client_from_service_account_info(client_class):
135135
assert client.transport._host == "cloudfunctions.googleapis.com:443"
136136

137137

138-
@pytest.mark.parametrize(
139-
"client_class", [CloudFunctionsServiceClient, CloudFunctionsServiceAsyncClient,]
140-
)
141-
def test_cloud_functions_service_client_service_account_always_use_jwt(client_class):
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-
client = client_class(credentials=creds)
147-
use_jwt.assert_not_called()
148-
149-
150138
@pytest.mark.parametrize(
151139
"transport_class,transport_name",
152140
[
153141
(transports.CloudFunctionsServiceGrpcTransport, "grpc"),
154142
(transports.CloudFunctionsServiceGrpcAsyncIOTransport, "grpc_asyncio"),
155143
],
156144
)
157-
def test_cloud_functions_service_client_service_account_always_use_jwt_true(
145+
def test_cloud_functions_service_client_service_account_always_use_jwt(
158146
transport_class, transport_name
159147
):
160148
with mock.patch.object(
@@ -164,6 +152,13 @@ def test_cloud_functions_service_client_service_account_always_use_jwt_true(
164152
transport = transport_class(credentials=creds, always_use_jwt_access=True)
165153
use_jwt.assert_called_once_with(True)
166154

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

168163
@pytest.mark.parametrize(
169164
"client_class", [CloudFunctionsServiceClient, CloudFunctionsServiceAsyncClient,]
@@ -248,6 +243,7 @@ def test_cloud_functions_service_client_client_options(
248243
client_cert_source_for_mtls=None,
249244
quota_project_id=None,
250245
client_info=transports.base.DEFAULT_CLIENT_INFO,
246+
always_use_jwt_access=True,
251247
)
252248

253249
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -264,6 +260,7 @@ def test_cloud_functions_service_client_client_options(
264260
client_cert_source_for_mtls=None,
265261
quota_project_id=None,
266262
client_info=transports.base.DEFAULT_CLIENT_INFO,
263+
always_use_jwt_access=True,
267264
)
268265

269266
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -280,6 +277,7 @@ def test_cloud_functions_service_client_client_options(
280277
client_cert_source_for_mtls=None,
281278
quota_project_id=None,
282279
client_info=transports.base.DEFAULT_CLIENT_INFO,
280+
always_use_jwt_access=True,
283281
)
284282

285283
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -308,6 +306,7 @@ def test_cloud_functions_service_client_client_options(
308306
client_cert_source_for_mtls=None,
309307
quota_project_id="octopus",
310308
client_info=transports.base.DEFAULT_CLIENT_INFO,
309+
always_use_jwt_access=True,
311310
)
312311

313312

@@ -384,6 +383,7 @@ def test_cloud_functions_service_client_mtls_env_auto(
384383
client_cert_source_for_mtls=expected_client_cert_source,
385384
quota_project_id=None,
386385
client_info=transports.base.DEFAULT_CLIENT_INFO,
386+
always_use_jwt_access=True,
387387
)
388388

389389
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -417,6 +417,7 @@ def test_cloud_functions_service_client_mtls_env_auto(
417417
client_cert_source_for_mtls=expected_client_cert_source,
418418
quota_project_id=None,
419419
client_info=transports.base.DEFAULT_CLIENT_INFO,
420+
always_use_jwt_access=True,
420421
)
421422

422423
# Check the case client_cert_source and ADC client cert are not provided.
@@ -438,6 +439,7 @@ def test_cloud_functions_service_client_mtls_env_auto(
438439
client_cert_source_for_mtls=None,
439440
quota_project_id=None,
440441
client_info=transports.base.DEFAULT_CLIENT_INFO,
442+
always_use_jwt_access=True,
441443
)
442444

443445

@@ -472,6 +474,7 @@ def test_cloud_functions_service_client_client_options_scopes(
472474
client_cert_source_for_mtls=None,
473475
quota_project_id=None,
474476
client_info=transports.base.DEFAULT_CLIENT_INFO,
477+
always_use_jwt_access=True,
475478
)
476479

477480

@@ -506,6 +509,7 @@ def test_cloud_functions_service_client_client_options_credentials_file(
506509
client_cert_source_for_mtls=None,
507510
quota_project_id=None,
508511
client_info=transports.base.DEFAULT_CLIENT_INFO,
512+
always_use_jwt_access=True,
509513
)
510514

511515

@@ -525,6 +529,7 @@ def test_cloud_functions_service_client_client_options_from_dict():
525529
client_cert_source_for_mtls=None,
526530
quota_project_id=None,
527531
client_info=transports.base.DEFAULT_CLIENT_INFO,
532+
always_use_jwt_access=True,
528533
)
529534

530535

0 commit comments

Comments
 (0)