WhintPy 1.1

https://sourceforge.net/projects/whintpy/

Module whintpy.connection

Class Authentication

Description

Manage the list of available authentification methods.

Example
 >>> # Get the list of available authentication method names
 >>> auth_methods = Authentication()
 >>> auth_methods.get_method_names()
 > ["ldap", "certificate", "token", "code"]
Example
 >>> # Instantiate an authentication method.
 >>> ldap_auth = auth_methods.get_auth_class(LdapAuthentication().method_name)("here.org")
 >>> jwt_auth = auth_methods.get_auth_class("jwt")("token_secret")

Constructor

Create the list of available authentication methods.

View Source
def __init__(self):
    """Create the list of available authentication methods.

    """
    self.__methods = dict()
    for auth in (LdapAuthentication, JwtAuthentication):
        name = auth.name()
        self.__methods[name] = auth

Public functions

get_method_names

Return the list of known authentication method names.

View Source
def get_method_names(self) -> tuple:
    """Return the list of known authentication method names."""
    return tuple(self.__methods.keys())

get_available_method_names

Return the list of known and available authentication method names.

View Source
def get_available_method_names(self) -> tuple:
    """Return the list of known and available authentication method names."""
    return tuple([m for m in self.__methods.keys() if self.__methods[m].available is True])

get_auth_class

Return the authentication class matching the given method name.

Parameters
  • name: (str) Name of an authentication method among the known ones.
Returns
  • (class) The class to be instantiated.
Raises

(KeyError) Unknown given authentication method name

View Source
def get_auth_class(self, name: str) -> object:
    """Return the authentication class matching the given method name.

        :param name: (str) Name of an authentication method among the known ones.
        :return: (class) The class to be instantiated.
        :raises: (KeyError) Unknown given authentication method name

        """
    method_name = str(name).strip()
    if method_name not in self.__methods:
        raise KeyError('{:s} is not a valid key for authentication. Must be one of: {:s}'.format(method_name, str(self.__methods.keys())))
    return self.__methods[method_name]

Overloads

__str__

View Source
def __str__(self):
    return str(tuple(self.__methods.keys()))

__repr__

View Source
def __repr__(self):
    return 'Authentication({})'.format(', '.join(['{:s}: {:s}'.format(k, self.__methods[k]) for k in self.__methods]))