forked from mtusi2026/mtusi2026lab2
feat: PostgreSQL, Bearer-сессии (Valkey/PostgreSQL), Argon2id, миграции, compose
- схема и миграции (migrations/0001_init.sql, python -m messenger.migrate); - регистрация с паролем (Argon2id), вход по Basic, opaque Bearer, logout, expiry; - сессии: SESSION_STORE=valkey (AOF, appendfsync always) или postgres; - пул соединений, statement/lock timeout и клиентский дедлайн: отказ БД = 503; - keyset-пагинация по индексу (chat_id, created_at, id), два запроса без OR; - compose.yaml с закреплёнными образами, secrets, restart.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
893beaa79a
commit
01524165dd
+18
-1
@@ -1,6 +1,9 @@
|
||||
"""Domain errors mapped 1:1 to the contract error codes (contracts/README.md)."""
|
||||
from __future__ import annotations
|
||||
|
||||
BEARER_CHALLENGE = 'Bearer realm="messenger"'
|
||||
BASIC_CHALLENGE = 'Basic realm="messenger", charset="UTF-8"'
|
||||
|
||||
|
||||
class ApiError(Exception):
|
||||
status = 500
|
||||
@@ -11,6 +14,10 @@ class ApiError(Exception):
|
||||
self.message = message or self.default_message
|
||||
super().__init__(self.message)
|
||||
|
||||
@property
|
||||
def headers(self) -> dict[str, str]:
|
||||
return {}
|
||||
|
||||
|
||||
class InvalidRequest(ApiError):
|
||||
status = 400
|
||||
@@ -19,9 +26,19 @@ class InvalidRequest(ApiError):
|
||||
|
||||
|
||||
class Unauthorized(ApiError):
|
||||
"""401 with the challenge of the scheme the endpoint expects (RFC 7235)."""
|
||||
|
||||
status = 401
|
||||
code = "unauthorized"
|
||||
default_message = "Требуется X-User-Id существующего пользователя"
|
||||
default_message = "Требуется действительная сессия"
|
||||
|
||||
def __init__(self, message: str | None = None, challenge: str = BEARER_CHALLENGE):
|
||||
super().__init__(message)
|
||||
self.challenge = challenge
|
||||
|
||||
@property
|
||||
def headers(self) -> dict[str, str]:
|
||||
return {"WWW-Authenticate": self.challenge}
|
||||
|
||||
|
||||
class NotFound(ApiError):
|
||||
|
||||
Reference in New Issue
Block a user