]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | # -*- coding: utf-8 -*- |
11fdf7f2 TL |
2 | |
3 | ||
4 | class ViewCacheNoDataException(Exception): | |
5 | def __init__(self): | |
6 | self.status = 200 | |
7 | super(ViewCacheNoDataException, self).__init__('ViewCache: unable to retrieve data') | |
8 | ||
9 | ||
10 | class DashboardException(Exception): | |
11 | """ | |
12 | Used for exceptions that are already handled and should end up as a user error. | |
13 | Or, as a replacement for cherrypy.HTTPError(...) | |
14 | ||
15 | Typically, you don't inherent from DashboardException | |
16 | """ | |
17 | ||
18 | # pylint: disable=too-many-arguments | |
19 | def __init__(self, e=None, code=None, component=None, http_status_code=None, msg=None): | |
20 | super(DashboardException, self).__init__(msg) | |
21 | self._code = code | |
22 | self.component = component | |
23 | if e: | |
24 | self.e = e | |
25 | if http_status_code: | |
26 | self.status = http_status_code | |
27 | else: | |
28 | self.status = 400 | |
29 | ||
30 | def __str__(self): | |
31 | try: | |
32 | return str(self.e) | |
33 | except AttributeError: | |
34 | return super(DashboardException, self).__str__() | |
35 | ||
36 | @property | |
37 | def errno(self): | |
38 | return self.e.errno | |
39 | ||
40 | @property | |
41 | def code(self): | |
42 | if self._code: | |
43 | return str(self._code) | |
9f95a23c | 44 | return str(abs(self.errno)) if self.errno is not None else 'Error' |
11fdf7f2 TL |
45 | |
46 | ||
adb31ebb TL |
47 | class InvalidCredentialsError(DashboardException): |
48 | def __init__(self): | |
49 | super().__init__(msg='Invalid credentials', | |
50 | code='invalid_credentials', | |
51 | component='auth') | |
52 | ||
53 | ||
11fdf7f2 TL |
54 | # access control module exceptions |
55 | class RoleAlreadyExists(Exception): | |
56 | def __init__(self, name): | |
57 | super(RoleAlreadyExists, self).__init__( | |
58 | "Role '{}' already exists".format(name)) | |
59 | ||
60 | ||
61 | class RoleDoesNotExist(Exception): | |
62 | def __init__(self, name): | |
63 | super(RoleDoesNotExist, self).__init__( | |
64 | "Role '{}' does not exist".format(name)) | |
65 | ||
66 | ||
67 | class ScopeNotValid(Exception): | |
68 | def __init__(self, name): | |
69 | super(ScopeNotValid, self).__init__( | |
70 | "Scope '{}' is not valid".format(name)) | |
71 | ||
72 | ||
73 | class PermissionNotValid(Exception): | |
74 | def __init__(self, name): | |
75 | super(PermissionNotValid, self).__init__( | |
76 | "Permission '{}' is not valid".format(name)) | |
77 | ||
78 | ||
79 | class RoleIsAssociatedWithUser(Exception): | |
80 | def __init__(self, rolename, username): | |
81 | super(RoleIsAssociatedWithUser, self).__init__( | |
82 | "Role '{}' is still associated with user '{}'" | |
83 | .format(rolename, username)) | |
84 | ||
85 | ||
86 | class UserAlreadyExists(Exception): | |
87 | def __init__(self, name): | |
88 | super(UserAlreadyExists, self).__init__( | |
89 | "User '{}' already exists".format(name)) | |
90 | ||
91 | ||
92 | class UserDoesNotExist(Exception): | |
93 | def __init__(self, name): | |
94 | super(UserDoesNotExist, self).__init__( | |
95 | "User '{}' does not exist".format(name)) | |
96 | ||
97 | ||
98 | class ScopeNotInRole(Exception): | |
99 | def __init__(self, scopename, rolename): | |
100 | super(ScopeNotInRole, self).__init__( | |
101 | "There are no permissions for scope '{}' in role '{}'" | |
102 | .format(scopename, rolename)) | |
103 | ||
104 | ||
105 | class RoleNotInUser(Exception): | |
106 | def __init__(self, rolename, username): | |
107 | super(RoleNotInUser, self).__init__( | |
108 | "Role '{}' is not associated with user '{}'" | |
109 | .format(rolename, username)) | |
81eedcae TL |
110 | |
111 | ||
9f95a23c TL |
112 | class PwdExpirationDateNotValid(Exception): |
113 | def __init__(self): | |
114 | super(PwdExpirationDateNotValid, self).__init__( | |
115 | "The password expiration date must not be in the past") | |
116 | ||
117 | ||
81eedcae TL |
118 | class GrafanaError(Exception): |
119 | pass | |
9f95a23c TL |
120 | |
121 | ||
122 | class PasswordPolicyException(Exception): | |
123 | pass |