| 1 | from typing import Any, Dict |
| 2 | |
| 3 | from fastapi import APIRouter |
| 4 | from pydantic import BaseModel, Field |
| 5 | |
| 6 | from api.logging_config import apply_access_log_setting, apply_log_level_setting |
| 7 | from config import Config, CONFIG_PATH |
| 8 | |
| 9 | router = APIRouter(tags=["Configuration"]) |
| 10 | |
| 11 | |
| 12 | class ConfigUpdateRequest(BaseModel): |
| 13 | values: Dict[str, Any] = Field(default_factory=dict) |
| 14 | |
| 15 | |
| 16 | @router.get("/api/config") |
| 17 | async def get_config(): |
| 18 | return { |
| 19 | "config": Config.as_dict(), |
| 20 | "path": str(CONFIG_PATH), |
| 21 | } |
| 22 | |
| 23 | |
| 24 | @router.put("/api/config") |
| 25 | async def update_config(req: ConfigUpdateRequest): |
| 26 | config = Config.update_config(req.values) |
| 27 | apply_log_level_setting() |
| 28 | apply_access_log_setting() |
| 29 | return { |
| 30 | "config": config, |
| 31 | "path": str(CONFIG_PATH), |
| 32 | } |
| 33 |