No canonical snake_case/camelCase serialization policy
This commit is contained in:
@@ -3,28 +3,22 @@
|
||||
Request, response, and domain models used by the jails router and service.
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic import Field
|
||||
|
||||
from app.models.config import BantimeEscalation
|
||||
from app.models.response import CommandResponse, CollectionResponse
|
||||
from app.models.response import BanGuiBaseModel, CommandResponse, CollectionResponse
|
||||
|
||||
|
||||
class JailStatus(BaseModel):
|
||||
class JailStatus(BanGuiBaseModel):
|
||||
"""Runtime metrics for a single jail."""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
currently_banned: int = Field(..., ge=0)
|
||||
total_banned: int = Field(..., ge=0)
|
||||
currently_failed: int = Field(..., ge=0)
|
||||
total_failed: int = Field(..., ge=0)
|
||||
|
||||
|
||||
class Jail(BaseModel):
|
||||
class Jail(BanGuiBaseModel):
|
||||
"""Domain model for a single fail2ban jail with its full configuration."""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
name: str = Field(..., description="Jail name as configured in fail2ban.")
|
||||
enabled: bool = Field(..., description="Whether the jail is currently active.")
|
||||
running: bool = Field(..., description="Whether the jail backend is running.")
|
||||
@@ -46,12 +40,9 @@ class Jail(BaseModel):
|
||||
)
|
||||
status: JailStatus | None = Field(default=None, description="Runtime counters.")
|
||||
|
||||
|
||||
class JailSummary(BaseModel):
|
||||
class JailSummary(BanGuiBaseModel):
|
||||
"""Lightweight jail entry for the overview list."""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
name: str
|
||||
enabled: bool
|
||||
running: bool
|
||||
@@ -62,7 +53,6 @@ class JailSummary(BaseModel):
|
||||
max_retry: int
|
||||
status: JailStatus | None = None
|
||||
|
||||
|
||||
class JailListResponse(CollectionResponse[JailSummary]):
|
||||
"""Response for ``GET /api/jails``.
|
||||
|
||||
@@ -71,7 +61,6 @@ class JailListResponse(CollectionResponse[JailSummary]):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class IgnoreListResponse(CollectionResponse[str]):
|
||||
"""Response for ``GET /api/jails/{name}/ignoreip``.
|
||||
|
||||
@@ -80,16 +69,13 @@ class IgnoreListResponse(CollectionResponse[str]):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class JailDetailResponse(BaseModel):
|
||||
class JailDetailResponse(BanGuiBaseModel):
|
||||
"""Response for ``GET /api/jails/{name}``.
|
||||
|
||||
Includes the primary jail object together with supplemental metadata
|
||||
required by the UI.
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
jail: Jail
|
||||
ignore_list: list[str] = Field(
|
||||
default_factory=list,
|
||||
@@ -100,7 +86,6 @@ class JailDetailResponse(BaseModel):
|
||||
description="Whether the jail ignores the server's own IP addresses.",
|
||||
)
|
||||
|
||||
|
||||
class JailCommandResponse(CommandResponse):
|
||||
"""Generic response for jail control commands (start, stop, reload, idle).
|
||||
|
||||
@@ -109,10 +94,7 @@ class JailCommandResponse(CommandResponse):
|
||||
|
||||
jail: str = Field(..., description="Target jail name, or '*' for operations on all jails.")
|
||||
|
||||
|
||||
class IgnoreIpRequest(BaseModel):
|
||||
class IgnoreIpRequest(BanGuiBaseModel):
|
||||
"""Payload for adding an IP or network to a jail's ignore list."""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
ip: str = Field(..., description="IP address or CIDR network to ignore.")
|
||||
|
||||
Reference in New Issue
Block a user