diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/pybind/mgr/dashboard/exceptions.py | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/dashboard/exceptions.py')
-rw-r--r-- | src/pybind/mgr/dashboard/exceptions.py | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/exceptions.py b/src/pybind/mgr/dashboard/exceptions.py new file mode 100644 index 000000000..96cbc5233 --- /dev/null +++ b/src/pybind/mgr/dashboard/exceptions.py @@ -0,0 +1,123 @@ +# -*- coding: utf-8 -*- + + +class ViewCacheNoDataException(Exception): + def __init__(self): + self.status = 200 + super(ViewCacheNoDataException, self).__init__('ViewCache: unable to retrieve data') + + +class DashboardException(Exception): + """ + Used for exceptions that are already handled and should end up as a user error. + Or, as a replacement for cherrypy.HTTPError(...) + + Typically, you don't inherent from DashboardException + """ + + # pylint: disable=too-many-arguments + def __init__(self, e=None, code=None, component=None, http_status_code=None, msg=None): + super(DashboardException, self).__init__(msg) + self._code = code + self.component = component + if e: + self.e = e + if http_status_code: + self.status = http_status_code + else: + self.status = 400 + + def __str__(self): + try: + return str(self.e) + except AttributeError: + return super(DashboardException, self).__str__() + + @property + def errno(self): + return self.e.errno + + @property + def code(self): + if self._code: + return str(self._code) + return str(abs(self.errno)) if self.errno is not None else 'Error' + + +class InvalidCredentialsError(DashboardException): + def __init__(self): + super().__init__(msg='Invalid credentials', + code='invalid_credentials', + component='auth') + + +# access control module exceptions +class RoleAlreadyExists(Exception): + def __init__(self, name): + super(RoleAlreadyExists, self).__init__( + "Role '{}' already exists".format(name)) + + +class RoleDoesNotExist(Exception): + def __init__(self, name): + super(RoleDoesNotExist, self).__init__( + "Role '{}' does not exist".format(name)) + + +class ScopeNotValid(Exception): + def __init__(self, name): + super(ScopeNotValid, self).__init__( + "Scope '{}' is not valid".format(name)) + + +class PermissionNotValid(Exception): + def __init__(self, name): + super(PermissionNotValid, self).__init__( + "Permission '{}' is not valid".format(name)) + + +class RoleIsAssociatedWithUser(Exception): + def __init__(self, rolename, username): + super(RoleIsAssociatedWithUser, self).__init__( + "Role '{}' is still associated with user '{}'" + .format(rolename, username)) + + +class UserAlreadyExists(Exception): + def __init__(self, name): + super(UserAlreadyExists, self).__init__( + "User '{}' already exists".format(name)) + + +class UserDoesNotExist(Exception): + def __init__(self, name): + super(UserDoesNotExist, self).__init__( + "User '{}' does not exist".format(name)) + + +class ScopeNotInRole(Exception): + def __init__(self, scopename, rolename): + super(ScopeNotInRole, self).__init__( + "There are no permissions for scope '{}' in role '{}'" + .format(scopename, rolename)) + + +class RoleNotInUser(Exception): + def __init__(self, rolename, username): + super(RoleNotInUser, self).__init__( + "Role '{}' is not associated with user '{}'" + .format(rolename, username)) + + +class PwdExpirationDateNotValid(Exception): + def __init__(self): + super(PwdExpirationDateNotValid, self).__init__( + "The password expiration date must not be in the past") + + +class GrafanaError(Exception): + pass + + +class PasswordPolicyException(Exception): + pass |