Task 25: extend service/repository protocol coverage and wire DI aliases

This commit is contained in:
2026-04-14 12:32:42 +02:00
parent b1fba79a2e
commit 09c764cebc
4 changed files with 554 additions and 741 deletions

View File

@@ -22,8 +22,23 @@ from app.models.auth import Session
from app.models.config import PendingRecovery
from app.models.geo import GeoBatchLookup
from app.models.server import ServerStatus
from app.repositories.protocols import SessionRepository
from app.services.protocols import AuthService, JailService
from app.repositories.protocols import (
BlocklistRepository,
Fail2BanDbRepository,
GeoCacheRepository,
ImportLogRepository,
SessionRepository,
)
from app.services.protocols import (
AuthService,
BlocklistService,
ConfigService,
GeoService,
HealthService,
HistoryService,
JailService,
ServerService,
)
from app.utils.constants import SESSION_COOKIE_NAME
from app.utils.runtime_state import RuntimeState
from app.utils.session_cache import InMemorySessionCache, NoOpSessionCache, SessionCache
@@ -239,6 +254,48 @@ async def get_jail_service() -> JailService:
return cast("JailService", jail_service)
async def get_blocklist_service() -> BlocklistService:
"""Provide the concrete blocklist service implementation."""
from app.services import blocklist_service # noqa: PLC0415
return cast("BlocklistService", blocklist_service)
async def get_config_service() -> ConfigService:
"""Provide the concrete configuration service implementation."""
from app.services import config_service # noqa: PLC0415
return cast("ConfigService", config_service)
async def get_history_service() -> HistoryService:
"""Provide the concrete history service implementation."""
from app.services import history_service # noqa: PLC0415
return cast("HistoryService", history_service)
async def get_geo_service() -> GeoService:
"""Provide the concrete geo service implementation."""
from app.services import geo_service # noqa: PLC0415
return cast("GeoService", geo_service)
async def get_health_service() -> HealthService:
"""Provide the concrete health service implementation."""
from app.services import health_service # noqa: PLC0415
return cast("HealthService", health_service)
async def get_server_service() -> ServerService:
"""Provide the concrete server service implementation."""
from app.services import server_service # noqa: PLC0415
return cast("ServerService", server_service)
async def get_session_repo() -> SessionRepository:
"""Provide the concrete session repository implementation."""
from app.repositories import session_repo # noqa: PLC0415
@@ -246,6 +303,34 @@ async def get_session_repo() -> SessionRepository:
return session_repo
async def get_blocklist_repo() -> BlocklistRepository:
"""Provide the concrete blocklist repository implementation."""
from app.repositories import blocklist_repo # noqa: PLC0415
return cast("BlocklistRepository", blocklist_repo)
async def get_import_log_repo() -> ImportLogRepository:
"""Provide the concrete import log repository implementation."""
from app.repositories import import_log_repo # noqa: PLC0415
return cast("ImportLogRepository", import_log_repo)
async def get_geo_cache_repo() -> GeoCacheRepository:
"""Provide the concrete geo cache repository implementation."""
from app.repositories import geo_cache_repo # noqa: PLC0415
return cast("GeoCacheRepository", geo_cache_repo)
async def get_fail2ban_db_repo() -> Fail2BanDbRepository:
"""Provide the concrete fail2ban DB repository implementation."""
from app.repositories import fail2ban_db_repo # noqa: PLC0415
return cast("Fail2BanDbRepository", fail2ban_db_repo)
async def get_app_state(app_context: Annotated[ApplicationContext, Depends(get_app_context)]) -> ApplicationContext:
"""Provide the application state object for the current request."""
return app_context
@@ -351,7 +436,17 @@ PendingRecoveryDep = Annotated[PendingRecovery | None, Depends(get_pending_recov
SessionCacheDep = Annotated[SessionCache, Depends(get_session_cache)]
AuthServiceDep = Annotated[AuthService, Depends(get_auth_service)]
JailServiceDep = Annotated[JailService, Depends(get_jail_service)]
BlocklistServiceDep = Annotated[BlocklistService, Depends(get_blocklist_service)]
ConfigServiceDep = Annotated[ConfigService, Depends(get_config_service)]
HistoryServiceDep = Annotated[HistoryService, Depends(get_history_service)]
GeoServiceDep = Annotated[GeoService, Depends(get_geo_service)]
HealthServiceDep = Annotated[HealthService, Depends(get_health_service)]
ServerServiceDep = Annotated[ServerService, Depends(get_server_service)]
SessionRepoDep = Annotated[SessionRepository, Depends(get_session_repo)]
AppStateDep = Annotated[AppState, Depends(get_app_state)]
BlocklistRepositoryDep = Annotated[BlocklistRepository, Depends(get_blocklist_repo)]
ImportLogRepositoryDep = Annotated[ImportLogRepository, Depends(get_import_log_repo)]
GeoCacheRepositoryDep = Annotated[GeoCacheRepository, Depends(get_geo_cache_repo)]
Fail2BanDbRepositoryDep = Annotated[Fail2BanDbRepository, Depends(get_fail2ban_db_repo)]
AppStateDep = Annotated[ApplicationContext, Depends(get_app_state)]
AppDep = Annotated[FastAPI, Depends(get_app)]
AuthDep = Annotated[Session, Depends(require_auth)]