api/machines: split off config validation into separate endpoint

- This speeds up PUT /machines{name}/config as it doesn't do the expensive check anymore
- instead use PUT /machines/{name}/verify which allows a dry-run evaluation of a config which is passed without writing it to disk
This commit is contained in:
DavHau
2023-10-25 17:48:30 +01:00
parent ed87aefbad
commit 0e5c7d2d13
3 changed files with 32 additions and 18 deletions

View File

@@ -64,16 +64,13 @@ def config_for_machine(machine_name: str) -> dict:
return json.load(f)
def set_config_for_machine(machine_name: str, config: dict) -> Optional[str]:
def set_config_for_machine(machine_name: str, config: dict) -> None:
# write the config to a json file located at {flake}/machines/{machine_name}/settings.json
if not machine_folder(machine_name).exists():
raise HTTPException(
status_code=404,
detail=f"Machine {machine_name} not found. Create the machine first`",
)
error = verify_machine_config(machine_name, config)
if error is not None:
return error
settings_path = machine_settings_file(machine_name)
settings_path.parent.mkdir(parents=True, exist_ok=True)
with open(settings_path, "w") as f:
@@ -82,7 +79,6 @@ def set_config_for_machine(machine_name: str, config: dict) -> Optional[str]:
if repo_dir is not None:
commit_file(settings_path, repo_dir)
return None
def schema_for_machine(