-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrors.py
More file actions
48 lines (35 loc) · 1.31 KB
/
errors.py
File metadata and controls
48 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class AuthException(Exception):
"""Base class for exceptions raised by GuardPost."""
class UnsupportedFeatureError(AuthException):
"""Exception raised for unsupported features."""
class InvalidCredentialsError(AuthException):
"""
Exception to be raised when invalid credentials are provided. The purpose of this
class is to implement rate limiting and provide protection against brute-force
attacks.
"""
def __init__(self, client_ip: str, key: str = "") -> None:
super().__init__(f"Invalid credentials received from {client_ip}.")
if not client_ip:
raise ValueError("Missing or empty client IP")
self._client_ip = client_ip
self._key = key or client_ip
@property
def client_ip(self) -> str:
return self._client_ip
@property
def key(self) -> str:
return self._key
@key.setter
def key(self, value: str):
self._key = value
class RateLimitExceededError(Exception):
"""
Exception raised when too many authentication attempts have been made,
triggering rate limiting protection against brute-force attacks.
"""
def __init__(self) -> None:
super().__init__(
"Too many authentication attempts. Access temporarily blocked due to rate "
"limiting."
)