refactor(auth): standardize session management and security
- Centralize secret retrieval using `getAdminSessionSecret` - Replace manual session parsing with `verifyRequestAdminSession` utility - Tighten API validation and improve security headers handling - Enforce environment variable security for production deployments
This commit is contained in:
1 parent
34519c07df
commit
177ed4a844
78 files changed
+6748
-3157
No files matched your search
@@ -1,72 +1,7 @@
|
||||
"""
|
||||
Structured Exception Hierarchy for the DataStack Python SDK.
|
||||
"""
|
||||
"""Compatibility re-export of canonical `datastack.exceptions`."""
|
||||
|
||||
from typing import Optional
|
||||
from . import _ensure_canonical_datastack_on_path
|
||||
|
||||
_ensure_canonical_datastack_on_path()
|
||||
|
||||
class DataStackError(Exception):
|
||||
"""Base exception for all DataStack SDK errors."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str,
|
||||
code: Optional[str] = None,
|
||||
retryable: bool = False,
|
||||
) -> None:
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
self.code = code or "DATASTACK_ERROR"
|
||||
self.retryable = retryable
|
||||
|
||||
|
||||
class DataStackConfigError(DataStackError):
|
||||
"""Raised when `config.datastack.py` or required credentials are missing or invalid."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__(message, code="CONFIG_ERROR", retryable=False)
|
||||
|
||||
|
||||
class DataStackAuthError(DataStackError):
|
||||
"""
|
||||
Raised when authentication fails (`AUTH_REQUIRED`, `AUTH_INVALID`,
|
||||
`CLIENT_REVOKED`, or `TOKEN_ROTATED`). Non-retryable until credentials are updated.
|
||||
"""
|
||||
|
||||
def __init__(self, message: str, code: str = "AUTH_ERROR") -> None:
|
||||
super().__init__(message, code=code, retryable=False)
|
||||
|
||||
|
||||
class DataStackRateLimitError(DataStackError):
|
||||
"""Raised when `RATE_LIMIT_EXCEEDED` persists after all backoff retries."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__(message, code="RATE_LIMIT_EXCEEDED", retryable=True)
|
||||
|
||||
|
||||
class DataStackPayloadTooLargeError(DataStackError):
|
||||
"""Raised when a single event exceeds the server's `maxPayloadSizeKb` limit."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__(message, code="PAYLOAD_TOO_LARGE", retryable=False)
|
||||
|
||||
|
||||
class DataStackConnectionError(DataStackError):
|
||||
"""Raised when both WebSocket and HTTP fallback are unreachable and offline spooling is disabled."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__(message, code="CONNECTION_ERROR", retryable=True)
|
||||
|
||||
|
||||
class DataStackFileError(DataStackError):
|
||||
"""Raised when a file passed to `send_file()` is missing, unsupported, or malformed."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__(message, code="FILE_ERROR", retryable=False)
|
||||
|
||||
|
||||
class DataStackOfflineSpoolError(DataStackError):
|
||||
"""Raised when the local offline disk spool directory is full or unwriteable."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__(message, code="OFFLINE_SPOOL_ERROR", retryable=False)
|
||||
from datastack.exceptions import * # noqa: E402, F401, F403
|
||||
Reference in new issue
Block a user