Skip to content

Commit b13c0f3

Browse files
committed
Add support for specifying a cluster CA certificate to the sdk
1 parent 3b41a22 commit b13c0f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: src/codeflare_sdk/cluster/auth.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TokenAuthentication(Authentication):
4949
cluster when the user has an API token and the API server address.
5050
"""
5151

52-
def __init__(self, token: str = None, server: str = None, skip_tls: bool = False):
52+
def __init__(self, token: str = None, server: str = None, ca_cert_path: str = None, skip_tls: bool = False):
5353
"""
5454
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
5555
and `server`, the API server address for authenticating to an OpenShift cluster.
@@ -58,6 +58,7 @@ def __init__(self, token: str = None, server: str = None, skip_tls: bool = False
5858
self.token = token
5959
self.server = server
6060
self.skip_tls = skip_tls
61+
self.ca_cert_path = ca_cert_path
6162

6263
def login(self) -> str:
6364
"""
@@ -68,12 +69,14 @@ def login(self) -> str:
6869
args = [f"--token={self.token}", f"--server={self.server}"]
6970
if self.skip_tls:
7071
args.append("--insecure-skip-tls-verify")
72+
elif self.skip_tls == False:
73+
args.append(f"--certificate-authority={self.ca_cert_path}")
7174
try:
7275
response = oc.invoke("login", args)
7376
except OpenShiftPythonException as osp: # pragma: no cover
7477
error_msg = osp.result.err()
7578
if "The server uses a certificate signed by unknown authority" in error_msg:
76-
return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
79+
return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication or provide a trusted certificate using `ca_cert_path`"
7780
elif "invalid" in error_msg:
7881
raise PermissionError(error_msg)
7982
else:

0 commit comments

Comments
 (0)