From 1d716a26b6ea8cad060d0baacc187849041eec66 Mon Sep 17 00:00:00 2001 From: maxusmusti Date: Thu, 8 Dec 2022 19:02:48 -0500 Subject: [PATCH] Updated docs for auth --- docs/cluster/auth.html | 450 ++++++++++++++++++++++++++++++++++++++ docs/cluster/cluster.html | 8 +- docs/cluster/config.html | 14 +- docs/cluster/index.html | 6 + 4 files changed, 474 insertions(+), 4 deletions(-) create mode 100644 docs/cluster/auth.html diff --git a/docs/cluster/auth.html b/docs/cluster/auth.html new file mode 100644 index 000000000..f3fc2b752 --- /dev/null +++ b/docs/cluster/auth.html @@ -0,0 +1,450 @@ + + + + + + +codeflare_sdk.cluster.auth API documentation + + + + + + + + + + + +
+
+
+

Module codeflare_sdk.cluster.auth

+
+
+

The auth sub-module contains the definitions for the Authentication objects, which represent +the methods by which a user can authenticate to their cluster(s). The abstract class, Authentication, +contains two required methods login() and logout(). Users can use one of the existing concrete classes to +authenticate to their cluster or add their own custom concrete classes here.

+
+ +Expand source code + +
# Copyright 2022 IBM, Red Hat
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+The auth sub-module contains the definitions for the Authentication objects, which represent
+the methods by which a user can authenticate to their cluster(s). The abstract class, `Authentication`,
+contains two required methods `login()` and `logout()`. Users can use one of the existing concrete classes to
+authenticate to their cluster or add their own custom concrete classes here.  
+"""
+
+import abc
+import openshift as oc
+
+
+class Authentication(metaclass=abc.ABCMeta):
+    """
+    An abstract class that defines the necessary methods for authenticating to a remote environment.
+    Specifically, this class defines the need for a `login()` and a `logout()` function.
+    """
+
+    def login(self):
+        """
+        Method for logging in to a remote cluster.
+        """
+        pass
+
+    def logout(self):
+        """
+        Method for logging out of the remote cluster.
+        """
+        pass
+
+
+class TokenAuthentication(Authentication):
+    """
+    `TokenAuthentication` is a subclass of `Authentication`. It can be used to authenticate to an OpenShift
+    cluster when the user has an API token and the API server address.
+    """
+
+    def __init__(
+        self,
+        token: str = None,
+        server: str = None,
+    ):
+        """
+        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.
+        """
+
+        self.token = token
+        self.server = server
+
+    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"])
+        return response.out()
+
+    def logout(self):
+        """
+        This function is used to logout of an OpenShift cluster.
+        """
+        response = oc.invoke("logout")
+        return response.out()
+
+
+class PasswordUserAuthentication(Authentication):
+    """
+    `PasswordUserAuthentication` is a subclass of `Authentication`. It can be used to authenticate to an OpenShift
+    cluster when the user has a username and password.
+    """
+
+    def __init__(
+        self,
+        username: str = None,
+        password: str = None,
+    ):
+        """
+        Initialize a PasswordUserAuthentication object that requires a value for `username`
+        and `password` for authenticating to an OpenShift cluster.
+        """
+        self.username = username
+        self.password = password
+
+    def login(self):
+        """
+        This function is used to login to an OpenShift cluster using the user's `username` and `password`.
+        """
+        response = oc.login(self.username, self.password)
+        return response.out()
+
+    def logout(self):
+        """
+        This function is used to logout of an OpenShift cluster.
+        """
+        response = oc.invoke("logout")
+        return response.out()
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class Authentication +
+
+

An abstract class that defines the necessary methods for authenticating to a remote environment. +Specifically, this class defines the need for a login() and a logout() function.

+
+ +Expand source code + +
class Authentication(metaclass=abc.ABCMeta):
+    """
+    An abstract class that defines the necessary methods for authenticating to a remote environment.
+    Specifically, this class defines the need for a `login()` and a `logout()` function.
+    """
+
+    def login(self):
+        """
+        Method for logging in to a remote cluster.
+        """
+        pass
+
+    def logout(self):
+        """
+        Method for logging out of the remote cluster.
+        """
+        pass
+
+

Subclasses

+ +

Methods

+
+
+def login(self) +
+
+

Method for logging in to a remote cluster.

+
+ +Expand source code + +
def login(self):
+    """
+    Method for logging in to a remote cluster.
+    """
+    pass
+
+
+
+def logout(self) +
+
+

Method for logging out of the remote cluster.

+
+ +Expand source code + +
def logout(self):
+    """
+    Method for logging out of the remote cluster.
+    """
+    pass
+
+
+
+
+
+class PasswordUserAuthentication +(username: str = None, password: str = None) +
+
+

PasswordUserAuthentication is a subclass of Authentication. It can be used to authenticate to an OpenShift +cluster when the user has a username and password.

+

Initialize a PasswordUserAuthentication object that requires a value for username +and password for authenticating to an OpenShift cluster.

+
+ +Expand source code + +
class PasswordUserAuthentication(Authentication):
+    """
+    `PasswordUserAuthentication` is a subclass of `Authentication`. It can be used to authenticate to an OpenShift
+    cluster when the user has a username and password.
+    """
+
+    def __init__(
+        self,
+        username: str = None,
+        password: str = None,
+    ):
+        """
+        Initialize a PasswordUserAuthentication object that requires a value for `username`
+        and `password` for authenticating to an OpenShift cluster.
+        """
+        self.username = username
+        self.password = password
+
+    def login(self):
+        """
+        This function is used to login to an OpenShift cluster using the user's `username` and `password`.
+        """
+        response = oc.login(self.username, self.password)
+        return response.out()
+
+    def logout(self):
+        """
+        This function is used to logout of an OpenShift cluster.
+        """
+        response = oc.invoke("logout")
+        return response.out()
+
+

Ancestors

+ +

Methods

+
+
+def login(self) +
+
+

This function is used to login to an OpenShift cluster using the user's username and password.

+
+ +Expand source code + +
def login(self):
+    """
+    This function is used to login to an OpenShift cluster using the user's `username` and `password`.
+    """
+    response = oc.login(self.username, self.password)
+    return response.out()
+
+
+
+def logout(self) +
+
+

This function is used to logout of an OpenShift cluster.

+
+ +Expand source code + +
def logout(self):
+    """
+    This function is used to logout of an OpenShift cluster.
+    """
+    response = oc.invoke("logout")
+    return response.out()
+
+
+
+
+
+class TokenAuthentication +(token: str = None, server: str = None) +
+
+

TokenAuthentication is a subclass of Authentication. It can be used to authenticate to an OpenShift +cluster when the user has an API token and the API server address.

+

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.

+
+ +Expand source code + +
class TokenAuthentication(Authentication):
+    """
+    `TokenAuthentication` is a subclass of `Authentication`. It can be used to authenticate to an OpenShift
+    cluster when the user has an API token and the API server address.
+    """
+
+    def __init__(
+        self,
+        token: str = None,
+        server: str = None,
+    ):
+        """
+        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.
+        """
+
+        self.token = token
+        self.server = server
+
+    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"])
+        return response.out()
+
+    def logout(self):
+        """
+        This function is used to logout of an OpenShift cluster.
+        """
+        response = oc.invoke("logout")
+        return response.out()
+
+

Ancestors

+ +

Methods

+
+
+def login(self) +
+
+

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

+
+ +Expand source code + +
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"])
+    return response.out()
+
+
+
+def logout(self) +
+
+

This function is used to logout of an OpenShift cluster.

+
+ +Expand source code + +
def logout(self):
+    """
+    This function is used to logout of an OpenShift cluster.
+    """
+    response = oc.invoke("logout")
+    return response.out()
+
+
+
+
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/docs/cluster/cluster.html b/docs/cluster/cluster.html index 5e1fe6687..8231fd4fc 100644 --- a/docs/cluster/cluster.html +++ b/docs/cluster/cluster.html @@ -126,6 +126,7 @@

Module codeflare_sdk.cluster.cluster

Applies the AppWrapper yaml, pushing the resource request onto the MCAD queue. """ + self.config.auth.login() namespace = self.config.namespace with oc.project(namespace): oc.invoke("apply", ["-f", self.app_wrapper_yaml]) @@ -138,6 +139,7 @@

Module codeflare_sdk.cluster.cluster

namespace = self.config.namespace with oc.project(namespace): oc.invoke("delete", ["AppWrapper", self.app_wrapper_name]) + self.config.auth.logout() def status(self, print_to_console: bool = True): """ @@ -501,6 +503,7 @@

Classes

Applies the AppWrapper yaml, pushing the resource request onto the MCAD queue. """ + self.config.auth.login() namespace = self.config.namespace with oc.project(namespace): oc.invoke("apply", ["-f", self.app_wrapper_yaml]) @@ -513,6 +516,7 @@

Classes

namespace = self.config.namespace with oc.project(namespace): oc.invoke("delete", ["AppWrapper", self.app_wrapper_name]) + self.config.auth.logout() def status(self, print_to_console: bool = True): """ @@ -709,7 +713,8 @@

Methods

""" namespace = self.config.namespace with oc.project(namespace): - oc.invoke("delete", ["AppWrapper", self.app_wrapper_name]) + oc.invoke("delete", ["AppWrapper", self.app_wrapper_name]) + self.config.auth.logout()
@@ -819,6 +824,7 @@

Methods

Applies the AppWrapper yaml, pushing the resource request onto the MCAD queue. """ + self.config.auth.login() namespace = self.config.namespace with oc.project(namespace): oc.invoke("apply", ["-f", self.app_wrapper_yaml])
diff --git a/docs/cluster/config.html b/docs/cluster/config.html index 4ab10299d..d5b2c8dba 100644 --- a/docs/cluster/config.html +++ b/docs/cluster/config.html @@ -51,6 +51,7 @@

Module codeflare_sdk.cluster.config

""" from dataclasses import dataclass, field +from .auth import Authentication import pathlib dir = pathlib.Path(__file__).parent.parent.resolve() @@ -77,7 +78,8 @@

Module codeflare_sdk.cluster.config

template: str = f"{dir}/templates/new-template.yaml" instascale: bool = False envs: dict = field(default_factory=dict) - image: str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124" + image: str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124" + auth: Authentication = Authentication()
@@ -91,7 +93,7 @@

Classes

class ClusterConfiguration -(name: str, namespace: str = 'default', head_info: list = <factory>, machine_types: list = <factory>, min_cpus: int = 1, max_cpus: int = 1, min_worker: int = 1, max_worker: int = 1, min_memory: int = 2, max_memory: int = 2, gpu: int = 0, template: str = '/home/meyceoz/Documents/codeflare-sdk/src/codeflare_sdk/templates/new-template.yaml', instascale: bool = False, envs: dict = <factory>, image: str = 'ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124') +(name: str, namespace: str = 'default', head_info: list = <factory>, machine_types: list = <factory>, min_cpus: int = 1, max_cpus: int = 1, min_worker: int = 1, max_worker: int = 1, min_memory: int = 2, max_memory: int = 2, gpu: int = 0, template: str = '/home/meyceoz/Documents/codeflare-sdk/src/codeflare_sdk/templates/new-template.yaml', instascale: bool = False, envs: dict = <factory>, image: str = 'ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124', auth: Authentication = <codeflare_sdk.cluster.auth.Authentication object>)

This dataclass is used to specify resource requirements and other details, and @@ -120,10 +122,15 @@

Classes

template: str = f"{dir}/templates/new-template.yaml" instascale: bool = False envs: dict = field(default_factory=dict) - image: str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124" + image: str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124" + auth: Authentication = Authentication()

Class variables

+
var authAuthentication
+
+
+
var envs : dict
@@ -205,6 +212,7 @@

Index

  • ClusterConfiguration