Added a /info endpoint
Contains useful info like version, and configurations
This commit is contained in:
@@ -188,6 +188,15 @@ class Spool(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
class Info(BaseModel):
|
||||
version: str = Field(example="0.7.0")
|
||||
debug_mode: bool = Field(example=False)
|
||||
automatic_backups: bool = Field(example=True)
|
||||
data_dir: str = Field(example="/home/app/.local/share/spoolman")
|
||||
backups_dir: str = Field(example="/home/app/.local/share/spoolman/backups")
|
||||
db_type: str = Field(example="sqlite")
|
||||
|
||||
|
||||
class HealthCheck(BaseModel):
|
||||
status: str = Field(example="healthy")
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from fastapi.responses import JSONResponse
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
|
||||
from spoolman import env
|
||||
from spoolman.database.database import backup_global_db
|
||||
from spoolman.exceptions import ItemNotFoundError
|
||||
|
||||
@@ -32,6 +33,20 @@ async def itemnotfounderror_exception_handler(_request: Request, exc: ItemNotFou
|
||||
)
|
||||
|
||||
|
||||
# Add a general info endpoint
|
||||
@app.get("/info")
|
||||
async def info() -> models.Info:
|
||||
"""Return general info about the API."""
|
||||
return models.Info(
|
||||
version=env.get_version(),
|
||||
debug_mode=env.is_debug_mode(),
|
||||
automatic_backups=env.is_automatic_backup_enabled(),
|
||||
data_dir=str(env.get_data_dir().resolve()),
|
||||
backups_dir=str(env.get_backups_dir().resolve()),
|
||||
db_type=str(env.get_database_type() or "sqlite"),
|
||||
)
|
||||
|
||||
|
||||
# Add health check endpoint
|
||||
@app.get("/health")
|
||||
async def health() -> models.HealthCheck:
|
||||
|
||||
Reference in New Issue
Block a user