plugins with the definition of the methods to be implemented.
"""
-__author__ = "Eduardo Sousa <esousa@whitestack.com>, " \
- "Pedro de la Cruz Ramos <pdelacruzramos@altran.com>"
+__author__ = (
+ "Eduardo Sousa <esousa@whitestack.com>, "
+ "Pedro de la Cruz Ramos <pdelacruzramos@altran.com>"
+)
__date__ = "$27-jul-2018 23:59:59$"
from http import HTTPStatus
"""
Authentication error, because token, user password not recognized
"""
+
def __init__(self, message, http_code=HTTPStatus.UNAUTHORIZED):
super(AuthException, self).__init__(message)
self.http_code = http_code
"""
Authentication error, because not having rights to make this operation
"""
+
pass
"""
Common and base class Exception for all authconn exceptions.
"""
+
def __init__(self, message, http_code=HTTPStatus.UNAUTHORIZED):
super(AuthconnException, self).__init__(message)
self.http_code = http_code
"""
Connectivity error with Auth backend.
"""
+
def __init__(self, message, http_code=HTTPStatus.BAD_GATEWAY):
super(AuthconnConnectionException, self).__init__(message, http_code)
"""
The request is not supported by the Auth backend.
"""
+
def __init__(self, message, http_code=HTTPStatus.NOT_IMPLEMENTED):
super(AuthconnNotSupportedException, self).__init__(message, http_code)
"""
The method is not implemented by the Auth backend.
"""
+
def __init__(self, message, http_code=HTTPStatus.NOT_IMPLEMENTED):
super(AuthconnNotImplementedException, self).__init__(message, http_code)
"""
The operation executed failed.
"""
+
def __init__(self, message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR):
super(AuthconnOperationException, self).__init__(message, http_code)
"""
The operation executed failed because element not found.
"""
+
def __init__(self, message, http_code=HTTPStatus.NOT_FOUND):
super().__init__(message, http_code)
"""
The operation has conflicts.
"""
+
def __init__(self, message, http_code=HTTPStatus.CONFLICT):
super().__init__(message, http_code)
Each Auth backend connector plugin must be a subclass of
Authconn class.
"""
- def __init__(self, config, db):
+
+ def __init__(self, config, db, role_permissions):
"""
Constructor of the Authconn class.
-
- Note: each subclass
-
:param config: configuration dictionary containing all the
necessary configuration parameters.
+ :param db: internal database classs
+ :param role_permissions: read only role permission list
"""
self.config = config
+ self.role_permissions = role_permissions
def authenticate(self, credentials, token_info=None):
"""
:param filter_q: dictionary to filter user list by name (username is also admited) and/or _id
:return: returns a list of users.
"""
+ return list() # Default return value so that the method get_user passes pylint
def get_user(self, _id, fail=True):
"""
users = self.get_user_list(filt)
if not users:
if fail:
- raise AuthconnNotFoundException("User with {} not found".format(filt), http_code=HTTPStatus.NOT_FOUND)
+ raise AuthconnNotFoundException(
+ "User with {} not found".format(filt),
+ http_code=HTTPStatus.NOT_FOUND,
+ )
else:
return None
return users[0]
projs = self.get_project_list(filt)
if not projs:
if fail:
- raise AuthconnNotFoundException("project with {} not found".format(filt))
+ raise AuthconnNotFoundException(
+ "project with {} not found".format(filt)
+ )
else:
return None
return projs[0]