Updated to main
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
# mypy: ignore-errors
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -6,7 +5,7 @@ from typing import Any
|
||||
from pydantic import AnyUrl, BaseModel, validator
|
||||
|
||||
from ..dirs import clan_data_dir, clan_flake_dir
|
||||
from ..flake.create import DEFAULT_URL
|
||||
from ..flakes.create import DEFAULT_URL
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -30,7 +29,7 @@ class ClanDataPath(BaseModel):
|
||||
dest: Path
|
||||
|
||||
@validator("dest")
|
||||
def check_data_path(cls: Any, v: Path) -> Path: # type: ignore
|
||||
def check_data_path(cls: Any, v: Path) -> Path: # noqa
|
||||
return validate_path(clan_data_dir(), v)
|
||||
|
||||
|
||||
@@ -38,7 +37,7 @@ class ClanFlakePath(BaseModel):
|
||||
dest: Path
|
||||
|
||||
@validator("dest")
|
||||
def check_dest(cls: Any, v: Path) -> Path: # type: ignore
|
||||
def check_dest(cls: Any, v: Path) -> Path: # noqa
|
||||
return validate_path(clan_flake_dir(), v)
|
||||
|
||||
|
||||
|
||||
@@ -17,11 +17,12 @@ from clan_cli.webui.api_outputs import (
|
||||
)
|
||||
|
||||
from ...async_cmd import run
|
||||
from ...flake import create
|
||||
from ...flakes import create
|
||||
from ...nix import nix_command, nix_flake_show
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# TODO: Check for directory traversal
|
||||
async def get_attrs(url: AnyUrl | Path) -> list[str]:
|
||||
cmd = nix_flake_show(url)
|
||||
@@ -42,6 +43,7 @@ async def get_attrs(url: AnyUrl | Path) -> list[str]:
|
||||
)
|
||||
return flake_attrs
|
||||
|
||||
|
||||
# TODO: Check for directory traversal
|
||||
@router.get("/api/flake/attrs")
|
||||
async def inspect_flake_attrs(url: AnyUrl | Path) -> FlakeAttrResponse:
|
||||
@@ -74,7 +76,6 @@ async def inspect_flake(
|
||||
return FlakeResponse(content=content, actions=actions)
|
||||
|
||||
|
||||
|
||||
@router.post("/api/flake/create", status_code=status.HTTP_201_CREATED)
|
||||
async def create_flake(
|
||||
args: Annotated[FlakeCreateInput, Body()],
|
||||
|
||||
@@ -27,17 +27,19 @@ log = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/api/machines")
|
||||
async def list_machines() -> MachinesResponse:
|
||||
@router.get("/api/{flake_name}/machines")
|
||||
async def list_machines(flake_name: str) -> MachinesResponse:
|
||||
machines = []
|
||||
for m in _list_machines():
|
||||
for m in _list_machines(flake_name):
|
||||
machines.append(Machine(name=m, status=Status.UNKNOWN))
|
||||
return MachinesResponse(machines=machines)
|
||||
|
||||
|
||||
@router.post("/api/machines", status_code=201)
|
||||
async def create_machine(machine: Annotated[MachineCreate, Body()]) -> MachineResponse:
|
||||
out = await _create_machine(machine.name)
|
||||
@router.post("/api/{flake_name}/machines", status_code=201)
|
||||
async def create_machine(
|
||||
flake_name: str, machine: Annotated[MachineCreate, Body()]
|
||||
) -> MachineResponse:
|
||||
out = await _create_machine(flake_name, machine.name)
|
||||
log.debug(out)
|
||||
return MachineResponse(machine=Machine(name=machine.name, status=Status.UNKNOWN))
|
||||
|
||||
@@ -48,23 +50,23 @@ async def get_machine(name: str) -> MachineResponse:
|
||||
return MachineResponse(machine=Machine(name=name, status=Status.UNKNOWN))
|
||||
|
||||
|
||||
@router.get("/api/machines/{name}/config")
|
||||
async def get_machine_config(name: str) -> ConfigResponse:
|
||||
config = config_for_machine(name)
|
||||
@router.get("/api/{flake_name}/machines/{name}/config")
|
||||
async def get_machine_config(flake_name: str, name: str) -> ConfigResponse:
|
||||
config = config_for_machine(flake_name, name)
|
||||
return ConfigResponse(config=config)
|
||||
|
||||
|
||||
@router.put("/api/machines/{name}/config")
|
||||
@router.put("/api/{flake_name}/machines/{name}/config")
|
||||
async def set_machine_config(
|
||||
name: str, config: Annotated[dict, Body()]
|
||||
flake_name: str, name: str, config: Annotated[dict, Body()]
|
||||
) -> ConfigResponse:
|
||||
set_config_for_machine(name, config)
|
||||
set_config_for_machine(flake_name, name, config)
|
||||
return ConfigResponse(config=config)
|
||||
|
||||
|
||||
@router.get("/api/machines/{name}/schema")
|
||||
async def get_machine_schema(name: str) -> SchemaResponse:
|
||||
schema = schema_for_machine(name)
|
||||
@router.get("/api/{flake_name}/machines/{name}/schema")
|
||||
async def get_machine_schema(flake_name: str, name: str) -> SchemaResponse:
|
||||
schema = schema_for_machine(flake_name, name)
|
||||
return SchemaResponse(schema=schema)
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ from ..api_outputs import (
|
||||
log = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# TODO: Check for directory traversal
|
||||
@router.post("/api/vms/inspect")
|
||||
async def inspect_vm(
|
||||
@@ -52,6 +53,7 @@ async def get_vm_logs(uuid: UUID) -> StreamingResponse:
|
||||
media_type="text/plain",
|
||||
)
|
||||
|
||||
|
||||
# TODO: Check for directory traversal
|
||||
@router.post("/api/vms/create")
|
||||
async def create_vm(vm: Annotated[VmConfig, Body()]) -> VmCreateResponse:
|
||||
|
||||
Reference in New Issue
Block a user