8000 fix: enable self signed jwt for grpc (#190) · googleapis/python-monitoring@502487a · GitHub
[go: up one dir, main page]

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

Commit 502487a

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

File tree

14 files changed

+154
-91
lines changed

14 files changed

+154
-91
lines changed

google/cloud/monitoring_v3/services/alert_policy_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ def __init__(
377377
client_cert_source_for_mtls=client_cert_source_func,
378378
quota_project_id=client_options.quota_project_id,
379379
client_info=client_info,
380+
always_use_jwt_access=(
381+
Transport == type(self).get_transport_class("grpc")
382+
or Transport == type(self).get_transport_class("grpc_asyncio")
383+
),
380384
)
381385

382386
def list_alert_policies(

google/cloud/monitoring_v3/services/group_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ def __init__(
352352
client_cert_source_for_mtls=client_cert_source_func,
353353
quota_project_id=client_options.quota_project_id,
354354
client_info=client_info,
355+
always_use_jwt_access=(
356+
Transport == type(self).get_transport_class("grpc")
357+
or Transport == type(self).get_transport_class("grpc_asyncio")
358+
),
355359
)
356360

357361
def list_groups(

google/cloud/monitoring_v3/services/metric_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ def __init__(
379379
client_cert_source_for_mtls=client_cert_source_func,
380380
quota_project_id=client_options.quota_project_id,
381381
client_info=client_info,
382+
always_use_jwt_access=(
383+
Transport == type(self).get_transport_class("grpc")
384+
or Transport == type(self).get_transport_class("grpc_asyncio")
385+
),
382386
)
383387

384388
def list_monitored_resource_descriptors(

google/cloud/monitoring_v3/services/notification_channel_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ def __init__(
374374
client_cert_source_for_mtls=client_cert_source_func,
375375
quota_project_id=client_options.quota_project_id,
376376
client_info=client_info,
377+
always_use_jwt_access=(
378+
Transport == type(self).get_transport_class("grpc")
379+
or Transport == type(self).get_transport_class("grpc_asyncio")
380+
),
377381
)
378382

379383
def list_notification_channel_descriptors(

google/cloud/monitoring_v3/services/query_service/client.py

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

335339
def query_time_series(

google/cloud/monitoring_v3/services/service_monitoring_service/client.py

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

376380
def create_service(

google/cloud/monitoring_v3/services/uptime_check_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ def __init__(
357357
client_cert_source_for_mtls=client_cert_source_func,
358358
quota_project_id=client_options.quota_project_id,
359359
client_info=client_info,
360+
always_use_jwt_access=(
361+
Transport == type(self).get_transport_class("grpc")
362+
or Transport == type(self).get_transport_class("grpc_asyncio")
363+
),
360364
)
361365

362366
def list_uptime_check_configs(

tests/unit/gapic/monitoring_v3/test_alert_policy_service.py

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

134134

135-
@pytest.mark.parametrize(
136-
"client_class", [AlertPolicyServiceClient, AlertPolicyServiceAsyncClient,]
137-
)
138-
def test_alert_policy_service_client_service_account_always_use_jwt(client_class):
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-
client = client_class(credentials=creds)
144-
use_jwt.assert_not_called()
145-
146-
147135
@pytest.mark.parametrize(
148136
"transport_class,transport_name",
149137
[
150138
(transports.AlertPolicyServiceGrpcTransport, "grpc"),
151139
(transports.AlertPolicyServiceGrpcAsyncIOTransport, "grpc_asyncio"),
152140
],
153141
)
154-
def test_alert_policy_service_client_service_account_always_use_jwt_true(
142+
def test_alert_policy_service_client_service_account_always_use_jwt(
155143
transport_class, transport_name
156144
):
157145
with mock.patch.object(
@@ -161,6 +149,13 @@ def test_alert_policy_service_client_service_account_always_use_jwt_true(
161149
transport = transport_class(credentials=creds, always_use_jwt_access=True)
162150
use_jwt.assert_called_once_with(True)
163151

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

165160
@pytest.mark.parametrize(
166161
"client_class", [AlertPolicyServiceClient, AlertPolicyServiceAsyncClient,]
@@ -241,6 +236,7 @@ def test_alert_policy_service_client_client_options(
241236
client_cert_source_for_mtls=None,
242237
quota_project_id=None,
243238
client_info=transports.base.DEFAULT_CLIENT_INFO,
239+
always_use_jwt_access=True,
244240
)
245241

246242
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -257,6 +253,7 @@ def test_alert_policy_service_client_client_options(
257253
client_cert_source_for_mtls=None,
258254
quota_project_id=None,
259255
client_info=transports.base.DEFAULT_CLIENT_INFO,
256+
always_use_jwt_access=True,
260257
)
261258

262259
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -273,6 +270,7 @@ def test_alert_policy_service_client_client_options(
273270
client_cert_source_for_mtls=None,
274271
quota_project_id=None,
275272
client_info=transports.base.DEFAULT_CLIENT_INFO,
273+
always_use_jwt_access=True,
276274
)
277275

278276
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -301,6 +299,7 @@ def test_alert_policy_service_client_client_options(
301299
client_cert_source_for_mtls=None,
302300
quota_project_id="octopus",
303301
client_info=transports.base.DEFAULT_CLIENT_INFO,
302+
always_use_jwt_access=True,
304303
)
305304

306305

@@ -377,6 +376,7 @@ def test_alert_policy_service_client_mtls_env_auto(
377376
client_cert_source_for_mtls=expected_client_cert_source,
378377
quota_project_id=None,
379378
client_info=transports.base.DEFAULT_CLIENT_INFO,
379+
always_use_jwt_access=True,
380380
)
381381

382382
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -410,6 +410,7 @@ def test_alert_policy_service_client_mtls_env_auto(
410410
client_cert_source_for_mtls=expected_client_cert_source,
411411
quota_project_id=None,
412412
client_info=transports.base.DEFAULT_CLIENT_INFO,
413+
always_use_jwt_access=True,
413414
)
414415

415416
# Check the case client_cert_source and ADC client cert are not provided.
@@ -431,6 +432,7 @@ def test_alert_policy_service_client_mtls_env_auto(
431432
client_cert_source_for_mtls=None,
432433
quota_project_id=None,
433434
client_info=transports.base.DEFAULT_CLIENT_INFO,
435+
always_use_jwt_access=True,
434436
)
435437

436438

@@ -461,6 +463,7 @@ def test_alert_policy_service_client_client_options_scopes(
461463
F438 client_cert_source_for_mtls=None,
462464
quota_project_id=None,
463465
client_info=transports.base.DEFAULT_CLIENT_INFO,
466+
always_use_jwt_access=True,
464467
)
465468

466469

@@ -491,6 +494,7 @@ def test_alert_policy_service_client_client_options_credentials_file(
491494
client_cert_source_for_mtls=None,
492495
quota_project_id=None,
493496
client_info=transports.base.DEFAULT_CLIENT_INFO,
497+
always_use_jwt_access=True,
494498
)
495499

496500

@@ -510,6 +514,7 @@ def test_alert_policy_service_client_client_options_from_dict():
510514
client_cert_source_for_mtls=None,
511515
quota_project_id=None,
512516
client_info=transports.base.DEFAULT_CLIENT_INFO,
517+
always_use_jwt_access=True,
513518
)
514519

515520

tests/unit/gapic/monitoring_v3/test_group_service.py

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

120120

121-
@pytest.mark.parametrize("client_class", [GroupServiceClient, GroupServiceAsyncClient,])
122-
def test_group_service_client_service_account_always_use_jwt(client_class):
123-
with mock.patch.object(
124-
service_account.Credentials, "with_always_use_jwt_access", create=True
125-
) as use_jwt:
126-
creds = service_account.Credentials(None, None, None)
127-
client = client_class(credentials=creds)
128-
use_jwt.assert_not_called()
129-
130-
131121
@pytest.mark.parametrize(
132122
"transport_class,transport_name",
133123
[
134124
(transports.GroupServiceGrpcTransport, "grpc"),
135125
(transports.GroupServiceGrpcAsyncIOTransport, "grpc_asyncio"),
136126
],
137127
)
138-
def test_group_service_client_service_account_always_use_jwt_true(
128+
def test_group_service_client_service_account_always_use_jwt(
139129
transport_class, transport_name
140130
):
141131
with mock.patch.object(
@@ -145,6 +135,13 @@ def test_group_service_client_service_account_always_use_jwt_true(
145135
transport = transport_class(credentials=creds, always_use_jwt_access=True)
146136
use_jwt.assert_called_once_with(True)
147137

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+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
143+
use_jwt.assert_not_called()
144+
148145

149146
@pytest.mark.parametrize("client_class", [GroupServiceClient, GroupServiceAsyncClient,])
150147
def test_group_service_client_from_service_account_file(client_class):
@@ -221,6 +218,7 @@ def test_group_service_client_client_options(
221218
client_cert_source_for_mtls=None,
222219
quota_project_id=None,
223220
client_info=transports.base.DEFAULT_CLIENT_INFO,
221+
always_use_jwt_access=True,
224222
)
225223

226224
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -237,6 +235,7 @@ def test_group_service_client_client_options(
237235
client_cert_source_for_mtls=None,
238236
quota_project_id=None,
239237
client_info=transports.base.DEFAULT_CLIENT_INFO,
238+
always_use_jwt_access=True,
240239
)
241240

242241
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -253,6 +252,7 @@ def test_group_service_client_client_options(
253252
client_cert_source_for_mtls=None,
254253
quota_project_id=None,
255254
client_info=transports.base.DEFAULT_CLIENT_INFO,
255+
always_use_jwt_access=True,
256256
)
257257

258258
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -281,6 +281,7 @@ def test_group_service_client_client_options(
281281
client_cert_source_for_mtls=None,
282282
quota_project_id="octopus",
283283
client_info=transports.base.DEFAULT_CLIENT_INFO,
284+
always_use_jwt_access=True,
284285
)
285286

286287

@@ -345,6 +346,7 @@ def test_group_service_client_mtls_env_auto(
345346
client_cert_source_for_mtls=expected_client_cert_source,
346347
quota_project_id=None,
347348
client_info=transports.base.DEFAULT_CLIENT_INFO,
349+
always_use_jwt_access=True,
348350
)
349351

350352
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -378,6 +380,7 @@ def test_group_service_client_mtls_env_auto(
378380
client_cert_source_for_mtls=expected_client_cert_source,
379381
quota_project_id=None,
380382
client_info=transports.base.DEFAULT_CLIENT_INFO,
383+
always_use_jwt_access=True,
381384
)
382385

383386
# Check the case client_cert_source and ADC client cert are not provided.
@@ -399,6 +402,7 @@ def test_group_service_client_mtls_env_auto(
399402
client_cert_source_for_mtls=None,
400403
quota_project_id=None,
401404
client_info=transports.base.DEFAULT_CLIENT_INFO,
405+
always_use_jwt_access=True,
402406
)
403407

404408

@@ -429,6 +433,7 @@ def test_group_service_client_client_options_scopes(
429433
client_cert_source_for_mtls=None,
430434
quota_project_id=None,
431435
client_info=transports.base.DEFAULT_CLIENT_INFO,
436+
always_use_jwt_access=True,
432437
)
433438

434439

@@ -459,6 +464,7 @@ def test_group_service_client_client_options_credentials_file(
459464
client_cert_source_for_mtls=None,
460465
quota_project_id=None,
461466
client_info=transports.base.DEFAULT_CLIENT_INFO,
467+
always_use_jwt_access=True,
462468
)
463469

464470

@@ -476,6 +482,7 @@ def test_group_service_client_client_options_from_dict():
476482
client_cert_source_for_mtls=None,
477483
quota_project_id=None,
478484
client_info=transports.base.DEFAULT_CLIENT_INFO,
485+
always_use_jwt_access=True,
479486
)
480487

481488

0 commit comments

Comments
 (0)
0