Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files. Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
from datetime import datetime
|
|
from typing import Protocol, runtime_checkable
|
|
from uuid import UUID
|
|
|
|
from messenger.identity.domain.models import Session, User
|
|
from messenger.shared.application.ports import UnitOfWork
|
|
|
|
|
|
@runtime_checkable
|
|
class UserRepository(Protocol):
|
|
async def add(self, user: User) -> None: ...
|
|
|
|
|
|
@runtime_checkable
|
|
class SessionRepository(Protocol):
|
|
async def add(self, session: Session) -> None: ...
|
|
|
|
async def remove(self, token_hash: bytes) -> None: ...
|
|
|
|
|
|
@runtime_checkable
|
|
class IdentityUnitOfWork(UnitOfWork, Protocol):
|
|
@property
|
|
def users(self) -> UserRepository: ...
|
|
|
|
@property
|
|
def sessions(self) -> SessionRepository: ...
|
|
|
|
|
|
@runtime_checkable
|
|
class UserDirectory(Protocol):
|
|
async def find(self, user_id: UUID) -> User | None: ...
|
|
|
|
async def find_by_username(self, username: str) -> User | None: ...
|
|
|
|
|
|
@runtime_checkable
|
|
class SessionDirectory(Protocol):
|
|
async def find(self, token_hash: bytes, now: datetime) -> Session | None: ...
|
|
|
|
|
|
@runtime_checkable
|
|
class SessionRevocations(Protocol):
|
|
async def revoke(self, session: Session) -> None: ...
|
|
|
|
async def restore(self, session: Session) -> None: ...
|
|
|
|
|
|
@runtime_checkable
|
|
class PasswordHasher(Protocol):
|
|
async def hash(self, password: str) -> str: ...
|
|
|
|
async def verify(self, password_hash: str | None, password: str) -> bool: ...
|