Skip to content

Commit da8879a

Browse files
committed
feat: make use of ssl context for keycloack security
1 parent 671db88 commit da8879a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) Cosmo Tech corporation.
22
# Licensed under the MIT license.
33

4-
__version__ = '0.8.6'
4+
__version__ = '0.8.7'

cosmotech/coal/cosmotech_api/connection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# specifically authorized by written means by Cosmo Tech.
77
import os
88
import pathlib
9+
import ssl
910

1011
import cosmotech_api
1112

@@ -39,10 +40,12 @@ def get_api_client() -> (cosmotech_api.ApiClient, str):
3940
client_id=os.environ.get("IDP_CLIENT_ID"),
4041
realm_name=os.environ.get("IDP_TENANT_ID"),
4142
client_secret_key=os.environ.get("IDP_CLIENT_SECRET"))
42-
if (ca_cert_path := os.environ.get("IDP_CA_CERT")) and pathlib.Path(os.environ.get("IDP_CA_CERT")).is_file():
43+
if (ca_cert_path := os.environ.get("IDP_CA_CERT")) and pathlib.Path(os.environ.get("IDP_CA_CERT")).exists():
4344
LOGGER.info("Found Certificate Authority override for IDP connection, using it.")
44-
keycloack_parameters["cert"] = ca_cert_path
45-
45+
if pathlib.Path(ca_cert_path).is_file():
46+
keycloack_parameters["verify"] = ssl.create_default_context(cafile=ca_cert_path)
47+
else:
48+
keycloack_parameters["verify"] = ssl.create_default_context(capath=ca_cert_path)
4649
keycloak_openid = KeycloakOpenID(**keycloack_parameters)
4750

4851
access_token = keycloak_openid.token(grant_type="client_credentials")

0 commit comments

Comments
 (0)