Forward the lab 4 foundation and migrate the lab 5 pipeline to SQLAlchemy

This commit is contained in:
Artyom
2026-11-06 09:12:25 +03:00
parent ae9f60fe1f
commit 1217da5f5e
134 changed files with 8243 additions and 1409 deletions
+8 -3
View File
@@ -17,6 +17,7 @@ from messenger.identity.application.ports import (
IdentityUnitOfWork,
PasswordHasher,
SessionDirectory,
SessionRevocations,
UserDirectory,
)
from messenger.identity.application.queries import Authenticate, GetCurrentUser, VerifyCredentials
@@ -27,7 +28,7 @@ from messenger.identity.infrastructure.postgres import (
PostgresSessionDirectory,
PostgresUserDirectory,
)
from messenger.identity.infrastructure.valkey import CachedSessionDirectory
from messenger.identity.infrastructure.valkey import CachedSessionDirectory, NoRevocations
from messenger.shared.application.commands import Command
from messenger.shared.application.messagebus import CommandHandler
from messenger.shared.application.ports import Clock, EventPublisher, IdGenerator, Logger
@@ -76,6 +77,10 @@ class IdentityProvider(Provider):
finally:
await client.aclose()
@provide(scope=Scope.APP)
def revocations(self, sessions: SessionDirectory) -> SessionRevocations:
return sessions if isinstance(sessions, CachedSessionDirectory) else NoRevocations()
@provide(scope=Scope.APP)
def verify(self, users: UserDirectory, hasher: PasswordHasher) -> VerifyCredentials:
return VerifyCredentials(users, hasher)
@@ -100,13 +105,13 @@ class IdentityProvider(Provider):
clock: Clock,
ids: IdGenerator,
hasher: PasswordHasher,
sessions: SessionDirectory,
revocations: SessionRevocations,
settings: IdentitySettings,
) -> IdentityCommandBus:
ttl = timedelta(seconds=settings.session_ttl_seconds)
handlers: dict[type[Command], CommandHandler] = {
RegisterUser: RegisterUserHandler(uow, clock, ids, hasher),
OpenSession: OpenSessionHandler(uow, clock, ttl),
CloseSession: CloseSessionHandler(uow, sessions),
CloseSession: CloseSessionHandler(uow, revocations),
}
return IdentityCommandBus(handlers, uow, publisher)