8000 fix: enable self signed jwt for grpc (#99) · googleapis/google-cloud-python@abde372 · GitHub
[go: up one dir, main page]

Skip to content

Commit abde372

Browse files
fix: enable self signed jwt for grpc (#99)
PiperOrigin-RevId: 386504689 Source-Link: googleapis/googleapis@762094a Source-Link: googleapis/googleapis-gen@6bfc480
1 parent cb9142b commit abde372

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ def __init__(
362362
client_cert_source_for_mtls=client_cert_source_func,
363363
quota_project_id=client_options.quota_project_id,
364364
client_info=client_info,
365+
always_use_jwt_access=(
366+
Transport == type(self).get_transport_class("grpc")
367+
or Transport == type(self).get_transport_class("grpc_asyncio")
368+
),
365369
)
366370

367371
def create_dashboard(

packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,14 @@ def test_dashboards_service_client_from_service_account_info(client_class):
133133
assert client.transport._host == "monitoring.googleapis.com:443"
134134

135135

136-
@pytest.mark.parametrize(
137-
"client_class", [DashboardsServiceClient, DashboardsServiceAsyncClient,]
138-
)
139-
def test_dashboards_service_client_service_account_always_use_jwt(client_class):
140-
with mock.patch.object(
141-
service_account.Credentials, "with_always_use_jwt_access", create=True
142-
) as use_jwt:
143-
creds = service_account.Credentials(None, None, None)
144-
client = client_class(credentials=creds)
145-
use_jwt.assert_not_called()
146-
147-
148136
@pytest.mark.parametrize(
149137
"transport_class,transport_name",
150138
[
151139
(transports.DashboardsServiceGrpcTransport, "grpc"),
152140
(transports.DashboardsServiceGrpcAsyncIOTransport, "grpc_asyncio"),
153141
],
154142
)
155-
def test_dashboards_service_client_service_account_always_use_jwt_true(
143+
def test_dashboards_service_client_service_account_always_use_jwt(
156144
transport_class, transport_name
157145
):
158146
with mock.patch.object(
@@ -162,6 +150,13 @@ def test_dashboards_service_client_service_account_always_use_jwt_true(
162150
transport = transport_class(credentials=creds, always_use_jwt_access=True)
163151
use_jwt.assert_called_once_with(True)
164152

153+
with mock.patch.object(
154+
service_account.Credentials, "with_always_use_jwt_access", create=True
155+
) as use_jwt:
156+
creds = service_account.Credentials(None, None, None)
157+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
158+
use_jwt.assert_not_called()
159+
165160

166161
@pytest.mark.parametrize(
167162
"client_class", [DashboardsServiceClient, DashboardsServiceAsyncClient,]
@@ -242,6 +237,7 @@ def test_dashboards_service_client_client_options(
242237
client_cert_source_for_mtls=None,
243238
quota_project_id=None,
244239
client_info=transports.base.DEFAULT_CLIENT_INFO,
240+
always_use_jwt_access=True,
245241
)
246242

247243
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -258,6 +254,7 @@ def test_dashboards_service_client_client_options(
258254
client_cert_source_for_mtls=None,
259255
quota_project_id=None,
260256
client_info=transports.base.DEFAULT_CLIENT_INFO,
257+
always_use_jwt_access=True,
261258
)
262259

263260
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -274,6 +271,7 @@ def test_dashboards_service_client_client_options(
274271
client_cert_source_for_mtls=None,
275272
quota_project_id=None,
276273
client_info=transports.base.DEFAULT_CLIENT_INFO,
274+
always_use_jwt_access=True,
277275
)
278276

279277
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -302,6 +300,7 @@ def test_dashboards_service_client_client_options(
302300
client_cert_source_for_mtls=None,
303301
quota_project_id="octopus",
304302
client_info=transports.base.DEFAULT_CLIENT_INFO,
303+
always_use_jwt_access=True,
305304
)
306305

307306

@@ -378,6 +377,7 @@ def test_dashboards_service_client_mtls_env_auto(
378377
client_cert_source_for_mtls=expected_client_cert_source,
379378
quota_project_id=None,
380379
client_info=transports.base.DEFAULT_CLIENT_INFO,
380+
always_use_jwt_access=True,
381381
)
382382

383383
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -411,6 +411,7 @@ def test_dashboards_service_client_mtls_env_auto(
411411
client_cert_source_for_mtls=expected_client_cert_source,
412412
quota_project_id=None,
413413
client_info=transports.base.DEFAULT_CLIENT_INFO,
414+
always_use_jwt_access=True,
414415
)
415416

416417
# Check the case client_cert_source and ADC client cert are not provided.
@@ -432,6 +433,7 @@ def test_dashboards_service_client_mtls_env_auto(
432433
client_cert_source_for_mtls=None,
433434
quota_project_id=None,
434435
client_info=transports.base.DEFAULT_CLIENT_INFO,
436+
always_use_jwt_access=True,
435437
)
436438

437439

@@ -462,6 +464,7 @@ def test_dashboards_service_client_client_options_scopes(
462464
client_cert_source_for_mtls=None,
463465
quota_project_id=None,
464466
client_info=transports.base.DEFAULT_CLIENT_INFO,
467+
always_use_jwt_access=True,
465468
)
466469

467470

@@ -492,6 +495,7 @@ def test_dashboards_service_client_client_options_credentials_file(
492495
client_cert_source_for_mtls=None,
493496
quota_project_id=None,
494497
client_info=transports.base.DEFAULT_CLIENT_INFO,
498+
always_use_jwt_access=True,
495499
)
496500

497501

@@ -511,6 +515,7 @@ def test_dashboards_service_client_client_options_from_dict():
511515
client_cert_source_for_mtls=None,
512516
quota_project_id=None,
513517
client_info=transports.base.DEFAULT_CLIENT_INFO,
518+
always_use_jwt_access=True,
514519
)
515520

516521

0 commit comments

Comments
 (0)
0