Refactor response handling and health check endpoints
- Enhance response model with additional fields and validation - Update health and server router implementations - Improve frontend type definitions and API integration - Clean up documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -94,7 +94,7 @@ Note on field naming:
|
||||
- All responses with multiple items include a "total" field.
|
||||
"""
|
||||
|
||||
from typing import Generic, TypeVar
|
||||
from typing import Generic, Literal, TypeVar
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
@@ -326,3 +326,51 @@ class ErrorResponse(BanGuiBaseModel):
|
||||
default=None,
|
||||
description="Unique ID for correlating this error with request logs on both frontend and backend.",
|
||||
)
|
||||
|
||||
|
||||
class HealthResponse(BanGuiBaseModel):
|
||||
"""Standardized response for the health check endpoint.
|
||||
|
||||
Fields:
|
||||
status: Application health status — 'ok' when healthy, 'unavailable' otherwise.
|
||||
fail2ban: fail2ban daemon status — 'online' or 'offline'.
|
||||
|
||||
Example:
|
||||
```python
|
||||
# Healthy (HTTP 200)
|
||||
{
|
||||
"status": "ok",
|
||||
"fail2ban": "online"
|
||||
}
|
||||
|
||||
# Unhealthy (HTTP 503)
|
||||
{
|
||||
"status": "unavailable",
|
||||
"fail2ban": "offline"
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
||||
status: Literal["ok", "unavailable"] = Field(
|
||||
...,
|
||||
description="Application health status: 'ok' when healthy, 'unavailable' otherwise.",
|
||||
)
|
||||
fail2ban: Literal["online", "offline"] = Field(
|
||||
...,
|
||||
description="fail2ban daemon status: 'online' when reachable, 'offline' otherwise.",
|
||||
)
|
||||
|
||||
|
||||
class FlushLogsResponse(BanGuiBaseModel):
|
||||
"""Standardized response for the flush-logs command endpoint.
|
||||
|
||||
Fields:
|
||||
message: Human-readable result message from fail2ban.
|
||||
|
||||
Example:
|
||||
```python
|
||||
{"message": "Success: fail2ban log files were flushed."}
|
||||
```
|
||||
"""
|
||||
|
||||
message: str = Field(..., description="Human-readable result message from fail2ban.")
|
||||
|
||||
Reference in New Issue
Block a user