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

Commit 016111e

Browse files
fix: enable self signed jwt for grpc (#76)
PiperOrigin-RevId: 386504689 Source-Link: googleapis/googleapis@762094a Source-Link: https://github.com/googleapis/googleapis-gen/commit/6bfc480e1a161d5de121c2bcc3745885d33b265a
1 parent 9365f86 commit 016111e

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

google/cloud/channel_v1/services/cloud_channel_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ def __init__(
427427
client_cert_source_for_mtls=client_cert_source_func,
428428
quota_project_id=client_options.quota_project_id,
429429
client_info=client_info,
430+
always_use_jwt_access=(
431+
Transport == type(self).get_transport_class("grpc")
432+
or Transport == type(self).get_transport_class("grpc_asyncio")
433+
),
430434
)
431435

432436
def list_customers(

tests/unit/gapic/channel_v1/test_cloud_channel_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,14 @@ def test_cloud_channel_service_client_from_service_account_info(client_class):
138138
assert client.transport._host == "cloudchannel.googleapis.com:443"
139139

140140

141-
@pytest.mark.parametrize(
142-
"client_class", [CloudChannelServiceClient, CloudChannelServiceAsyncClient,]
143-
)
144-
def test_cloud_channel_service_client_service_account_always_use_jwt(client_class):
145-
with mock.patch.object(
146-
service_account.Credentials, "with_always_use_jwt_access", create=True
147-
) as use_jwt:
148-
creds = service_account.Credentials(None, None, None)
149-
client = client_class(credentials=creds)
150-
use_jwt.assert_not_called()
151-
152-
153141
@pytest.mark.parametrize(
154142
"transport_class,transport_name",
155143
[
156144
(transports.CloudChannelServiceGrpcTransport, "grpc"),
157145
(transports.CloudChannelServiceGrpcAsyncIOTransport, "grpc_asyncio"),
158146
],
159147
)
160-
def test_cloud_channel_service_client_service_account_always_use_jwt_true(
148+
def test_cloud_channel_service_client_service_account_always_use_jwt(
161149
transport_class, transport_name
162150
):
163151
with mock.patch.object(
@@ -167,6 +155,13 @@ def test_cloud_channel_service_client_service_account_always_use_jwt_true(
167155
transport = transport_class(credentials=creds, always_use_jwt_access=True)
168156
use_jwt.assert_called_once_with(True)
169157

158+
with mock.patch.object(
159+
service_account.Credentials, "with_always_use_jwt_access", create=True
160+
) as use_jwt:
161+
creds = service_account.Credentials(None, None, None)
162+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
163+
use_jwt.assert_not_called()
164+
170165

171166
@pytest.mark.parametrize(
172167
"client_class", [CloudChannelServiceClient, CloudChannelServiceAsyncClient,]
@@ -251,6 +246,7 @@ def test_cloud_channel_service_client_client_options(
251246
client_cert_source_for_mtls=None,
252247
quota_project_id=None,
253248
client_info=transports.base.DEFAULT_CLIENT_INFO,
249+
always_use_jwt_access=True,
254250
)
255251

256252
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -267,6 +263,7 @@ def test_cloud_channel_service_client_client_options(
267263
client_cert_source_for_mtls=None,
268264
quota_project_id=None,
269265
client_info=transports.base.DEFAULT_CLIENT_INFO,
266+
always_use_jwt_access=True,
270267
)
271268

272269
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -283,6 +280,7 @@ def test_cloud_channel_service_client_client_options(
283280
client_cert_source_for_mtls=None,
284281
quota_project_id=None,
285282
client_info=transports.base.DEFAULT_CLIENT_INFO,
283+
always_use_jwt_access=True,
286284
)
287285

288286
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -311,6 +309,7 @@ def test_cloud_channel_service_client_client_options(
311309
client_cert_source_for_mtls=None,
312310
quota_project_id="octopus",
313311
client_info=transports.base.DEFAULT_CLIENT_INFO,
312+
always_use_jwt_access=True,
314313
)
315314

316315

@@ -387,6 +386,7 @@ def test_cloud_channel_service_client_mtls_env_auto(
387386
client_cert_source_for_mtls=expected_client_cert_source,
388387
quota_project_id=None,
389388
client_info=transports.base.DEFAULT_CLIENT_INFO,
389+
always_use_jwt_access=True,
390390
)
391391

392392
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -420,6 +420,7 @@ def test_cloud_channel_service_client_mtls_env_auto(
420420
client_cert_source_for_mtls=expected_client_cert_source,
421421
quota_project_id=None,
422422
client_info=transports.base.DEFAULT_CLIENT_INFO,
423+
always_use_jwt_access=True,
423424
)
424425

425426
# Check the case client_cert_source and ADC client cert are not provided.
@@ -441,6 +442,7 @@ def test_cloud_channel_service_client_mtls_env_auto(
441442
client_cert_source_for_mtls=None,
442443
quota_project_id=None,
443444
client_info=transports.base.DEFAULT_CLIENT_INFO,
445+
always_use_jwt_access=True,
444446
)
445447

446448

@@ -475,6 +477,7 @@ def test_cloud_channel_service_client_client_options_scopes(
475477
client_cert_source_for_mtls=None,
476478
quota_project_id=None,
477479
client_info=transports.base.DEFAULT_CLIENT_INFO,
480+
always_use_jwt_access=True,
478481
)
479482

480483

@@ -509,6 +512,7 @@ def test_cloud_channel_service_client_client_options_credentials_file(
509512
client_cert_source_for_mtls=None,
510513
quota_project_id=None,
511514
client_info=transports.base.DEFAULT_CLIENT_INFO,
515+
always_use_jwt_access=True,
512516
)
513517

514518

@@ -528,6 +532,7 @@ def test_cloud_channel_service_client_client_options_from_dict():
528532
client_cert_source_for_mtls=None,
529533
quota_project_id=None,
530534
client_info=transports.base.DEFAULT_CLIENT_INFO,
535+
always_use_jwt_access=True,
531536
)
532537

533538

0 commit comments

Comments
 (0)