feat: completed tasks for grade 4

This commit is contained in:
2026-11-22 14:40:35 +03:00
parent 0b97f77d76
commit e0263ba902
42 changed files with 5257 additions and 523 deletions
+1
View File
@@ -47,6 +47,7 @@ class Settings(BaseSettings):
max_messages: int = Field(ge=1)
max_in_flight: int = Field(ge=1)
login_max_in_flight: int = Field(default=10, ge=1, le=16)
session_ttl_seconds: int = Field(default=3600, ge=1)
session_store: Literal["redis"] = "redis"
+3 -4
View File
@@ -1,6 +1,5 @@
"""Настройки очереди из .env; credentials брокера читаются отдельно из файла."""
"""Настройки очереди из .env; идентификация брокера через TLS."""
from pathlib import Path
from typing import Self
from pydantic import Field, model_validator
@@ -13,9 +12,9 @@ class JobSettings(BaseSettings):
broker_ca_file: str | None = None
broker_host: str = "broker"
broker_port: int = Field(default=5672, ge=1, le=65535)
broker_password_file: Path = Path("/run/secrets/broker_password")
broker_cert_file: str = "/run/tls/broker-client.crt"
broker_key_file: str = "/run/tls/broker-client.key"
broker_queue: str = "attachment-jobs"
broker_user: str = "messenger"
broker_vhost: str = "/"
worker_concurrency: int = Field(default=2, ge=1, le=4)
job_max_attempts: int = Field(default=5, ge=1, le=100)
+10
View File
@@ -40,3 +40,13 @@ async def acquire_request_slot(request: Request) -> AsyncIterator[None]:
yield
finally:
capacity.release()
async def acquire_login_slot(request: Request) -> AsyncIterator[None]:
capacity: RequestCapacity = request.app.state.login_capacity
if not capacity.try_acquire():
raise rate_limited()
try:
yield
finally:
capacity.release()
+4
View File
@@ -48,6 +48,10 @@ async def verify_password(password: str, password_hash: str) -> bool:
)
def password_needs_rehash(password_hash: str) -> bool:
return _hasher.check_needs_rehash(password_hash)
async def dummy_verify_password(password: str) -> None:
"""Проверка против фиктивного хеша: время ответа не выдаёт отсутствие пользователя."""
await verify_password(password, _DUMMY_HASH)