Skip to content

Commit f0a09a7

Browse files
committed
init arg should take priority over env var
Signed-off-by: Kevin <[email protected]>
1 parent 14e732c commit f0a09a7

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/codeflare_sdk/cluster/auth.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
global config_path
3333
config_path = None
3434

35+
WORKBENCH_CA_CERT_PATH = "/etc/pki/tls/custom-certs/ca-bundle.crt"
36+
3537

3638
class Authentication(metaclass=abc.ABCMeta):
3739
"""
@@ -81,7 +83,7 @@ def __init__(
8183
token: str,
8284
server: str,
8385
skip_tls: bool = False,
84-
ca_cert_path: str = "/etc/pki/tls/custom-certs/ca-bundle.crt",
86+
ca_cert_path: str = None,
8587
):
8688
"""
8789
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
@@ -91,7 +93,17 @@ def __init__(
9193
self.token = token
9294
self.server = server
9395
self.skip_tls = skip_tls
94-
self.ca_cert_path = ca_cert_path
96+
self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)
97+
98+
def _gen_ca_cert_path(self, ca_cert_path: str):
99+
if ca_cert_path is not None:
100+
return ca_cert_path
101+
elif "CF_SDK_CA_CERT_PATH" in os.environ:
102+
return os.environ.get("CF_SDK_CA_CERT_PATH")
103+
elif os.path.exists(WORKBENCH_CA_CERT_PATH):
104+
return WORKBENCH_CA_CERT_PATH
105+
else:
106+
return None
95107

96108
def login(self) -> str:
97109
"""
@@ -106,12 +118,8 @@ def login(self) -> str:
106118
configuration.api_key_prefix["authorization"] = "Bearer"
107119
configuration.host = self.server
108120
configuration.api_key["authorization"] = self.token
109-
ca_path_env = os.environ.get("CF_SDK_CA_CERT_PATH", self.ca_cert_path)
110121

111122
if self.skip_tls == False:
112-
if ca_path_env != self.ca_cert_path:
113-
self.ca_cert_path = ca_path_env
114-
115123
if self.ca_cert_path == None:
116124
configuration.ssl_ca_cert = None
117125
elif os.path.isfile(self.ca_cert_path):

0 commit comments

Comments
 (0)