Skip to content

Commit

Permalink
init arg should take priority over env var
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin <[email protected]>
  • Loading branch information
KPostOffice committed May 21, 2024
1 parent 14e732c commit f0a09a7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/codeflare_sdk/cluster/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
global config_path
config_path = None

WORKBENCH_CA_CERT_PATH = "/etc/pki/tls/custom-certs/ca-bundle.crt"


class Authentication(metaclass=abc.ABCMeta):
"""
Expand Down Expand Up @@ -81,7 +83,7 @@ def __init__(
token: str,
server: str,
skip_tls: bool = False,
ca_cert_path: str = "/etc/pki/tls/custom-certs/ca-bundle.crt",
ca_cert_path: str = None,
):
"""
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
Expand All @@ -91,7 +93,17 @@ def __init__(
self.token = token
self.server = server
self.skip_tls = skip_tls
self.ca_cert_path = ca_cert_path
self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)

def _gen_ca_cert_path(self, ca_cert_path: str):
if ca_cert_path is not None:
return ca_cert_path
elif "CF_SDK_CA_CERT_PATH" in os.environ:
return os.environ.get("CF_SDK_CA_CERT_PATH")
elif os.path.exists(WORKBENCH_CA_CERT_PATH):
return WORKBENCH_CA_CERT_PATH
else:
return None

def login(self) -> str:
"""
Expand All @@ -106,12 +118,8 @@ def login(self) -> str:
configuration.api_key_prefix["authorization"] = "Bearer"
configuration.host = self.server
configuration.api_key["authorization"] = self.token
ca_path_env = os.environ.get("CF_SDK_CA_CERT_PATH", self.ca_cert_path)

if self.skip_tls == False:
if ca_path_env != self.ca_cert_path:
self.ca_cert_path = ca_path_env

if self.ca_cert_path == None:
configuration.ssl_ca_cert = None
elif os.path.isfile(self.ca_cert_path):
Expand Down

0 comments on commit f0a09a7

Please sign in to comment.