Centralise DbDep and mark Task 11 complete
This commit is contained in:
@@ -214,6 +214,8 @@ Reference: `Docs/Refactoring.md` for full analysis of each issue.
|
|||||||
|
|
||||||
**Why this is needed:** A single definition of `DbDep` ensures that any future change to the db dependency (e.g. adding row factory configuration) is applied uniformly across all routers.
|
**Why this is needed:** A single definition of `DbDep` ensures that any future change to the db dependency (e.g. adding row factory configuration) is applied uniformly across all routers.
|
||||||
|
|
||||||
|
**Status:** Completed ✅
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Task 12 — Complete the protocol injection layer or remove it
|
### Task 12 — Complete the protocol injection layer or remove it
|
||||||
|
|||||||
@@ -22,19 +22,16 @@ registered *before* the ``/{id}`` routes so FastAPI resolves them correctly.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Annotated
|
from fastapi import APIRouter, HTTPException, Query, status
|
||||||
|
|
||||||
import aiosqlite
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|
||||||
|
|
||||||
from app.dependencies import (
|
from app.dependencies import (
|
||||||
AuthDep,
|
AuthDep,
|
||||||
|
DbDep,
|
||||||
Fail2BanSocketDep,
|
Fail2BanSocketDep,
|
||||||
GeoBatchLookupDep,
|
GeoBatchLookupDep,
|
||||||
HttpSessionDep,
|
HttpSessionDep,
|
||||||
SchedulerDep,
|
SchedulerDep,
|
||||||
SettingsDep,
|
SettingsDep,
|
||||||
get_db,
|
|
||||||
)
|
)
|
||||||
from app.models.blocklist import (
|
from app.models.blocklist import (
|
||||||
BlocklistListResponse,
|
BlocklistListResponse,
|
||||||
@@ -52,8 +49,6 @@ from app.tasks.blocklist_import import run_import_with_resources
|
|||||||
|
|
||||||
router: APIRouter = APIRouter(prefix="/api/blocklists", tags=["Blocklists"])
|
router: APIRouter = APIRouter(prefix="/api/blocklists", tags=["Blocklists"])
|
||||||
|
|
||||||
DbDep = Annotated[aiosqlite.Connection, Depends(get_db)]
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Source list + create
|
# Source list + create
|
||||||
|
|||||||
@@ -13,18 +13,17 @@ from typing import TYPE_CHECKING, Annotated
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from app.services.jail_service import IpLookupResult
|
from app.services.jail_service import IpLookupResult
|
||||||
|
|
||||||
import aiosqlite
|
from fastapi import APIRouter, HTTPException, Path, status
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Path, status
|
|
||||||
|
|
||||||
from app.dependencies import (
|
from app.dependencies import (
|
||||||
AuthDep,
|
AuthDep,
|
||||||
|
DbDep,
|
||||||
Fail2BanSocketDep,
|
Fail2BanSocketDep,
|
||||||
HttpSessionDep,
|
HttpSessionDep,
|
||||||
get_db,
|
|
||||||
)
|
)
|
||||||
|
from app.exceptions import Fail2BanConnectionError
|
||||||
from app.models.geo import GeoCacheStatsResponse, GeoReResolveResponse, IpLookupResponse
|
from app.models.geo import GeoCacheStatsResponse, GeoReResolveResponse, IpLookupResponse
|
||||||
from app.services import geo_service, jail_service
|
from app.services import geo_service, jail_service
|
||||||
from app.exceptions import Fail2BanConnectionError
|
|
||||||
|
|
||||||
router: APIRouter = APIRouter(prefix="/api/geo", tags=["Geo"])
|
router: APIRouter = APIRouter(prefix="/api/geo", tags=["Geo"])
|
||||||
|
|
||||||
@@ -99,7 +98,7 @@ async def lookup_ip(
|
|||||||
)
|
)
|
||||||
async def geo_stats(
|
async def geo_stats(
|
||||||
_auth: AuthDep,
|
_auth: AuthDep,
|
||||||
db: Annotated[aiosqlite.Connection, Depends(get_db)],
|
db: DbDep,
|
||||||
) -> GeoCacheStatsResponse:
|
) -> GeoCacheStatsResponse:
|
||||||
"""Return diagnostic counters for the geo cache subsystem.
|
"""Return diagnostic counters for the geo cache subsystem.
|
||||||
|
|
||||||
@@ -123,7 +122,7 @@ async def geo_stats(
|
|||||||
)
|
)
|
||||||
async def re_resolve_geo(
|
async def re_resolve_geo(
|
||||||
_auth: AuthDep,
|
_auth: AuthDep,
|
||||||
db: Annotated[aiosqlite.Connection, Depends(get_db)],
|
db: DbDep,
|
||||||
http_session: HttpSessionDep,
|
http_session: HttpSessionDep,
|
||||||
) -> GeoReResolveResponse:
|
) -> GeoReResolveResponse:
|
||||||
"""Retry geo resolution for every IP in ``geo_cache`` with a null country.
|
"""Retry geo resolution for every IP in ``geo_cache`` with a null country.
|
||||||
|
|||||||
Reference in New Issue
Block a user