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

Commit 29475ff

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

File tree

12 files changed

+132
-89
lines changed

12 files changed

+132
-89
lines changed

google/cloud/videointelligence_v1/services/video_intelligence_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def __init__(
331331
client_cert_source_for_mtls=client_cert_source_func,
332332
quota_project_id=client_options.quota_project_id,
333333
client_info=client_info,
334+
always_use_jwt_access=(
335+
Transport == type(self).get_transport_class("grpc")
336+
or Transport == type(self).get_transport_class("grpc_asyncio")
337+
),
334338
)
335339

336340
def annotate_video(

google/cloud/videointelligence_v1beta2/services/video_intelligence_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def __init__(
331331
client_cert_source_for_mtls=client_cert_source_func,
332332
quota_project_id=client_options.quota_project_id,
333333
client_info=client_info,
334+
always_use_jwt_access=(
335+
Transport == type(self).get_transport_class("grpc")
336+
or Transport == type(self).get_transport_class("grpc_asyncio")
337+
),
334338
)
335339

336340
def annotate_video(

google/cloud/videointelligence_v1p1beta1/services/video_intelligence_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def __init__(
331331
client_cert_source_for_mtls=client_cert_source_func,
332332
quota_project_id=client_options.quota_project_id,
333333
client_info=client_info,
334+
always_use_jwt_access=(
335+
Transport == type(self).get_transport_class("grpc")
336+
or Transport == type(self).get_transport_class("grpc_asyncio")
337+
),
334338
)
335339

336340
def annotate_video(

google/cloud/videointelligence_v1p2beta1/services/video_intelligence_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def __init__(
331331
client_cert_source_for_mtls=client_cert_source_func,
332332
quota_project_id=client_options.quota_project_id,
333333
client_info=client_info,
334+
always_use_jwt_access=(
335+
Transport == type(self).get_transport_class("grpc")
336+
or Transport == type(self).get_transport_class("grpc_asyncio")
337+
),
334338
)
335339

336340
def annotate_video(

google/cloud/videointelligence_v1p3beta1/services/streaming_video_intelligence_service/client.py

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

354358
def streaming_annotate_video(

google/cloud/videointelligence_v1p3beta1/services/video_intelligence_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def __init__(
331331
client_cert_source_for_mtls=client_cert_source_func,
332332
quota_project_id=client_options.quota_project_id,
333333
client_info=client_info,
334+
always_use_jwt_access=(
335+
Transport == type(self).get_transport_class("grpc")
336+
or Transport == type(self).get_transport_class("grpc_asyncio")
337+
),
334338
)
335339

336340
def annotate_video(

tests/unit/gapic/videointelligence_v1/test_video_intelligence_service.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,14 @@ def test_video_intelligence_service_client_from_service_account_info(client_clas
130130
assert client.transport._host == "videointelligence.googleapis.com:443"
131131

132132

133-
@pytest.mark.parametrize(
134-
"client_class",
135-
[VideoIntelligenceServiceClient, VideoIntelligenceServiceAsyncClient,],
136-
)
137-
def test_video_intelligence_service_client_service_account_always_use_jwt(client_class):
138-
with mock.patch.object(
139-
service_account.Credentials, "with_always_use_jwt_access", create=True
140-
) as use_jwt:
141-
creds = service_account.Credentials(None, None, None)
142-
client = client_class(credentials=creds)
143-
use_jwt.assert_not_called()
144-
145-
146133
@pytest.mark.parametrize(
147134
"transport_class,transport_name",
148135
[
149136
(transports.VideoIntelligenceServiceGrpcTransport, "grpc"),
150137
(transports.VideoIntelligenceServiceGrpcAsyncIOTransport, "grpc_asyncio"),
151138
],
152139
)
153-
def test_video_intelligence_service_client_service_account_always_use_jwt_true(
140+
def test_video_intelligence_service_client_service_account_always_use_jwt(
154141
transport_class, transport_name
155142
):
156143
with mock.patch.object(
@@ -160,6 +147,13 @@ def test_video_intelligence_service_client_service_account_always_use_jwt_true(
160147
transport = transport_class(credentials=creds, always_use_jwt_access=True)
161148
use_jwt.assert_called_once_with(True)
162149

150+
with mock.patch.object(
151+
service_account.Credentials, "with_always_use_jwt_access", create=True
152+
) as use_jwt:
153+
creds = service_account.Credentials(None, None, None)
154+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
155+
use_jwt.assert_not_called()
156+
163157

164158
@pytest.mark.parametrize(
165159
"client_class",
@@ -249,6 +243,7 @@ def test_video_intelligence_service_client_client_options(
249243
client_cert_source_for_mtls=None,
250244
quota_project_id=None,
251245
client_info=transports.base.DEFAULT_CLIENT_INFO,
246+
always_use_jwt_access=True,
252247
)
253248

254249
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -265,6 +260,7 @@ def test_video_intelligence_service_client_client_options(
265260
client_cert_source_for_mtls=None,
266261
quota_project_id=None,
267262
client_info=transports.base.DEFAULT_CLIENT_INFO,
263+
always_use_jwt_access=True,
268264
)
269265

270266
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -281,6 +277,7 @@ def test_video_intelligence_service_client_client_options(
281277
client_cert_source_for_mtls=None,
282278
quota_project_id=None,
283279
client_info=transports.base.DEFAULT_CLIENT_INFO,
280+
always_use_jwt_access=True,
284281
)
285282

286283
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -309,6 +306,7 @@ def test_video_intelligence_service_client_client_options(
309306
client_cert_source_for_mtls=None,
310307
quota_project_id="octopus",
311308
client_info=transports.base.DEFAULT_CLIENT_INFO,
309+
always_use_jwt_access=True,
312310
)
313311

314312

@@ -385,6 +383,7 @@ def test_video_intelligence_service_client_mtls_env_auto(
385383
client_cert_source_for_mtls=expected_client_cert_source,
386384
quota_project_id=None,
387385
client_info=transports.base.DEFAULT_CLIENT_INFO,
386+
always_use_jwt_access=True,
388387
)
389388

390389
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -418,6 +417,7 @@ def test_video_intelligence_service_client_mtls_env_auto(
418417
client_cert_source_for_mtls=expected_client_cert_source,
419418
quota_project_id=None,
420419
client_info=transports.base.DEFAULT_CLIENT_INFO,
420+
always_use_jwt_access=True,
421421
)
422422

423423
# Check the case client_cert_source and ADC client cert are not provided.
@@ -439,6 +439,7 @@ def test_video_intelligence_service_client_mtls_env_auto(
439439
client_cert_source_for_mtls=None,
440440
quota_project_id=None,
441441
client_info=transports.base.DEFAULT_CLIENT_INFO,
442+
always_use_jwt_access=True,
442443
)
443444

444445

@@ -473,6 +474,7 @@ def test_video_intelligence_service_client_client_options_scopes(
473474
client_cert_source_for_mtls=None,
474475
quota_project_id=None,
475476
client_info=transports.base.DEFAULT_CLIENT_INFO,
477+
always_use_jwt_access=True,
476478
)
477479

478480

@@ -507,6 +509,7 @@ def test_video_intelligence_service_client_client_options_credentials_file(
507509
client_cert_source_for_mtls=None,
508510
quota_project_id=None,
509511
client_info=transports.base.DEFAULT_CLIENT_INFO,
512+
always_use_jwt_access=True,
510513
)
511514

512515

@@ -526,6 +529,7 @@ def test_video_intelligence_service_client_client_options_from_dict():
526529
client_cert_source_for_mtls=None,
527530
quota_project_id=None,
528531
client_info=transports.base.DEFAULT_CLIENT_INFO,
532+
always_use_jwt_access=True,
529533
)
530534

531535

tests/unit/gapic/videointelligence_v1beta2/test_video_intelligence_service.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,14 @@ def test_video_intelligence_service_client_from_service_account_info(client_clas
130130
assert client.transport._host == "videointelligence.googleapis.com:443"
131131

132132

133-
@pytest.mark.parametrize(
134-
"client_class",
135-
[VideoIntelligenceServiceClient, VideoIntelligenceServiceAsyncClient,],
136-
)
137-
def test_video_intelligence_service_client_service_account_always_use_jwt(client_class):
138-
with mock.patch.object(
139-
service_account.Credentials, "with_always_use_jwt_access", create=True
140-
) as use_jwt:
141-
creds = service_account.Credentials(None, None, None)
142-
client = client_class(credentials=creds)
143-
use_jwt.assert_not_called()
144-
145-
146133
@pytest.mark.parametrize(
147134
"transport_class,transport_name",
148135
[
149136
(transports.VideoIntelligenceServiceGrpcTransport, "grpc"),
150137
(transports.VideoIntelligenceServiceGrpcAsyncIOTransport, "grpc_asyncio"),
151138
],
152139
)
153-
def test_video_intelligence_service_client_service_account_always_use_jwt_true(
140+
def test_video_intelligence_service_client_service_account_always_use_jwt(
154141
transport_class, transport_name
155142
):
156143
with mock.patch.object(
@@ -160,6 +147,13 @@ def test_video_intelligence_service_client_service_account_always_use_jwt_true(
160147
transport = transport_class(credentials=creds, always_use_jwt_access=True)
161148
use_jwt.assert_called_once_with(True)
162149

150+
with mock.patch.object(
151+
service_account.Credentials, "with_always_use_jwt_access", create=True
152+
) as use_jwt:
153+
creds = service_account.Credentials(None, None, None)
154+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
155+
use_jwt.assert_not_called()
156+
163157

164158
@pytest.mark.parametrize(
165159
"client_class",
@@ -249,6 +243,7 @@ def test_video_intelligence_service_client_client_options(
249243
client_cert_source_for_mtls=None,
250244
quota_project_id=None,
251245
client_info=transports.base.DEFAULT_CLIENT_INFO,
246+
always_use_jwt_access=True,
252247
)
253248

254249
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -265,6 +260,7 @@ def test_video_intelligence_service_client_client_options(
265260
client_cert_source_for_mtls=None,
266261
quota_project_id=None,
267262
client_info=transports.base.DEFAULT_CLIENT_INFO,
263+
always_use_jwt_access=True,
268264
)
269265

270266
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -281,6 +277,7 @@ def test_video_intelligence_service_client_client_options(
281277
client_cert_source_for_mtls=None,
282278
quota_project_id=None,
283279
client_info=transports.base.DEFAULT_CLIENT_INFO,
280+
always_use_jwt_access=True,
284281
)
285282

286283
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -309,6 +306,7 @@ def test_video_intelligence_service_client_client_options(
309306
client_cert_source_for_mtls=None,
310307
quota_project_id="octopus",
311308
client_info=transports.base.DEFAULT_CLIENT_INFO,
309+
always_use_jwt_access=True,
312310
)
313311

314312

@@ -385,6 +383,7 @@ def test_video_intelligence_service_client_mtls_env_auto(
385383
client_cert_source_for_mtls=expected_client_cert_source,
386384
quota_project_id=None,
387385
client_info=transports.base.DEFAULT_CLIENT_INFO,
386+
always_use_jwt_access=True,
388387
)
389388

390389
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -418,6 +417,7 @@ def test_video_intelligence_service_client_mtls_env_auto(
418417
client_cert_source_for_mtls=expected_client_cert_source,
419418
quota_project_id=None,
420419
client_info=transports.base.DEFAULT_CLIENT_INFO,
420+
always_use_jwt_access=True,
421421
)
422422

423423
# Check the case client_cert_source and ADC client cert are not provided.
@@ -439,6 +439,7 @@ def test_video_intelligence_service_client_mtls_env_auto(
439439
client_cert_source_for_mtls=None,
440440
quota_project_id=None,
441441
client_info=transports.base.DEFAULT_CLIENT_INFO,
442+
always_use_jwt_access=True,
442443
)
443444

444445

@@ -473,6 +474,7 @@ def test_video_intelligence_service_client_client_options_scopes(
473474
client_cert_source_for_mtls=None,
474475
quota_project_id=None,
475476
client_info=transports.base.DEFAULT_CLIENT_INFO,
477+
always_use_jwt_access=True,
476478
)
477479

478480

@@ -507,6 +509,7 @@ def test_video_intelligence_service_client_client_options_credentials_file(
507509
client_cert_source_for_mtls=None,
508510
quota_project_id=None,
509511
client_info=transports.base.DEFAULT_CLIENT_INFO,
512+
always_use_jwt_access=True,
510513
)
511514

512515

@@ -526,6 +529,7 @@ def test_video_intelligence_service_client_client_options_from_dict():
526529
client_cert_source_for_mtls=None,
527530
quota_project_id=None,
528531
client_info=transports.base.DEFAULT_CLIENT_INFO,
532+
always_use_jwt_access=True,
529533
)
530534

531535

0 commit comments

Comments
 (0)