From 02ca5bd87042529849256587f2e4a5b8e4b43425 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 30 Apr 2025 15:19:43 +0700 Subject: [PATCH] gui: make update machine work Also fix error when age plugins not defined --- pkgs/clan-cli/clan_cli/machines/update.py | 10 ++----- pkgs/clan-cli/clan_cli/secrets/sops.py | 28 +++++-------------- .../app/src/routes/machines/details.tsx | 4 --- 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index fe87f236f..2415dc7c2 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -108,13 +108,9 @@ def update_machines(base_path: str, machines: list[InventoryMachine]) -> None: name, flake=flake, ) - if not machine.get("deploy", {}).get("targetHost"): - msg = f"'TargetHost' is not set for machine '{name}'" - raise ClanError(msg) - # Copy targetHost to machine - m.override_target_host = machine.get("deploy", {}).get("targetHost") - # Would be nice to have? - # m.override_build_host = machine.deploy.buildHost + # prefer target host set via inventory, but fallback to the one set in the machine + if target_host := machine.get("deploy", {}).get("targetHost"): + m.override_target_host = target_host group_machines.append(m) deploy_machines(group_machines) diff --git a/pkgs/clan-cli/clan_cli/secrets/sops.py b/pkgs/clan-cli/clan_cli/secrets/sops.py index 70ec7fbc0..8eff3a695 100644 --- a/pkgs/clan-cli/clan_cli/secrets/sops.py +++ b/pkgs/clan-cli/clan_cli/secrets/sops.py @@ -18,7 +18,8 @@ from clan_lib.api import API from clan_cli.cmd import Log, RunOpts, run from clan_cli.dirs import user_config_dir from clan_cli.errors import ClanError -from clan_cli.nix import nix_eval, nix_shell +from clan_cli.flake import Flake +from clan_cli.nix import nix_shell from .folders import sops_users_folder @@ -196,26 +197,11 @@ def load_age_plugins(flake_dir: str | Path) -> list[str]: msg = "Missing flake directory" raise ClanError(msg) - cmd = nix_eval( - [ - f"{flake_dir}#clanInternals.secrets.age.plugins", - "--json", - ] - ) - - try: - result = run(cmd) - except Exception as e: - msg = f"Failed to load age plugins {flake_dir}" - raise ClanError(msg) from e - - json_str = result.stdout.strip() - - try: - plugins = json.loads(json_str) - except json.JSONDecodeError as e: - msg = f"Failed to decode '{json_str}': {e}" - raise ClanError(msg) from e + flake = Flake(str(flake_dir)) + result = flake.select("clanInternals.?secrets.?age.?plugins") + plugins = result["secrets"]["age"]["plugins"] + if plugins == {}: + plugins = [] if isinstance(plugins, list): return plugins diff --git a/pkgs/webview-ui/app/src/routes/machines/details.tsx b/pkgs/webview-ui/app/src/routes/machines/details.tsx index fd8976522..bbd6ef1df 100644 --- a/pkgs/webview-ui/app/src/routes/machines/details.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/details.tsx @@ -459,10 +459,6 @@ const MachineForm = (props: MachineDetailsProps) => { } const target = targetHost(); - if (!target) { - toast.error("Target host is required"); - return; - } const loading_toast = toast.loading("Updating machine..."); const r = await callApi("update_machines", {