Content-Length: 489514 | pFad | https://www.github.com/googleapis/python-eventarc/commit/c9af9101a3d16395b6ccdecdfd6676394741f686

AFE fix: enable self signed jwt for grpc (#21) · googleapis/python-eventarc@c9af910 · GitHub
Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit c9af910

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

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

google/cloud/eventarc_v1/services/eventarc/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ def __init__(
372372
client_cert_source_for_mtls=client_cert_source_func,
373373
quota_project_id=client_options.quota_project_id,
374374
client_info=client_info,
375+
always_use_jwt_access=(
376+
Transport == type(self).get_transport_class("grpc")
377+
or Transport == type(self).get_transport_class("grpc_asyncio")
378+
),
375379
)
376380

377381
def get_trigger(

tests/unit/gapic/eventarc_v1/test_eventarc.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,14 @@ def test_eventarc_client_from_service_account_info(client_class):
119119
assert client.transport._host == "eventarc.googleapis.com:443"
120120

121121

122-
@pytest.mark.parametrize("client_class", [EventarcClient, EventarcAsyncClient,])
123-
def test_eventarc_client_service_account_always_use_jwt(client_class):
124-
with mock.patch.object(
125-
service_account.Credentials, "with_always_use_jwt_access", create=True
126-
) as use_jwt:
127-
creds = service_account.Credentials(None, None, None)
128-
client = client_class(credentials=creds)
129-
use_jwt.assert_not_called()
130-
131-
132122
@pytest.mark.parametrize(
133123
"transport_class,transport_name",
134124
[
135125
(transports.EventarcGrpcTransport, "grpc"),
136126
(transports.EventarcGrpcAsyncIOTransport, "grpc_asyncio"),
137127
],
138128
)
139-
def test_eventarc_client_service_account_always_use_jwt_true(
129+
def test_eventarc_client_service_account_always_use_jwt(
140130
transport_class, transport_name
141131
):
142132
with mock.patch.object(
@@ -146,6 +136,13 @@ def test_eventarc_client_service_account_always_use_jwt_true(
146136
transport = transport_class(credentials=creds, always_use_jwt_access=True)
147137
use_jwt.assert_called_once_with(True)
148138

139+
with mock.patch.object(
140+
service_account.Credentials, "with_always_use_jwt_access", create=True
141+
) as use_jwt:
142+
creds = service_account.Credentials(None, None, None)
143+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
144+
use_jwt.assert_not_called()
145+
149146

150147
@pytest.mark.parametrize("client_class", [EventarcClient, EventarcAsyncClient,])
151148
def test_eventarc_client_from_service_account_file(client_class):
@@ -216,6 +213,7 @@ def test_eventarc_client_client_options(client_class, transport_class, transport
216213
client_cert_source_for_mtls=None,
217214
quota_project_id=None,
218215
client_info=transports.base.DEFAULT_CLIENT_INFO,
216+
always_use_jwt_access=True,
219217
)
220218

221219
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -232,6 +230,7 @@ def test_eventarc_client_client_options(client_class, transport_class, transport
232230
client_cert_source_for_mtls=None,
233231
quota_project_id=None,
234232
client_info=transports.base.DEFAULT_CLIENT_INFO,
233+
always_use_jwt_access=True,
235234
)
236235

237236
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -248,6 +247,7 @@ def test_eventarc_client_client_options(client_class, transport_class, transport
248247
client_cert_source_for_mtls=None,
249248
quota_project_id=None,
250249
client_info=transports.base.DEFAULT_CLIENT_INFO,
250+
always_use_jwt_access=True,
251251
)
252252

253253
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -276,6 +276,7 @@ def test_eventarc_client_client_options(client_class, transport_class, transport
276276
client_cert_source_for_mtls=None,
277277
quota_project_id="octopus",
278278
client_info=transports.base.DEFAULT_CLIENT_INFO,
279+
always_use_jwt_access=True,
279280
)
280281

281282

@@ -340,6 +341,7 @@ def test_eventarc_client_mtls_env_auto(
340341
client_cert_source_for_mtls=expected_client_cert_source,
341342
quota_project_id=None,
342343
client_info=transports.base.DEFAULT_CLIENT_INFO,
344+
always_use_jwt_access=True,
343345
)
344346

345347
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -373,6 +375,7 @@ def test_eventarc_client_mtls_env_auto(
373375
client_cert_source_for_mtls=expected_client_cert_source,
374376
quota_project_id=None,
375377
client_info=transports.base.DEFAULT_CLIENT_INFO,
378+
always_use_jwt_access=True,
376379
)
377380

378381
# Check the case client_cert_source and ADC client cert are not provided.
@@ -394,6 +397,7 @@ def test_eventarc_client_mtls_env_auto(
394397
client_cert_source_for_mtls=None,
395398
quota_project_id=None,
396399
client_info=transports.base.DEFAULT_CLIENT_INFO,
400+
always_use_jwt_access=True,
397401
)
398402

399403

@@ -420,6 +424,7 @@ def test_eventarc_client_client_options_scopes(
420424
client_cert_source_for_mtls=None,
421425
quota_project_id=None,
422426
client_info=transports.base.DEFAULT_CLIENT_INFO,
427+
always_use_jwt_access=True,
423428
)
424429

425430

@@ -446,6 +451,7 @@ def test_eventarc_client_client_options_credentials_file(
446451
client_cert_source_for_mtls=None,
447452
quota_project_id=None,
448453
client_info=transports.base.DEFAULT_CLIENT_INFO,
454+
always_use_jwt_access=True,
449455
)
450456

451457

@@ -463,6 +469,7 @@ def test_eventarc_client_client_options_from_dict():
463469
client_cert_source_for_mtls=None,
464470
quota_project_id=None,
465471
client_info=transports.base.DEFAULT_CLIENT_INFO,
472+
always_use_jwt_access=True,
466473
)
467474

468475

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.github.com/googleapis/python-eventarc/commit/c9af9101a3d16395b6ccdecdfd6676394741f686

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy