Skip to content

Commit 0f3dcc4

Browse files
update auth to allow for skip_tls (#50)
1 parent 8feb136 commit 0f3dcc4

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/codeflare_sdk/cluster/auth.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import abc
2323
import openshift as oc
24+
from openshift import OpenShiftPythonException
2425

2526

2627
class Authentication(metaclass=abc.ABCMeta):
@@ -48,26 +49,33 @@ class TokenAuthentication(Authentication):
4849
cluster when the user has an API token and the API server address.
4950
"""
5051

51-
def __init__(
52-
self,
53-
token: str = None,
54-
server: str = None,
55-
):
52+
def __init__(self, token: str = None, server: str = None, skip_tls: bool = False):
5653
"""
5754
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
5855
and `server`, the API server address for authenticating to an OpenShift cluster.
5956
"""
6057

6158
self.token = token
6259
self.server = server
60+
self.skip_tls = skip_tls
6361

6462
def login(self):
6563
"""
6664
This function is used to login to an OpenShift cluster using the user's API token and API server address.
67-
"""
68-
token = self.token
69-
server = self.server
70-
response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"])
65+
Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls`
66+
to `True`.
67+
"""
68+
args = [f"--token={self.token}", f"--server={self.server}:6443"]
69+
if self.skip_tls:
70+
args.append("--insecure-skip-tls-verify")
71+
try:
72+
response = oc.invoke("login", args)
73+
except OpenShiftPythonException as osp:
74+
error_msg = osp.result.err()
75+
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"
77+
else:
78+
return error_msg
7179
return response.out()
7280

7381
def logout(self):

0 commit comments

Comments
 (0)