T-10: Fix get_geo_batch_lookup for proper injection with GeoCache instance
Instead of returning a bound method (geo_cache.lookup_batch), now inject the GeoCache instance directly into routers and services. This provides proper runtime isolation since T-04 made GeoCache a proper object. Changes: - Remove get_geo_batch_lookup() dependency provider - Add GeoCacheDep type alias for injecting GeoCache instances - Update all routers (bans, blocklist, dashboard, jails) to use GeoCacheDep - Update ban_service, blocklist_service, jail_service to accept GeoCache - Update service protocols to match new signatures - Update docstrings to reference GeoCache methods instead of module functions All callers now call geo_cache.lookup_batch(...) directly instead of geo_batch_lookup(...), providing real dependency injection with proper testing isolation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -16,7 +16,7 @@ from app.dependencies import (
|
||||
AuthDep,
|
||||
DbDep,
|
||||
Fail2BanSocketDep,
|
||||
GeoBatchLookupDep,
|
||||
GeoCacheDep,
|
||||
HttpSessionDep,
|
||||
)
|
||||
from app.models.ban import ActiveBanListResponse, BanRequest, UnbanAllResponse, UnbanRequest
|
||||
@@ -37,7 +37,7 @@ async def get_active_bans(
|
||||
db: DbDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
http_session: HttpSessionDep,
|
||||
geo_batch_lookup: GeoBatchLookupDep,
|
||||
geo_cache: GeoCacheDep,
|
||||
) -> ActiveBanListResponse:
|
||||
"""Return every IP that is currently banned across all fail2ban jails.
|
||||
|
||||
@@ -56,7 +56,7 @@ async def get_active_bans(
|
||||
"""
|
||||
return await ban_service.get_active_bans(
|
||||
socket_path,
|
||||
geo_batch_lookup=geo_batch_lookup,
|
||||
geo_cache=geo_cache,
|
||||
http_session=http_session,
|
||||
app_db=db,
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ from app.dependencies import (
|
||||
AuthDep,
|
||||
DbDep,
|
||||
Fail2BanSocketDep,
|
||||
GeoBatchLookupDep,
|
||||
GeoCacheDep,
|
||||
HttpSessionDep,
|
||||
SchedulerDep,
|
||||
SettingsDep,
|
||||
@@ -118,7 +118,7 @@ async def run_import_now(
|
||||
db: DbDep,
|
||||
_auth: AuthDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
geo_batch_lookup: GeoBatchLookupDep,
|
||||
geo_cache: GeoCacheDep,
|
||||
) -> ImportRunResult:
|
||||
"""Download and apply all enabled blocklist sources immediately.
|
||||
|
||||
@@ -136,8 +136,8 @@ async def run_import_now(
|
||||
db,
|
||||
http_session,
|
||||
socket_path,
|
||||
geo_is_cached=geo_service.is_cached,
|
||||
geo_batch_lookup=geo_batch_lookup,
|
||||
geo_is_cached=geo_cache.is_cached,
|
||||
geo_cache=geo_cache,
|
||||
ban_ip=ban_service.ban_ip,
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from app.dependencies import (
|
||||
AuthDep,
|
||||
DbDep,
|
||||
Fail2BanSocketDep,
|
||||
GeoBatchLookupDep,
|
||||
GeoCacheDep,
|
||||
HttpSessionDep,
|
||||
ServerStatusDep,
|
||||
)
|
||||
@@ -84,7 +84,7 @@ async def get_dashboard_bans(
|
||||
db: DbDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
http_session: HttpSessionDep,
|
||||
geo_batch_lookup: GeoBatchLookupDep,
|
||||
geo_cache: GeoCacheDep,
|
||||
range: TimeRange = Query(default=_DEFAULT_RANGE, description="Time-range preset."),
|
||||
source: Literal["fail2ban", "archive"] = Query(
|
||||
default="fail2ban",
|
||||
@@ -125,7 +125,7 @@ async def get_dashboard_bans(
|
||||
page_size=page_size,
|
||||
http_session=http_session,
|
||||
app_db=db,
|
||||
geo_batch_lookup=geo_batch_lookup,
|
||||
geo_cache=geo_cache,
|
||||
origin=origin,
|
||||
)
|
||||
|
||||
@@ -140,7 +140,7 @@ async def get_bans_by_country(
|
||||
db: DbDep,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
http_session: HttpSessionDep,
|
||||
geo_batch_lookup: GeoBatchLookupDep,
|
||||
geo_cache: GeoCacheDep,
|
||||
range: TimeRange = Query(default=_DEFAULT_RANGE, description="Time-range preset."),
|
||||
source: Literal["fail2ban", "archive"] = Query(
|
||||
default="fail2ban",
|
||||
@@ -177,8 +177,8 @@ async def get_bans_by_country(
|
||||
range,
|
||||
source=source,
|
||||
http_session=http_session,
|
||||
geo_cache_lookup=geo_service.lookup_cached_only,
|
||||
geo_batch_lookup=geo_batch_lookup,
|
||||
geo_cache_lookup=geo_cache.lookup_cached_only,
|
||||
geo_cache=geo_cache,
|
||||
app_db=db,
|
||||
origin=origin,
|
||||
country_code=country_code,
|
||||
|
||||
@@ -27,7 +27,7 @@ from app.dependencies import (
|
||||
AuthDep,
|
||||
DbDep,
|
||||
Fail2BanSocketDep,
|
||||
GeoBatchLookupDep,
|
||||
GeoCacheDep,
|
||||
HttpSessionDep,
|
||||
)
|
||||
from app.exceptions import (
|
||||
@@ -427,7 +427,7 @@ async def get_jail_banned_ips(
|
||||
name: _NamePath,
|
||||
socket_path: Fail2BanSocketDep,
|
||||
http_session: HttpSessionDep,
|
||||
geo_batch_lookup: GeoBatchLookupDep,
|
||||
geo_cache: GeoCacheDep,
|
||||
page: int = 1,
|
||||
page_size: int = 25,
|
||||
search: str | None = None,
|
||||
@@ -470,7 +470,7 @@ async def get_jail_banned_ips(
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
search=search,
|
||||
geo_batch_lookup=geo_batch_lookup,
|
||||
geo_cache=geo_cache,
|
||||
http_session=http_session,
|
||||
app_db=db,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user