generated from Luis/nextjs-python-web-template
smoke check error handling for create vm
This commit is contained in:
@@ -12,26 +12,29 @@ from .utils import run_cmd
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/api/flake/attrs")
|
||||
async def inspect_flake_attrs(url: str) -> FlakeAttrResponse:
|
||||
async def get_attrs(url: str) -> list[str]:
|
||||
cmd = nix_flake_show(url)
|
||||
stdout = await run_cmd(cmd)
|
||||
|
||||
data: dict[str,dict] = {}
|
||||
data: dict[str, dict] = {}
|
||||
try:
|
||||
data = json.loads(stdout)
|
||||
except JSONDecodeError:
|
||||
raise HTTPException(status_code=422, detail=f"Could not load flake.")
|
||||
|
||||
raise HTTPException(status_code=422, detail="Could not load flake.")
|
||||
|
||||
nixos_configs = data.get("nixosConfigurations",{})
|
||||
nixos_configs = data.get("nixosConfigurations", {})
|
||||
flake_attrs = list(nixos_configs.keys())
|
||||
|
||||
if not flake_attrs:
|
||||
raise HTTPException(status_code=422, detail="No entry or no attribute: nixosConfigurations")
|
||||
raise HTTPException(
|
||||
status_code=422, detail="No entry or no attribute: nixosConfigurations"
|
||||
)
|
||||
return flake_attrs
|
||||
|
||||
|
||||
return FlakeAttrResponse(flake_attrs=flake_attrs)
|
||||
@router.get("/api/flake/attrs")
|
||||
async def inspect_flake_attrs(url: str) -> FlakeAttrResponse:
|
||||
return FlakeAttrResponse(flake_attrs=await get_attrs(url))
|
||||
|
||||
|
||||
@router.get("/api/flake")
|
||||
|
||||
Reference in New Issue
Block a user