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

Commit 9d4ccd1

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

File tree

16 files changed

+176
-122
lines changed

16 files changed

+176
-122
lines changed

google/cloud/gaming_v1/services/game_server_clusters_service/client.py

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

361365
def list_game_server_clusters(

google/cloud/gaming_v1/services/game_server_configs_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ def __init__(
355355
client_cert_source_for_mtls=client_cert_source_func,
356356
quota_project_id=client_options.quota_project_id,
357357
client_info=client_info,
358+
always_use_jwt_access=(
359+
Transport == type(self).get_transport_class("grpc")
360+
or Transport == type(self).get_transport_class("grpc_asyncio")
361+
),
358362
)
359363

360364
def list_game_server_configs(

google/cloud/gaming_v1/services/game_server_deployments_service/client.py

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

383387
def list_game_server_deployments(

google/cloud/gaming_v1/services/realms_service/client.py

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

355359
def list_realms(

google/cloud/gaming_v1beta/services/game_server_clusters_service/client.py

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

361365
def list_game_server_clusters(

google/cloud/gaming_v1beta/services/game_server_configs_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ def __init__(
355355
client_cert_source_for_mtls=client_cert_source_func,
356356
quota_project_id=client_options.quota_project_id,
357357
client_info=client_info,
358+
always_use_jwt_access=(
359+
Transport == type(self).get_transport_class("grpc")
360+
or Transport == type(self).get_transport_class("grpc_asyncio")
361+
),
358362
)
359363

360364
def list_game_server_configs(

google/cloud/gaming_v1beta/services/game_server_deployments_service/client.py

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

383387
def list_game_server_deployments(

google/cloud/gaming_v1beta/services/realms_service/client.py

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

355359
def list_realms(

tests/unit/gapic/gaming_v1/test_game_server_clusters_service.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,14 @@ def test_game_server_clusters_service_client_from_service_account_info(client_cl
133133
assert client.transport._host == "gameservices.googleapis.com:443"
134134

135135

136-
@pytest.mark.parametrize(
137-
"client_class",
138-
[GameServerClustersServiceClient, GameServerClustersServiceAsyncClient,],
139-
)
140-
def test_game_server_clusters_service_client_service_account_always_use_jwt(
141-
client_class,
142-
):
143-
with mock.patch.object(
144-
service_account.Credentials, "with_always_use_jwt_access", create=True
145-
) as use_jwt:
146-
creds = service_account.Credentials(None, None, None)
147-
client = client_class(credentials=creds)
148-
use_jwt.assert_not_called()
149-
150-
151136
@pytest.mark.parametrize(
152137
"transport_class,transport_name",
153138
[
154139
(transports.GameServerClustersServiceGrpcTransport, "grpc"),
155140
(transports.GameServerClustersServiceGrpcAsyncIOTransport, "grpc_asyncio"),
156141
],
157142
)
158-
def test_game_server_clusters_service_client_service_account_always_use_jwt_true(
143+
def test_game_server_clusters_service_client_service_account_always_use_jwt(
159144
transport_class, transport_name
160145
):
161146
with mock.patch.object(
@@ -165,6 +150,13 @@ def test_game_server_clusters_service_client_service_account_always_use_jwt_true
165150
transport = transport_class(credentials=creds, always_use_jwt_access=True)
166151
use_jwt.assert_called_once_with(True)
167152

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+
168160

169161
@pytest.mark.parametrize(
170162
"client_class",
@@ -254,6 +246,7 @@ def test_game_server_clusters_service_client_client_options(
254246
client_cert_source_for_mtls=None,
255247
quota_project_id=None,
256248
client_info=transports.base.DEFAULT_CLIENT_INFO,
249+
always_use_jwt_access=True,
257250
)
258251

259252
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -270,6 +263,7 @@ def test_game_server_clusters_service_client_client_options(
270263
client_cert_source_for_mtls=None,
271264
quota_project_id=None,
272265
client_info=transports.base.DEFAULT_CLIENT_INFO,
266+
always_use_jwt_access=True,
273267
)
274268

275269
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -286,6 +280,7 @@ def test_game_server_clusters_service_client_client_options(
286280
client_cert_source_for_mtls=None,
287281
quota_project_id=None,
288282
client_info=transports.base.DEFAULT_CLIENT_INFO,
283+
always_use_jwt_access=True,
289284
)
290285

291286
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -314,6 +309,7 @@ def test_game_server_clusters_service_client_client_options(
314309
client_cert_source_for_mtls=None,
315310
quota_project_id="octopus",
316311
client_info=transports.base.DEFAULT_CLIENT_INFO,
312+
always_use_jwt_access=True,
317313
)
318314

319315

@@ -390,6 +386,7 @@ def test_game_server_clusters_service_client_mtls_env_auto(
390386
client_cert_source_for_mtls=expected_client_cert_source,
391387
quota_project_id=None,
392388
client_info=transports.base.DEFAULT_CLIENT_INFO,
389+
always_use_jwt_access=True,
393390
)
394391

395392
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -423,6 +420,7 @@ def test_game_server_clusters_service_client_mtls_env_auto(
423420
client_cert_source_for_mtls=expected_client_cert_source,
424421
quota_project_id=None,
425422
client_info=transports.base.DEFAULT_CLIENT_INFO,
423+
always_use_jwt_access=True,
426424
)
427425

428426
# Check the case client_cert_source and ADC client cert are not provided.
@@ -444,6 +442,7 @@ def test_game_server_clusters_service_client_mtls_env_auto(
444442
client_cert_source_for_mtls=None,
445443
quota_project_id=None,
446444
client_info=transports.base.DEFAULT_CLIENT_INFO,
445+
always_use_jwt_access=True,
447446
)
448447

449448

@@ -478,6 +477,7 @@ def test_game_server_clusters_service_client_client_options_scopes(
478477
client_cert_source_for_mtls=None,
479478
quota_project_id=None,
480479
client_info=transports.base.DEFAULT_CLIENT_INFO,
480+
always_use_jwt_access=True,
481481
)
482482

483483

@@ -512,6 +512,7 @@ def test_game_server_clusters_service_client_client_options_credentials_file(
512512
client_cert_source_for_mtls=None,
513513
quota_project_id=None,
514514
client_info=transports.base.DEFAULT_CLIENT_INFO,
515+
always_use_jwt_access=True,
515516
)
516517

517518

@@ -531,6 +532,7 @@ def test_game_server_clusters_service_client_client_options_from_dict():
531532
client_cert_source_for_mtls=None,
532533
quota_project_id=None,
533534
client_info=transports.base.DEFAULT_CLIENT_INFO,
535+
always_use_jwt_access=True,
534536
)
535537

536538

tests/unit/gapic/gaming_v1/test_game_server_configs_service.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,29 +131,14 @@ def test_game_server_configs_service_client_from_service_account_info(client_cla
131131
assert client.transport._host == "gameservices.googleapis.com:443"
132132

133133

134-
@pytest.mark.parametrize(
135-
"client_class",
136-
[GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient,],
137-
)
138-
def test_game_server_configs_service_client_service_account_always_use_jwt(
139-
client_class,
140-
):
141-
with mock.patch.object(
142-
service_account.Credentials, "with_always_use_jwt_access", create=True
143-
) as use_jwt:
144-
creds = service_account.Credentials(None, None, None)
145-
client = client_class(credentials=creds)
146-
use_jwt.assert_not_called()
147-
148-
149134
@pytest.mark.parametrize(
150135
"transport_class,transport_name",
151136
[
152137
(transports.GameServerConfigsServiceGrpcTransport, "grpc"),
153138
(transports.GameServerConfigsServiceGrpcAsyncIOTransport, "grpc_asyncio"),
154139
],
155140
)
156-
def test_game_server_configs_service_client_service_account_always_use_jwt_true(
141+
def test_game_server_configs_service_client_service_account_always_use_jwt(
157142
transport_class, transport_name
158143
):
159144
with mock.patch.object(
@@ -163,6 +148,13 @@ def test_game_server_configs_service_client_service_account_always_use_jwt_true(
163148
transport = transport_class(credentials=creds, always_use_jwt_access=True)
164149
use_jwt.assert_called_once_with(True)
165150

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

167159
@pytest.mark.parametrize(
168160
"client_class",
@@ -252,6 +244,7 @@ def test_game_server_configs_service_client_client_options(
252244
client_cert_source_for_mtls=None,
253245
quota_project_id=None,
254246
client_info=transports.base.DEFAULT_CLIENT_INFO,
247+
always_use_jwt_access=True,
255248
)
256249

257250
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -268,6 +261,7 @@ def test_game_server_configs_service_client_client_options(
268261
client_cert_source_for_mtls=None,
269262
quota_project_id=None,
270263
client_info=transports.base.DEFAULT_CLIENT_INFO,
264+
always_use_jwt_access=True,
271265
)
272266

273267
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -284,6 +278,7 @@ def test_game_server_configs_service_client_client_options(
284278
client_cert_source_for_mtls=None,
285279
quota_project_id=None,
286280
client_info=transports.base.DEFAULT_CLIENT_INFO,
281+
always_use_jwt_access=True,
287282
)
288283

289284
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -312,6 +307,7 @@ def test_game_server_configs_service_client_client_options(
312307
client_cert_source_for_mtls=None,
313308
quota_project_id="octopus",
314309
client_info=transports.base.DEFAULT_CLIENT_INFO,
310+
always_use_jwt_access=True,
315311
)
316312

317313

@@ -388,6 +384,7 @@ def test_game_server_configs_service_client_mtls_env_auto(
388384
client_cert_source_for_mtls=expected_client_cert_source,
389385
quota_project_id=None,
390386
client_info=transports.base.DEFAULT_CLIENT_INFO,
387+
always_use_jwt_access=True,
391388
)
392389

393390
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -421,6 +418,7 @@ def test_game_server_configs_service_client_mtls_env_auto(
421418
client_cert_source_for_mtls=expected_client_cert_source,
422419
quota_project_id=None,
423420
client_info=transports.base.DEFAULT_CLIENT_INFO,
421+
always_use_jwt_access=True,
424422
)
425423

426424
# Check the case client_cert_source and ADC client cert are not provided.
@@ -442,6 +440,7 @@ def test_game_server_configs_service_client_mtls_env_auto(
442440
client_cert_source_for_mtls=None,
443441
quota_project_id=None,
444442
client_info=transports.base.DEFAULT_CLIENT_INFO,
443+
always_use_jwt_access=True,
445444
)
446445

447446

@@ -476,6 +475,7 @@ def test_game_server_configs_service_client_client_options_scopes(
476475
client_cert_source_for_mtls=None,
477476
quota_project_id=None,
478477
client_info=transports.base.DEFAULT_CLIENT_INFO,
478+
always_use_jwt_access=True,
479479
)
480480

481481

@@ -510,6 +510,7 @@ def test_game_server_configs_service_client_client_options_credentials_file(
510510
client_cert_source_for_mtls=None,
511511
quota_project_id=None,
512512
client_info=transports.base.DEFAULT_CLIENT_INFO,
513+
always_use_jwt_access=True,
513514
)
514515

515516

@@ -529,6 +530,7 @@ def test_game_server_configs_service_client_client_options_from_dict():
529530
client_cert_source_for_mtls=None,
530531
quota_project_id=None,
531532
client_info=transports.base.DEFAULT_CLIENT_INFO,
533+
always_use_jwt_access=True,
532534
)
533535

534536

0 commit comments

Comments
 (0)