from typing import Any from fastapi import APIRouter, Depends, HTTPException from app.auth import verify_token from app.ops_runner import run_ops_json router = APIRouter() @router.get("/", summary="Get all container statuses") async def get_status( _: str = Depends(verify_token), ) -> list[dict[str, Any]]: """ Returns a list of container status objects from `ops status --json`. Each item contains: project, service, status, health, uptime. """ result = await run_ops_json(["status"]) if not result["success"]: raise HTTPException( status_code=500, detail=f"Failed to retrieve status: {result['error']}", ) data = result["data"] # Normalise to list regardless of what ops returns if isinstance(data, list): return data if isinstance(data, dict): # Some ops implementations wrap the list in a key for key in ("services", "containers", "status", "data"): if key in data and isinstance(data[key], list): return data[key] return [data] return []