Expose BanGUI version in API responses (dashboard + config)
This commit is contained in:
@@ -1002,6 +1002,7 @@ class ServiceStatusResponse(BaseModel):
|
|||||||
|
|
||||||
online: bool = Field(..., description="Whether fail2ban is reachable via its socket.")
|
online: bool = Field(..., description="Whether fail2ban is reachable via its socket.")
|
||||||
version: str | None = Field(default=None, description="fail2ban version string, or None when offline.")
|
version: str | None = Field(default=None, description="fail2ban version string, or None when offline.")
|
||||||
|
bangui_version: str = Field(..., description="BanGUI application version.")
|
||||||
jail_count: int = Field(default=0, ge=0, description="Number of currently active jails.")
|
jail_count: int = Field(default=0, ge=0, description="Number of currently active jails.")
|
||||||
total_bans: int = Field(default=0, ge=0, description="Aggregated current ban count across all jails.")
|
total_bans: int = Field(default=0, ge=0, description="Aggregated current ban count across all jails.")
|
||||||
total_failures: int = Field(default=0, ge=0, description="Aggregated current failure count across all jails.")
|
total_failures: int = Field(default=0, ge=0, description="Aggregated current failure count across all jails.")
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class ServerStatusResponse(BaseModel):
|
|||||||
model_config = ConfigDict(strict=True)
|
model_config = ConfigDict(strict=True)
|
||||||
|
|
||||||
status: ServerStatus
|
status: ServerStatus
|
||||||
|
bangui_version: str = Field(..., description="BanGUI application version.")
|
||||||
|
|
||||||
|
|
||||||
class ServerSettings(BaseModel):
|
class ServerSettings(BaseModel):
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
from fastapi import APIRouter, Query, Request
|
from fastapi import APIRouter, Query, Request
|
||||||
|
|
||||||
|
from app import __version__
|
||||||
from app.dependencies import AuthDep
|
from app.dependencies import AuthDep
|
||||||
from app.models.ban import (
|
from app.models.ban import (
|
||||||
BanOrigin,
|
BanOrigin,
|
||||||
@@ -69,7 +70,7 @@ async def get_server_status(
|
|||||||
"server_status",
|
"server_status",
|
||||||
ServerStatus(online=False),
|
ServerStatus(online=False),
|
||||||
)
|
)
|
||||||
return ServerStatusResponse(status=cached)
|
return ServerStatusResponse(status=cached, bangui_version=__version__)
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
|
|||||||
@@ -897,6 +897,7 @@ async def get_service_status(socket_path: str) -> ServiceStatusResponse:
|
|||||||
Returns:
|
Returns:
|
||||||
:class:`~app.models.config.ServiceStatusResponse`.
|
:class:`~app.models.config.ServiceStatusResponse`.
|
||||||
"""
|
"""
|
||||||
|
from app import __version__ # noqa: TCH001 - expose the app release version
|
||||||
from app.services.health_service import probe # lazy import avoids circular dep
|
from app.services.health_service import probe # lazy import avoids circular dep
|
||||||
|
|
||||||
server_status = await probe(socket_path)
|
server_status = await probe(socket_path)
|
||||||
@@ -922,6 +923,7 @@ async def get_service_status(socket_path: str) -> ServiceStatusResponse:
|
|||||||
return ServiceStatusResponse(
|
return ServiceStatusResponse(
|
||||||
online=server_status.online,
|
online=server_status.online,
|
||||||
version=server_status.version,
|
version=server_status.version,
|
||||||
|
bangui_version=__version__,
|
||||||
jail_count=server_status.active_jails,
|
jail_count=server_status.active_jails,
|
||||||
total_bans=server_status.total_bans,
|
total_bans=server_status.total_bans,
|
||||||
total_failures=server_status.total_failures,
|
total_failures=server_status.total_failures,
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import aiosqlite
|
|||||||
import pytest
|
import pytest
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
|
import app
|
||||||
|
|
||||||
from app.config import Settings
|
from app.config import Settings
|
||||||
from app.db import init_db
|
from app.db import init_db
|
||||||
from app.main import create_app
|
from app.main import create_app
|
||||||
@@ -2000,6 +2002,7 @@ class TestGetServiceStatus:
|
|||||||
return ServiceStatusResponse(
|
return ServiceStatusResponse(
|
||||||
online=online,
|
online=online,
|
||||||
version="1.0.0" if online else None,
|
version="1.0.0" if online else None,
|
||||||
|
bangui_version=app.__version__,
|
||||||
jail_count=2 if online else 0,
|
jail_count=2 if online else 0,
|
||||||
total_bans=10 if online else 0,
|
total_bans=10 if online else 0,
|
||||||
total_failures=3 if online else 0,
|
total_failures=3 if online else 0,
|
||||||
@@ -2018,6 +2021,7 @@ class TestGetServiceStatus:
|
|||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
assert data["online"] is True
|
assert data["online"] is True
|
||||||
|
assert data["bangui_version"] == app.__version__
|
||||||
assert data["jail_count"] == 2
|
assert data["jail_count"] == 2
|
||||||
assert data["log_level"] == "INFO"
|
assert data["log_level"] == "INFO"
|
||||||
|
|
||||||
@@ -2031,6 +2035,7 @@ class TestGetServiceStatus:
|
|||||||
|
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
assert data["bangui_version"] == app.__version__
|
||||||
assert data["online"] is False
|
assert data["online"] is False
|
||||||
assert data["log_level"] == "UNKNOWN"
|
assert data["log_level"] == "UNKNOWN"
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import aiosqlite
|
|||||||
import pytest
|
import pytest
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
|
import app
|
||||||
|
|
||||||
from app.config import Settings
|
from app.config import Settings
|
||||||
from app.db import init_db
|
from app.db import init_db
|
||||||
from app.main import create_app
|
from app.main import create_app
|
||||||
@@ -151,6 +153,9 @@ class TestDashboardStatus:
|
|||||||
body = response.json()
|
body = response.json()
|
||||||
|
|
||||||
assert "status" in body
|
assert "status" in body
|
||||||
|
assert "bangui_version" in body
|
||||||
|
assert body["bangui_version"] == app.__version__
|
||||||
|
|
||||||
status = body["status"]
|
status = body["status"]
|
||||||
assert "online" in status
|
assert "online" in status
|
||||||
assert "version" in status
|
assert "version" in status
|
||||||
@@ -163,8 +168,10 @@ class TestDashboardStatus:
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Endpoint returns the exact values from ``app.state.server_status``."""
|
"""Endpoint returns the exact values from ``app.state.server_status``."""
|
||||||
response = await dashboard_client.get("/api/dashboard/status")
|
response = await dashboard_client.get("/api/dashboard/status")
|
||||||
status = response.json()["status"]
|
body = response.json()
|
||||||
|
status = body["status"]
|
||||||
|
|
||||||
|
assert body["bangui_version"] == app.__version__
|
||||||
assert status["online"] is True
|
assert status["online"] is True
|
||||||
assert status["version"] == "1.0.2"
|
assert status["version"] == "1.0.2"
|
||||||
assert status["active_jails"] == 2
|
assert status["active_jails"] == 2
|
||||||
@@ -177,8 +184,10 @@ class TestDashboardStatus:
|
|||||||
"""Endpoint returns online=False when the cache holds an offline snapshot."""
|
"""Endpoint returns online=False when the cache holds an offline snapshot."""
|
||||||
response = await offline_dashboard_client.get("/api/dashboard/status")
|
response = await offline_dashboard_client.get("/api/dashboard/status")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
status = response.json()["status"]
|
body = response.json()
|
||||||
|
status = body["status"]
|
||||||
|
|
||||||
|
assert body["bangui_version"] == app.__version__
|
||||||
assert status["online"] is False
|
assert status["online"] is False
|
||||||
assert status["version"] is None
|
assert status["version"] is None
|
||||||
assert status["active_jails"] == 0
|
assert status["active_jails"] == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user