@@ -54,6 +54,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
54
54
55
55
import abc
56
56
import openshift as oc
57
+ from openshift import OpenShiftPythonException
57
58
58
59
59
60
class Authentication(metaclass=abc.ABCMeta):
@@ -81,26 +82,33 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
81
82
cluster when the user has an API token and the API server address.
82
83
"""
83
84
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):
89
86
"""
90
87
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
91
88
and `server`, the API server address for authenticating to an OpenShift cluster.
92
89
"""
93
90
94
91
self.token = token
95
92
self.server = server
93
+ self.skip_tls = skip_tls
96
94
97
95
def login(self):
98
96
"""
99
97
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
104
112
return response.out()
105
113
106
114
def logout(self):
@@ -311,7 +319,7 @@ <h3>Methods</h3>
311
319
</ dd >
312
320
< dt id ="codeflare_sdk.cluster.auth.TokenAuthentication "> < code class ="flex name class ">
313
321
< 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 >
315
323
</ code > </ dt >
316
324
< dd >
317
325
< 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>
328
336
cluster when the user has an API token and the API server address.
329
337
"""
330
338
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):
336
340
"""
337
341
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
338
342
and `server`, the API server address for authenticating to an OpenShift cluster.
339
343
"""
340
344
341
345
self.token = token
342
346
self.server = server
347
+ self.skip_tls = skip_tls
343
348
344
349
def login(self):
345
350
"""
346
351
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
351
366
return response.out()
352
367
353
368
def logout(self):
@@ -367,18 +382,30 @@ <h3>Methods</h3>
367
382
< span > def < span class ="ident "> login</ span > </ span > (< span > self)</ span >
368
383
</ code > </ dt >
369
384
< 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 >
371
388
< details class ="source ">
372
389
< summary >
373
390
< span > Expand source code</ span >
374
391
</ summary >
375
392
< pre > < code class ="python "> def login(self):
376
393
"""
377
394
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`.
378
397
"""
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
382
409
return response.out()</ code > </ pre >
383
410
</ details >
384
411
</ dd >
0 commit comments