Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit f5b5ca5

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

File tree

16 files changed

+176
-104
lines changed

16 files changed

+176
-104
lines changed

google/cloud/vision_v1/services/image_annotator/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ def __init__(
365365
client_cert_source_for_mtls=client_cert_source_func,
366366
quota_project_id=client_options.quota_project_id,
367367
client_info=client_info,
368+
always_use_jwt_access=(
369+
Transport == type(self).get_transport_class("grpc")
370+
or Transport == type(self).get_transport_class("grpc_asyncio")
371+
),
368372
)
369373

370374
def batch_annotate_images(

google/cloud/vision_v1/services/product_search/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ def __init__(
404404
client_cert_source_for_mtls=client_cert_source_func,
405405
quota_project_id=client_options.quota_project_id,
406406
client_info=client_info,
407+
always_use_jwt_access=(
408+
Transport == type(self).get_transport_class("grpc")
409+
or Transport == type(self).get_transport_class("grpc_asyncio")
410+
),
407411
)
408412

409413
def create_product_set(

google/cloud/vision_v1p1beta1/services/image_annotator/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 batch_annotate_images(

google/cloud/vision_v1p2beta1/services/image_annotator/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ def __init__(
333333
client_cert_source_for_mtls=client_cert_source_func,
334334
quota_project_id=client_options.quota_project_id,
335335
client_info=client_info,
336+
always_use_jwt_access=(
337+
Transport == type(self).get_transport_class("grpc")
338+
or Transport == type(self).get_transport_class("grpc_asyncio")
339+
),
336340
)
337341

338342
def batch_annotate_images(

google/cloud/vision_v1p3beta1/services/image_annotator/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ def __init__(
365365
client_cert_source_for_mtls=client_cert_source_func,
366366
quota_project_id=client_options.quota_project_id,
367367
client_info=client_info,
368+
always_use_jwt_access=(
369+
Transport == type(self).get_transport_class("grpc")
370+
or Transport == type(self).get_transport_class("grpc_asyncio")
371+
),
368372
)
369373

370374
def batch_annotate_images(

google/cloud/vision_v1p3beta1/services/product_search/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ def __init__(
405405
client_cert_source_for_mtls=client_cert_source_func,
406406
quota_project_id=client_options.quota_project_id,
407407
client_info=client_info,
408+
always_use_jwt_access=(
409+
Transport == type(self).get_transport_class("grpc")
410+
or Transport == type(self).get_transport_class("grpc_asyncio")
411+
),
408412
)
409413

410414
def create_product_set(

google/cloud/vision_v1p4beta1/services/image_annotator/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ def __init__(
365365
client_cert_source_for_mtls=client_cert_source_func,
366366
quota_project_id=client_options.quota_project_id,
367367
client_info=client_info,
368+
always_use_jwt_access=(
369+
Transport == type(self).get_transport_class("grpc")
370+
or Transport == type(self).get_transport_class("grpc_asyncio")
371+
),
368372
)
369373

370374
def batch_annotate_images(

google/cloud/vision_v1p4beta1/services/product_search/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ def __init__(
406406
client_cert_source_for_mtls=client_cert_source_func,
407407
quota_project_id=client_options.quota_project_id,
408408
client_info=client_info,
409+
always_use_jwt_access=(
410+
Transport == type(self).get_transport_class("grpc")
411+
or Transport == type(self).get_transport_class("grpc_asyncio")
412+
),
409413
)
410414

411415
def create_product_set(

tests/unit/gapic/vision_v1/test_image_annotator.py

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

126126

127-
@pytest.mark.parametrize(
128-
"client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,]
129-
)
130-
def test_image_annotator_client_service_account_always_use_jwt(client_class):
131-
with mock.patch.object(
132-
service_account.Credentials, "with_always_use_jwt_access", create=True
133-
) as use_jwt:
134-
creds = service_account.Credentials(None, None, None)
135-
client = client_class(credentials=creds)
136-
use_jwt.assert_not_called()
137-
138-
139127
@pytest.mark.parametrize(
140128
"transport_class,transport_name",
141129
[
142130
(transports.ImageAnnotatorGrpcTransport, "grpc"),
143131
(transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"),
144132
],
145133
)
146-
def test_image_annotator_client_service_account_always_use_jwt_true(
134+
def test_image_annotator_client_service_account_always_use_jwt(
147135
transport_class, transport_name
148136
):
149137
with mock.patch.object(
@@ -153,6 +141,13 @@ def test_image_annotator_client_service_account_always_use_jwt_true(
153141
transport = transport_class(credentials=creds, always_use_jwt_access=True)
154142
use_jwt.assert_called_once_with(True)
155143

144+
with mock.patch.object(
145+
service_account.Credentials, "with_always_use_jwt_access", create=True
146+
) as use_jwt:
147+
creds = service_account.Credentials(None, None, None)
148+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
149+
use_jwt.assert_not_called()
150+
156151

157152
@pytest.mark.parametrize(
158153
"client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,]
@@ -233,6 +228,7 @@ def test_image_annotator_client_client_options(
233228
client_cert_source_for_mtls=None,
234229
quota_project_id=None,
235230
client_info=transports.base.DEFAULT_CLIENT_INFO,
231+
always_use_jwt_access=True,
236232
)
237233

238234
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -249,6 +245,7 @@ def test_image_annotator_client_client_options(
249245
client_cert_source_for_mtls=None,
250246
quota_project_id=None,
251247
client_info=transports.base.DEFAULT_CLIENT_INFO,
248+
always_use_jwt_access=True,
252249
)
253250

254251
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -265,6 +262,7 @@ def test_image_annotator_client_client_options(
265262
client_cert_source_for_mtls=None,
266263
quota_project_id=None,
267264
client_info=transports.base.DEFAULT_CLIENT_INFO,
265+
always_use_jwt_access=True,
268266
)
269267

270268
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -293,6 +291,7 @@ def test_image_annotator_client_client_options(
293291
client_cert_source_for_mtls=None,
294292
quota_project_id="octopus",
295293
client_info=transports.base.DEFAULT_CLIENT_INFO,
294+
always_use_jwt_access=True,
296295
)
297296

298297

@@ -359,6 +358,7 @@ def test_image_annotator_client_mtls_env_auto(
359358
client_cert_source_for_mtls=expected_client_cert_source,
360359
quota_project_id=None,
361360
client_info=transports.base.DEFAULT_CLIENT_INFO,
361+
always_use_jwt_access=True,
362362
)
363363

364364
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -392,6 +392,7 @@ def test_image_annotator_client_mtls_env_auto(
392392
client_cert_source_for_mtls=expected_client_cert_source,
393393
quota_project_id=None,
394394
client_info=transports.base.DEFAULT_CLIENT_INFO,
395+
always_use_jwt_access=True,
395396
)
396397

397398
# Check the case client_cert_source and ADC client cert are not provided.
@@ -413,6 +414,7 @@ def test_image_annotator_client_mtls_env_auto(
413414
client_cert_source_for_mtls=None,
414415
quota_project_id=None,
415416
client_info=transports.base.DEFAULT_CLIENT_INFO,
417+
always_use_jwt_access=True,
416418
)
417419

418420

@@ -443,6 +445,7 @@ def test_image_annotator_client_client_options_scopes(
443445
client_cert_source_for_mtls=None,
444446
quota_project_id=None,
445447
client_info=transports.base.DEFAULT_CLIENT_INFO,
448+
always_use_jwt_access=True,
446449
)
447450

448451

@@ -473,6 +476,7 @@ def test_image_annotator_client_client_options_credentials_file(
473476
client_cert_source_for_mtls=None,
474477
quota_project_id=None,
475478
client_info=transports.base.DEFAULT_CLIENT_INFO,
479+
always_use_jwt_access=True,
476480
)
477481

478482

@@ -492,6 +496,7 @@ def test_image_annotator_client_client_options_from_dict():
492496
client_cert_source_for_mtls=None,
493497
quota_project_id=None,
494498
client_info=transports.base.DEFAULT_CLIENT_INFO,
499+
always_use_jwt_access=True,
495500
)
496501

497502

tests/unit/gapic/vision_v1/test_product_search.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,14 @@ def test_product_search_client_from_service_account_info(client_class):
127127
assert client.transport._host == "vision.googleapis.com:443"
128128

129129

130-
@pytest.mark.parametrize(
131-
"client_class", [ProductSearchClient, ProductSearchAsyncClient,]
132-
)
133-
def test_product_search_client_service_account_always_use_jwt(client_class):
134-
with mock.patch.object(
135-
service_account.Credentials, "with_always_use_jwt_access", create=True
136-
) as use_jwt:
137-
creds = service_account.Credentials(None, None, None)
138-
client = client_class(credentials=creds)
139-
use_jwt.assert_not_called()
140-
141-
142130
@pytest.mark.parametrize(
143131
"transport_class,transport_name",
144132
[
145133
(transports.ProductSearchGrpcTransport, "grpc"),
146134
(transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"),
147135
],
148136
)
149-
def test_product_search_client_service_account_always_use_jwt_true(
137+
def test_product_search_client_service_account_always_use_jwt(
150138
transport_class, transport_name
151139
):
152140
with mock.patch.object(
@@ -156,6 +144,13 @@ def test_product_search_client_service_account_always_use_jwt_true(
156144
transport = transport_class(credentials=creds, always_use_jwt_access=True)
157145
use_jwt.assert_called_once_with(True)
158146

147+
with mock.patch.object(
148+
service_account.Credentials, "with_always_use_jwt_access", create=True
149+
) as use_jwt:
150+
creds = service_account.Credentials(None, None, None)
151+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
152+
use_jwt.assert_not_called()
153+
159154

160155
@pytest.mark.parametrize(
161156
"client_class", [ProductSearchClient, ProductSearchAsyncClient,]
@@ -236,6 +231,7 @@ def test_product_search_client_client_options(
236231
client_cert_source_for_mtls=None,
237232
quota_project_id=None,
238233
client_info=transports.base.DEFAULT_CLIENT_INFO,
234+
always_use_jwt_access=True,
239235
)
240236

241237
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -252,6 +248,7 @@ def test_product_search_client_client_options(
252248
client_cert_source_for_mtls=None,
253249
quota_project_id=None,
254250
client_info=transports.base.DEFAULT_CLIENT_INFO,
251+
always_use_jwt_access=True,
255252
)
256253

257254
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -268,6 +265,7 @@ def test_product_search_client_client_options(
268265
client_cert_source_for_mtls=None,
269266
quota_project_id=None,
270267
client_info=transports.base.DEFAULT_CLIENT_INFO,
268+
always_use_jwt_access=True,
271269
)
272270

273271
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -296,6 +294,7 @@ def test_product_search_client_client_options(
296294
client_cert_source_for_mtls=None,
297295
quota_project_id="octopus",
298296
client_info=transports.base.DEFAULT_CLIENT_INFO,
297+
always_use_jwt_access=True,
299298
)
300299

301300

@@ -362,6 +361,7 @@ def test_product_search_client_mtls_env_auto(
362361
client_cert_source_for_mtls=expected_client_cert_source,
363362
quota_project_id=None,
364363
client_info=transports.base.DEFAULT_CLIENT_INFO,
364+
always_use_jwt_access=True,
365365
)
366366

367367
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -395,6 +395,7 @@ def test_product_search_client_mtls_env_auto(
395395
client_cert_source_for_mtls=expected_client_cert_source,
396396
quota_project_id=None,
397397
client_info=transports.base.DEFAULT_CLIENT_INFO,
398+
always_use_jwt_access=True,
398399
)
399400

400401
# Check the case client_cert_source and ADC client cert are not provided.
@@ -416,6 +417,7 @@ def test_product_search_client_mtls_env_auto(
416417
client_cert_source_for_mtls=None,
417418
quota_project_id=None,
418419
client_info=transports.base.DEFAULT_CLIENT_INFO,
420+
always_use_jwt_access=True,
419421
)
420422

421423

@@ -446,6 +448,7 @@ def test_product_search_client_client_options_scopes(
446448
client_cert_source_for_mtls=None,
447449
quota_project_id=None,
448450
client_info=transports.base.DEFAULT_CLIENT_INFO,
451+
always_use_jwt_access=True,
449452
)
450453

451454

@@ -476,6 +479,7 @@ def test_product_search_client_client_options_credentials_file(
476479
client_cert_source_for_mtls=None,
477480
quota_project_id=None,
478481
client_info=transports.base.DEFAULT_CLIENT_INFO,
482+
always_use_jwt_access=True,
479483
)
480484

481485

@@ -495,6 +499,7 @@ def test_product_search_client_client_options_from_dict():
495499
client_cert_source_for_mtls=None,
496500
quota_project_id=None,
497501
client_info=transports.base.DEFAULT_CLIENT_INFO,
502+
always_use_jwt_access=True,
498503
)
499504

500505

0 commit comments

Comments
 (0)