flare / config_controller.py
ciyidogan's picture
Update config_controller.py
8029647 verified
raw
history blame
1.16 kB
from fastapi import APIRouter, Request, HTTPException
from service_config import ServiceConfig
import json
router = APIRouter()
service_config = ServiceConfig()
service_config.load()
@router.get("/get")
def get_config():
return {
"work_mode": service_config.work_mode,
"cloud_token": service_config.cloud_token,
"spark_endpoint": service_config.spark_endpoint,
"last_version_number": service_config.last_version_number
}
@router.post("/update")
async def update_config(request: Request):
data = await request.json()
work_mode = data.get("work_mode")
cloud_token = data.get("cloud_token")
spark_endpoint = data.get("spark_endpoint")
if not work_mode or not spark_endpoint:
raise HTTPException(status_code=400, detail="work_mode and spark_endpoint cannot be empty")
service_config.work_mode = work_mode
service_config.cloud_token = cloud_token
service_config.spark_endpoint = spark_endpoint
with open(service_config.config_path, "w", encoding="utf-8") as f:
json.dump(service_config, f, indent=2)
return {"message": "Configuration updated successfully"}