From 35a373021435d906e800b33beed27ac3e9ad8641 Mon Sep 17 00:00:00 2001 From: maxusmusti Date: Fri, 20 Jan 2023 10:56:30 -0500 Subject: [PATCH] Prep 0.2.1 Release --- docs/cluster/auth.html | 73 +++++++++++++++++++++++++++++------------- pyproject.toml | 6 ++-- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/docs/cluster/auth.html b/docs/cluster/auth.html index f3fc2b752..01538a024 100644 --- a/docs/cluster/auth.html +++ b/docs/cluster/auth.html @@ -54,6 +54,7 @@

Module codeflare_sdk.cluster.auth

import abc import openshift as oc +from openshift import OpenShiftPythonException class Authentication(metaclass=abc.ABCMeta): @@ -81,11 +82,7 @@

Module codeflare_sdk.cluster.auth

cluster when the user has an API token and the API server address. """ - def __init__( - self, - token: str = None, - server: str = None, - ): + def __init__(self, token: str = None, server: str = None, skip_tls: bool = False): """ Initialize a TokenAuthentication object that requires a value for `token`, the API Token and `server`, the API server address for authenticating to an OpenShift cluster. @@ -93,14 +90,25 @@

Module codeflare_sdk.cluster.auth

self.token = token self.server = server + self.skip_tls = skip_tls def login(self): """ This function is used to login to an OpenShift cluster using the user's API token and API server address. - """ - token = self.token - server = self.server - response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"]) + Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls` + to `True`. + """ + args = [f"--token={self.token}", f"--server={self.server}:6443"] + if self.skip_tls: + args.append("--insecure-skip-tls-verify") + try: + response = oc.invoke("login", args) + except OpenShiftPythonException as osp: + error_msg = osp.result.err() + if "The server uses a certificate signed by unknown authority" in error_msg: + return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication" + else: + return error_msg return response.out() def logout(self): @@ -311,7 +319,7 @@

Methods

class TokenAuthentication -(token: str = None, server: str = None) +(token: str = None, server: str = None, skip_tls: bool = False)

TokenAuthentication is a subclass of Authentication. It can be used to authenticate to an OpenShift @@ -328,11 +336,7 @@

Methods

cluster when the user has an API token and the API server address. """ - def __init__( - self, - token: str = None, - server: str = None, - ): + def __init__(self, token: str = None, server: str = None, skip_tls: bool = False): """ Initialize a TokenAuthentication object that requires a value for `token`, the API Token and `server`, the API server address for authenticating to an OpenShift cluster. @@ -340,14 +344,25 @@

Methods

self.token = token self.server = server + self.skip_tls = skip_tls def login(self): """ This function is used to login to an OpenShift cluster using the user's API token and API server address. - """ - token = self.token - server = self.server - response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"]) + Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls` + to `True`. + """ + args = [f"--token={self.token}", f"--server={self.server}:6443"] + if self.skip_tls: + args.append("--insecure-skip-tls-verify") + try: + response = oc.invoke("login", args) + except OpenShiftPythonException as osp: + error_msg = osp.result.err() + if "The server uses a certificate signed by unknown authority" in error_msg: + return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication" + else: + return error_msg return response.out() def logout(self): @@ -367,7 +382,9 @@

Methods

def login(self)
-

This function is used to login to an OpenShift cluster using the user's API token and API server address.

+

This function is used to login to an OpenShift cluster using the user's API token and API server address. +Depending on the cluster, a user can choose to login in with "–insecure-skip-tls-verify by setting skip_tls` +to True.

Expand source code @@ -375,10 +392,20 @@

Methods

def login(self):
     """
     This function is used to login to an OpenShift cluster using the user's API token and API server address.
+    Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls`
+    to `True`.
     """
-    token = self.token
-    server = self.server
-    response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"])
+    args = [f"--token={self.token}", f"--server={self.server}:6443"]
+    if self.skip_tls:
+        args.append("--insecure-skip-tls-verify")
+    try:
+        response = oc.invoke("login", args)
+    except OpenShiftPythonException as osp:
+        error_msg = osp.result.err()
+        if "The server uses a certificate signed by unknown authority" in error_msg:
+            return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
+        else:
+            return error_msg
     return response.out()
diff --git a/pyproject.toml b/pyproject.toml index edaa3c211..60d23c427 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,15 @@ [tool.poetry] name = "codeflare-sdk" -version = "0.2.0" +version = "0.2.1" description = "Python SDK for codeflare client" license = "Apache-2.0" authors = [ - "Atin Sood ", - "Abhishek Malvankar ", "Michael Clifford ", "Mustafa Eyceoz ", + "Abhishek Malvankar ", + "Atin Sood ", ] readme = 'README.md'