21
21
from hopsworks_common .client import auth , base
22
22
23
23
24
+ try :
25
+ import jks
26
+ except ImportError :
27
+ pass
28
+
29
+
24
30
class Client (base .Client ):
25
31
HOPSWORKS_HOSTNAME_VERIFICATION = "HOPSWORKS_HOSTNAME_VERIFICATION"
26
32
DOMAIN_CA_TRUSTSTORE_PEM = "DOMAIN_CA_TRUSTSTORE_PEM"
@@ -50,7 +56,7 @@ def __init__(self, hostname_verification):
50
56
self ._hostname_verification = os .environ .get (
51
57
self .HOPSWORKS_HOSTNAME_VERIFICATION , "{}" .format (hostname_verification )
52
58
).lower () in ("true" , "1" , "y" , "yes" )
53
- self ._hopsworks_ca_trust_store_path = self ._get_ca_chain_path ()
59
+ self ._hopsworks_ca_trust_store_path = self ._materialize_ca_chain ()
54
60
55
61
self ._project_id = os .environ [self .PROJECT_ID ]
56
62
self ._project_name = self ._project_name ()
@@ -67,10 +73,23 @@ def __init__(self, hostname_verification):
67
73
68
74
credentials = self ._get_credentials (self ._project_id )
69
75
70
- self ._write_pem_file (credentials ["caChain" ], self ._get_ca_chain_path ())
71
76
self ._write_pem_file (credentials ["clientCert" ], self ._get_client_cert_path ())
72
77
self ._write_pem_file (credentials ["clientKey" ], self ._get_client_key_path ())
73
78
79
+ def _materialize_ca_chain (self ):
80
+ """Convert truststore from jks to pem and return the location"""
81
+ ca_chain_path = Path (self ._get_ca_chain_path ())
82
+ if not ca_chain_path .exists ():
83
+ keystore_pw = self ._cert_key
84
+ ks = jks .KeyStore .load (
85
+ self ._get_jks_key_store_path (), keystore_pw , try_decrypt_keys = True
86
+ )
87
+ ts = jks .KeyStore .load (
88
+ self ._get_jks_trust_store_path (), keystore_pw , try_decrypt_keys = True
89
+ )
90
+ self ._write_ca_chain (ks , ts , ca_chain_path )
91
+ return str (ca_chain_path )
92
+
74
93
def _get_hopsworks_rest_endpoint (self ):
75
94
"""Get the hopsworks REST endpoint for making requests to the REST API."""
76
95
return os .environ [self .REST_ENDPOINT ]
0 commit comments