@@ -49,7 +49,7 @@ class TokenAuthentication(Authentication):
49
49
cluster when the user has an API token and the API server address.
50
50
"""
51
51
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 ):
53
53
"""
54
54
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
55
55
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
58
58
self .token = token
59
59
self .server = server
60
60
self .skip_tls = skip_tls
61
+ self .ca_cert_path = ca_cert_path
61
62
62
63
def login (self ) -> str :
63
64
"""
@@ -68,12 +69,14 @@ def login(self) -> str:
68
69
args = [f"--token={ self .token } " , f"--server={ self .server } " ]
69
70
if self .skip_tls :
70
71
args .append ("--insecure-skip-tls-verify" )
72
+ elif self .skip_tls == False :
73
+ args .append (f"--certificate-authority={ self .ca_cert_path } " )
71
74
try :
72
75
response = oc .invoke ("login" , args )
73
76
except OpenShiftPythonException as osp : # pragma: no cover
74
77
error_msg = osp .result .err ()
75
78
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` "
77
80
elif "invalid" in error_msg :
78
81
raise PermissionError (error_msg )
79
82
else :
0 commit comments