@@ -54,6 +54,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
5454
5555import abc
5656import openshift as oc
57+ from openshift import OpenShiftPythonException
5758
5859
5960class Authentication(metaclass=abc.ABCMeta):
@@ -81,26 +82,33 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
8182 cluster when the user has an API token and the API server address.
8283 """
8384
84- def __init__(
85- self,
86- token: str = None,
87- server: str = None,
88- ):
85+ def __init__(self, token: str = None, server: str = None, skip_tls: bool = False):
8986 """
9087 Initialize a TokenAuthentication object that requires a value for `token`, the API Token
9188 and `server`, the API server address for authenticating to an OpenShift cluster.
9289 """
9390
9491 self.token = token
9592 self.server = server
93+ self.skip_tls = skip_tls
9694
9795 def login(self):
9896 """
9997 This function is used to login to an OpenShift cluster using the user's API token and API server address.
100- """
101- token = self.token
102- server = self.server
103- response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"])
98+ Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls`
99+ to `True`.
100+ """
101+ args = [f"--token={self.token}", f"--server={self.server}:6443"]
102+ if self.skip_tls:
103+ args.append("--insecure-skip-tls-verify")
104+ try:
105+ response = oc.invoke("login", args)
106+ except OpenShiftPythonException as osp:
107+ error_msg = osp.result.err()
108+ if "The server uses a certificate signed by unknown authority" in error_msg:
109+ return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
110+ else:
111+ return error_msg
104112 return response.out()
105113
106114 def logout(self):
@@ -311,7 +319,7 @@ <h3>Methods</h3>
311319</ dd >
312320< dt id ="codeflare_sdk.cluster.auth.TokenAuthentication "> < code class ="flex name class ">
313321< span > class < span class ="ident "> TokenAuthentication</ span > </ span >
314- < span > (</ span > < span > token: str = None, server: str = None)</ span >
322+ < span > (</ span > < span > token: str = None, server: str = None, skip_tls: bool = False )</ span >
315323</ code > </ dt >
316324< dd >
317325< div class ="desc "> < p > < code > < a title ="codeflare_sdk.cluster.auth.TokenAuthentication " href ="#codeflare_sdk.cluster.auth.TokenAuthentication "> TokenAuthentication</ a > </ code > is a subclass of < code > < a title ="codeflare_sdk.cluster.auth.Authentication " href ="#codeflare_sdk.cluster.auth.Authentication "> Authentication</ a > </ code > . It can be used to authenticate to an OpenShift
@@ -328,26 +336,33 @@ <h3>Methods</h3>
328336 cluster when the user has an API token and the API server address.
329337 """
330338
331- def __init__(
332- self,
333- token: str = None,
334- server: str = None,
335- ):
339+ def __init__(self, token: str = None, server: str = None, skip_tls: bool = False):
336340 """
337341 Initialize a TokenAuthentication object that requires a value for `token`, the API Token
338342 and `server`, the API server address for authenticating to an OpenShift cluster.
339343 """
340344
341345 self.token = token
342346 self.server = server
347+ self.skip_tls = skip_tls
343348
344349 def login(self):
345350 """
346351 This function is used to login to an OpenShift cluster using the user's API token and API server address.
347- """
348- token = self.token
349- server = self.server
350- response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"])
352+ Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls`
353+ to `True`.
354+ """
355+ args = [f"--token={self.token}", f"--server={self.server}:6443"]
356+ if self.skip_tls:
357+ args.append("--insecure-skip-tls-verify")
358+ try:
359+ response = oc.invoke("login", args)
360+ except OpenShiftPythonException as osp:
361+ error_msg = osp.result.err()
362+ if "The server uses a certificate signed by unknown authority" in error_msg:
363+ return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
364+ else:
365+ return error_msg
351366 return response.out()
352367
353368 def logout(self):
@@ -367,18 +382,30 @@ <h3>Methods</h3>
367382< span > def < span class ="ident "> login</ span > </ span > (< span > self)</ span >
368383</ code > </ dt >
369384< dd >
370- < div class ="desc "> < p > This function is used to login to an OpenShift cluster using the user's API token and API server address.</ p > </ div >
385+ < div class ="desc "> < p > This function is used to login to an OpenShift cluster using the user's API token and API server address.
386+ Depending on the cluster, a user can choose to login in with "–insecure-skip-tls-verify< code > by setting </ code > skip_tls`
387+ to < code > True</ code > .</ p > </ div >
371388< details class ="source ">
372389< summary >
373390< span > Expand source code</ span >
374391</ summary >
375392< pre > < code class ="python "> def login(self):
376393 """
377394 This function is used to login to an OpenShift cluster using the user's API token and API server address.
395+ Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls`
396+ to `True`.
378397 """
379- token = self.token
380- server = self.server
381- response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"])
398+ args = [f"--token={self.token}", f"--server={self.server}:6443"]
399+ if self.skip_tls:
400+ args.append("--insecure-skip-tls-verify")
401+ try:
402+ response = oc.invoke("login", args)
403+ except OpenShiftPythonException as osp:
404+ error_msg = osp.result.err()
405+ if "The server uses a certificate signed by unknown authority" in error_msg:
406+ return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
407+ else:
408+ return error_msg
382409 return response.out()</ code > </ pre >
383410</ details >
384411</ dd >
0 commit comments