Debian Codegraph @

src/globus_sdk/token_storage/validating_token_storage/errors.py

raw
1 from __future__ import annotations
2
3 import uuid
4 from datetime import datetime
5
6 from globus_sdk import GlobusError, Scope
7
8
9 class TokenValidationError(GlobusError):
10 """The class of errors raised when a token fails validation."""
11
12
13 class IdentityValidationError(TokenValidationError):
14 """
15 The class of errors raised when a token response's identity is indeterminate or
16 incorrect.
17 """
18
19
20 class MissingIdentityError(IdentityValidationError, LookupError):
21 """No identity info contained in a token response."""
22
23
24 class IdentityMismatchError(IdentityValidationError, ValueError):
25 """The identity in a token response did not match the expected identity."""
26
27 def __init__(
28 self, message: str, stored_id: uuid.UUID | str, new_id: uuid.UUID | str
29 ) -> None:
30 super().__init__(message)
31 self.stored_id = stored_id
32 self.new_id = new_id
33
34
35 class MissingTokenError(TokenValidationError, LookupError):
36 """No token stored for a given resource server."""
37
38 def __init__(self, message: str, resource_server: str) -> None:
39 super().__init__(message)
40 self.resource_server = resource_server
41
42
43 class ExpiredTokenError(TokenValidationError, ValueError):
44 """The token stored for a given resource server has expired."""
45
46 def __init__(self, expires_at_seconds: int) -> None:
47 expiration = datetime.fromtimestamp(expires_at_seconds)
48 super().__init__(f"Token expired at {expiration.isoformat()}")
49 self.expiration = expiration
50
51
52 class UnmetScopeRequirementsError(TokenValidationError, ValueError):
53 """The token stored for a given resource server is missing required scopes."""
54
55 def __init__(
56 self, message: str, scope_requirements: dict[str, list[Scope]]
57 ) -> None:
58 super().__init__(message)
59 # The full set of scope requirements which were evaluated.
60 # Notably this is not exclusively the unmet scope requirements.
61 self.scope_requirements = scope_requirements