""" Configuration management API endpoint. """ import logging from fastapi import APIRouter from app.config import settings from app.schemas import ConfigResponse, ConfigUpdate log = logging.getLogger("foxy.api.config") router = APIRouter(prefix="/api/config", tags=["config"]) @router.get("", response_model=ConfigResponse) async def get_config(): """Get current configuration (secrets masked).""" return ConfigResponse( OPENCLAW_WORKSPACE=settings.OPENCLAW_WORKSPACE, GITEA_SERVER=settings.GITEA_SERVER, DEPLOYMENT_SERVER=settings.DEPLOYMENT_SERVER, DEPLOYMENT_USER=settings.DEPLOYMENT_USER, TELEGRAM_CHAT_ID=settings.TELEGRAM_CHAT_ID, LOG_LEVEL=settings.LOG_LEVEL, GITEA_OPENCLAW_TOKEN="***" if settings.GITEA_OPENCLAW_TOKEN else "", DEPLOYMENT_PWD="***" if settings.DEPLOYMENT_PWD else "", TELEGRAM_BOT_TOKEN="***" if settings.TELEGRAM_BOT_TOKEN else "", ) @router.put("") async def update_config(body: ConfigUpdate): """ Update non-sensitive configuration values. Note: In production, this would persist to .env file or a config store. For now, it updates the in-memory settings. """ updated = {} for field, value in body.model_dump(exclude_unset=True).items(): if value is not None: setattr(settings, field, value) updated[field] = value log.info(f"Config updated: {list(updated.keys())}") return {"message": "Configuration updated", "updated_fields": list(updated.keys())}