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

Commit aca8358

Browse files
fix: enable self signed jwt for grpc (#26)
PiperOrigin-RevId: 386504689 Source-Link: googleapis/googleapis@762094a Source-Link: https://github.com/googleapis/googleapis-gen/commit/6bfc480e1a161d5de121c2bcc3745885d33b265a
1 parent 4c7a5c4 commit aca8358

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/vpcaccess_v1/services/vpc_access_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ def __init__(
350350
client_cert_source_for_mtls=client_cert_source_func,
351351
quota_project_id=client_options.quota_project_id,
352352
client_info=client_info,
353+
always_use_jwt_access=(
354+
Transport == type(self).get_transport_class("grpc")
355+
or Transport == type(self).get_transport_class("grpc_asyncio")
356+
),
353357
)
354358

355359
def create_connector(

tests/unit/gapic/vpcaccess_v1/test_vpc_access_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,14 @@ def test_vpc_access_service_client_from_service_account_info(client_class):
125125
assert client.transport._host == "vpcaccess.googleapis.com:443"
126126

127127

128-
@pytest.mark.parametrize(
129-
"client_class", [VpcAccessServiceClient, VpcAccessServiceAsyncClient,]
130-
)
131-
def test_vpc_access_service_client_service_account_always_use_jwt(client_class):
132-
with mock.patch.object(
133-
service_account.Credentials, "with_always_use_jwt_access", create=True
134-
) as use_jwt:
135-
creds = service_account.Credentials(None, None, None)
136-
client = client_class(credentials=creds)
137-
use_jwt.assert_not_called()
138-
139-
140128
@pytest.mark.parametrize(
141129
"transport_class,transport_name",
142130
[
143131
(transports.VpcAccessServiceGrpcTransport, "grpc"),
144132
(transports.VpcAccessServiceGrpcAsyncIOTransport, "grpc_asyncio"),
145133
],
146134
)
147-
def test_vpc_access_service_client_service_account_always_use_jwt_true(
135+
def test_vpc_access_service_client_service_account_always_use_jwt(
148136
transport_class, transport_name
149137
):
150138
with mock.patch.object(
@@ -154,6 +142,13 @@ def test_vpc_access_service_client_service_account_always_use_jwt_true(
154142
transport = transport_class(credentials=creds, always_use_jwt_access=True)
155143
use_jwt.assert_called_once_with(True)
156144

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+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
150+
use_jwt.assert_not_called()
151+
157152

158153
@pytest.mark.parametrize(
159154
"client_class", [VpcAccessServiceClient, VpcAccessServiceAsyncClient,]
@@ -234,6 +229,7 @@ def test_vpc_access_service_client_client_options(
234229
client_cert_source_for_mtls=None,
235230
quota_project_id=None,
236231
client_info=transports.base.DEFAULT_CLIENT_INFO,
232+
always_use_jwt_access=True,
237233
)
238234

239235
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -250,6 +246,7 @@ def test_vpc_access_service_client_client_options(
250246
client_cert_source_for_mtls=None,
251247
quota_project_id=None,
252248
client_info=transports.base.DEFAULT_CLIENT_INFO,
249+
always_use_jwt_access=True,
253250
)
254251

255252
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -266,6 +263,7 @@ def test_vpc_access_service_client_client_options(
266263
client_cert_source_for_mtls=None,
267264
quota_project_id=None,
268265
client_info=transports.base.DEFAULT_CLIENT_INFO,
266+
always_use_jwt_access=True,
269267
)
270268

271269
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -294,6 +292,7 @@ def test_vpc_access_service_client_client_options(
294292
client_cert_source_for_mtls=None,
295293
quota_project_id="octopus",
296294
client_info=transports.base.DEFAULT_CLIENT_INFO,
295+
always_use_jwt_access=True,
297296
)
298297

299298

@@ -370,6 +369,7 @@ def test_vpc_access_service_client_mtls_env_auto(
370369
client_cert_source_for_mtls=expected_client_cert_source,
371370
quota_project_id=None,
372371
client_info=transports.base.DEFAULT_CLIENT_INFO,
372+
always_use_jwt_access=True,
373373
)
374374

375375
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -403,6 +403,7 @@ def test_vpc_access_service_client_mtls_env_auto(
403403
client_cert_source_for_mtls=expected_client_cert_source,
404404
quota_project_id=None,
405405
client_info=transports.base.DEFAULT_CLIENT_INFO,
406+
always_use_jwt_access=True,
406407
)
407408

408409
# Check the case client_cert_source and ADC client cert are not provided.
@@ -424,6 +425,7 @@ def test_vpc_access_service_client_mtls_env_auto(
424425
client_cert_source_for_mtls=None,
425426
quota_project_id=None,
426427
client_info=transports.base.DEFAULT_CLIENT_INFO,
428+
always_use_jwt_access=True,
427429
)
428430

429431

@@ -454,6 +456,7 @@ def test_vpc_access_service_client_client_options_scopes(
454456
client_cert_source_for_mtls=None,
455457
quota_project_id=None,
456458
client_info=transports.base.DEFAULT_CLIENT_INFO,
459+
always_use_jwt_access=True,
457460
)
458461

459462

@@ -484,6 +487,7 @@ def test_vpc_access_service_client_client_options_credentials_file(
484487
client_cert_source_for_mtls=None,
485488
quota_project_id=None,
486489
client_info=transports.base.DEFAULT_CLIENT_INFO,
490+
always_use_jwt_access=True,
487491
)
488492

489493

@@ -503,6 +507,7 @@ def test_vpc_access_service_client_client_options_from_dict():
503507
client_cert_source_for_mtls=None,
504508
quota_project_id=None,
505509
client_info=transports.base.DEFAULT_CLIENT_INFO,
510+
always_use_jwt_access=True,
506511
)
507512

508513

0 commit comments

Comments
 (0)