106 lines
2.6 KiB
Python
106 lines
2.6 KiB
Python
"""Service interface protocols for dependency injection.
|
|
|
|
These structural protocols define the public contract that routers and higher
|
|
layers depend on, without binding them to concrete module implementations.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Protocol
|
|
|
|
import aiosqlite
|
|
|
|
from app.models.auth import Session
|
|
from app.models.ban import JailBannedIpsResponse
|
|
from app.models.jail import JailDetailResponse, JailListResponse
|
|
|
|
|
|
class AuthService(Protocol):
|
|
"""Protocol for authentication service operations."""
|
|
|
|
async def login(
|
|
self,
|
|
db: aiosqlite.Connection,
|
|
password: str,
|
|
session_duration_minutes: int,
|
|
session_repo: object | None = None,
|
|
) -> Session:
|
|
...
|
|
|
|
async def validate_session(
|
|
self,
|
|
db: aiosqlite.Connection,
|
|
token: str,
|
|
session_secret: str | None = None,
|
|
session_repo: object | None = None,
|
|
) -> Session:
|
|
...
|
|
|
|
async def logout(
|
|
self,
|
|
db: aiosqlite.Connection,
|
|
token: str,
|
|
session_secret: str | None = None,
|
|
session_repo: object | None = None,
|
|
) -> str | None:
|
|
...
|
|
|
|
|
|
class JailService(Protocol):
|
|
"""Protocol for jail management service operations."""
|
|
|
|
async def list_jails(self, socket_path: str) -> JailListResponse:
|
|
...
|
|
|
|
async def get_jail(self, socket_path: str, name: str) -> JailDetailResponse:
|
|
...
|
|
|
|
async def reload_all(self, socket_path: str) -> None:
|
|
...
|
|
|
|
async def start_jail(self, socket_path: str, name: str) -> None:
|
|
...
|
|
|
|
async def stop_jail(self, socket_path: str, name: str) -> None:
|
|
...
|
|
|
|
async def set_idle(self, socket_path: str, name: str, *, on: bool) -> None:
|
|
...
|
|
|
|
async def reload_jail(self, socket_path: str, name: str) -> None:
|
|
...
|
|
|
|
async def get_ignore_list(self, socket_path: str, name: str) -> list[str]:
|
|
...
|
|
|
|
async def add_ignore_ip(self, socket_path: str, name: str, ip: str) -> None:
|
|
...
|
|
|
|
async def del_ignore_ip(self, socket_path: str, name: str, ip: str) -> None:
|
|
...
|
|
|
|
async def set_ignore_self(self, socket_path: str, name: str, *, on: bool) -> None:
|
|
...
|
|
|
|
async def get_jail_banned_ips(
|
|
self,
|
|
socket_path: str,
|
|
jail_name: str,
|
|
page: int,
|
|
page_size: int,
|
|
search: str | None = None,
|
|
*,
|
|
geo_batch_lookup: object,
|
|
http_session: object,
|
|
app_db: aiosqlite.Connection,
|
|
) -> JailBannedIpsResponse:
|
|
...
|
|
|
|
async def lookup_ip(
|
|
self,
|
|
socket_path: str,
|
|
ip: str,
|
|
geo_enricher: object,
|
|
) -> object:
|
|
...
|