File tree 1 file changed +17
-9
lines changed
src/codeflare_sdk/cluster
1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change 21
21
22
22
import abc
23
23
import openshift as oc
24
+ from openshift import OpenShiftPythonException
24
25
25
26
26
27
class Authentication (metaclass = abc .ABCMeta ):
@@ -48,26 +49,33 @@ class TokenAuthentication(Authentication):
48
49
cluster when the user has an API token and the API server address.
49
50
"""
50
51
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 ):
56
53
"""
57
54
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
58
55
and `server`, the API server address for authenticating to an OpenShift cluster.
59
56
"""
60
57
61
58
self .token = token
62
59
self .server = server
60
+ self .skip_tls = skip_tls
63
61
64
62
def login (self ):
65
63
"""
66
64
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
71
79
return response .out ()
72
80
73
81
def logout (self ):
You can’t perform that action at this time.
0 commit comments