From 19dbab01d72ecd556c33585aa4108bf48425ca0d Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 6 May 2025 12:05:02 +0200 Subject: [PATCH] chore(API): cleanup remove unnused functions --- pkgs/clan-cli/clan_cli/__init__.py | 4 +- pkgs/clan-cli/clan_cli/flash/flash.py | 1 + pkgs/clan-cli/clan_cli/inventory/__init__.py | 4 +- pkgs/clan-cli/clan_cli/machines/hardware.py | 22 ----------- pkgs/clan-cli/clan_cli/machines/list.py | 4 +- pkgs/clan-cli/clan_lib/api/admin.py | 37 ------------------- .../app/src/components/MachineListItem.tsx | 2 +- .../app/src/routes/machines/details.tsx | 11 ++---- .../app/src/routes/machines/list.tsx | 6 +-- 9 files changed, 14 insertions(+), 77 deletions(-) delete mode 100644 pkgs/clan-cli/clan_lib/api/admin.py diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 07b45347e..19a311ff2 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -6,13 +6,13 @@ from pathlib import Path from types import ModuleType # These imports are unused, but necessary for @API.register to run once. -from clan_lib.api import admin, directory, disk, iwd, mdns_discovery, modules +from clan_lib.api import directory, disk, iwd, mdns_discovery, modules from .arg_actions import AppendOptionAction from .clan import show, update # API endpoints that are not used in the cli. -__all__ = ["admin", "directory", "disk", "iwd", "mdns_discovery", "modules", "update"] +__all__ = ["directory", "disk", "iwd", "mdns_discovery", "modules", "update"] from . import ( backups, diff --git a/pkgs/clan-cli/clan_cli/flash/flash.py b/pkgs/clan-cli/clan_cli/flash/flash.py index 36021fb97..76727c7b3 100644 --- a/pkgs/clan-cli/clan_cli/flash/flash.py +++ b/pkgs/clan-cli/clan_cli/flash/flash.py @@ -35,6 +35,7 @@ class Disk: device: str +# TODO: unify this with machine install @API.register def flash_machine( machine: Machine, diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index 76f558785..fe3d0715f 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -61,7 +61,6 @@ def get_inventory_path(flake_dir: str | Path) -> Path: default_inventory: Inventory = {"meta": {"name": "New Clan"}} -@API.register def load_inventory_eval(flake_dir: str | Path) -> Inventory: """ Loads the evaluated inventory. @@ -522,6 +521,7 @@ def get_inventory_with_writeable_keys( return WriteInfo(writeables, data_eval, data_disk) +# TODO: remove this function in favor of a proper read/write API @API.register def set_inventory( inventory: Inventory, flake_dir: str | Path, message: str, commit: bool = True @@ -560,7 +560,7 @@ def set_inventory( commit_file(inventory_file, Path(flake_dir), commit_message=message) -@API.register +# TODO: wrap this in a proper persistence API def delete(directory: str | Path, delete_set: set[str]) -> None: """ Delete keys from the inventory diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 3d0b9709c..f441e615d 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -57,28 +57,6 @@ def show_machine_hardware_config(clan_dir: Path, machine_name: str) -> HardwareC return HardwareConfig.detect_type(clan_dir, machine_name) -@API.register -def show_machine_deployment_target(clan_dir: Path, machine_name: str) -> str | None: - """ - Show deployment target for a machine returns None if none exist. - """ - config = nix_config() - system = config["system"] - cmd = nix_eval( - [ - f"{clan_dir}#clanInternals.machines.{system}.{machine_name}", - "--apply", - "machine: { inherit (machine.config.clan.core.networking) targetHost; }", - "--json", - ] - ) - proc = run_no_stdout(cmd, RunOpts(prefix=machine_name)) - res = proc.stdout.strip() - - target_host = json.loads(res) - return target_host.get("targetHost", None) - - @API.register def show_machine_hardware_platform(clan_dir: Path, machine_name: str) -> str | None: """ diff --git a/pkgs/clan-cli/clan_cli/machines/list.py b/pkgs/clan-cli/clan_cli/machines/list.py index b34cb3dde..263df33c1 100644 --- a/pkgs/clan-cli/clan_cli/machines/list.py +++ b/pkgs/clan-cli/clan_cli/machines/list.py @@ -36,7 +36,7 @@ def set_machine(flake_url: Path, machine_name: str, machine: InventoryMachine) - @API.register -def list_inventory_machines(flake_url: str | Path) -> dict[str, InventoryMachine]: +def list_machines(flake_url: str | Path) -> dict[str, InventoryMachine]: inventory = load_inventory_eval(flake_url) return inventory.get("machines", {}) @@ -60,7 +60,7 @@ def extract_header(c: str) -> str: @API.register -def get_inventory_machine_details(flake_url: Path, machine_name: str) -> MachineDetails: +def get_machine_details(flake_url: Path, machine_name: str) -> MachineDetails: inventory = load_inventory_eval(flake_url) machine = inventory.get("machines", {}).get(machine_name) if machine is None: diff --git a/pkgs/clan-cli/clan_lib/api/admin.py b/pkgs/clan-cli/clan_lib/api/admin.py deleted file mode 100644 index 2f9ec3586..000000000 --- a/pkgs/clan-cli/clan_lib/api/admin.py +++ /dev/null @@ -1,37 +0,0 @@ -# @API.register -# def set_admin_service( -# base_url: str, -# allowed_keys: dict[str, str], -# instance_name: str = "admin", -# extra_machines: list[str] | None = None, -# ) -> None: -# """ -# Set the admin service of a clan -# Every machine is by default part of the admin service via the 'all' tag -# """ -# if extra_machines is None: -# extra_machines = [] -# inventory = load_inventory_eval(base_url) - -# if not allowed_keys: -# msg = "At least one key must be provided to ensure access" -# raise ClanError(msg) - -# instance = ServiceAdmin( -# meta=ServiceMeta(name=instance_name), -# roles=ServiceAdminRole( -# default=ServiceAdminRoleDefault( -# machines=extra_machines, -# tags=["all"], -# ) -# ), -# config=AdminConfig(allowedKeys=allowed_keys), -# ) - -# inventory.services.admin[instance_name] = instance - -# save_inventory( -# inventory, -# base_url, -# f"Set admin service: '{instance_name}'", -# ) diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx index 9415dc907..c4f67a3b7 100644 --- a/pkgs/webview-ui/app/src/components/MachineListItem.tsx +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -10,7 +10,7 @@ import { Filter } from "../routes/machines"; import { Typography } from "./Typography"; import { Button } from "./button"; -type MachineDetails = SuccessQuery<"list_inventory_machines">["data"][string]; +type MachineDetails = SuccessQuery<"list_machines">["data"][string]; interface MachineListItemProps { name: string; diff --git a/pkgs/webview-ui/app/src/routes/machines/details.tsx b/pkgs/webview-ui/app/src/routes/machines/details.tsx index fbbf104e6..c5742fd1e 100644 --- a/pkgs/webview-ui/app/src/routes/machines/details.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/details.tsx @@ -32,7 +32,7 @@ type MachineFormInterface = MachineData & { disk?: string; }; -type MachineData = SuccessData<"get_inventory_machine_details">; +type MachineData = SuccessData<"get_machine_details">; const steps: Record = { "1": "Hardware detection", @@ -641,16 +641,11 @@ const MachineForm = (props: MachineDetailsProps) => { export const MachineDetails = () => { const params = useParams(); const genericQuery = createQuery(() => ({ - queryKey: [ - activeURI(), - "machine", - params.id, - "get_inventory_machine_details", - ], + queryKey: [activeURI(), "machine", params.id, "get_machine_details"], queryFn: async () => { const curr = activeURI(); if (curr) { - const result = await callApi("get_inventory_machine_details", { + const result = await callApi("get_machine_details", { flake_url: curr, machine_name: params.id, }); diff --git a/pkgs/webview-ui/app/src/routes/machines/list.tsx b/pkgs/webview-ui/app/src/routes/machines/list.tsx index e5bb2eaf0..35b90ac71 100644 --- a/pkgs/webview-ui/app/src/routes/machines/list.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/list.tsx @@ -18,7 +18,7 @@ import { Header } from "@/src/layout/header"; import { makePersisted } from "@solid-primitives/storage"; type MachinesModel = Extract< - OperationResponse<"list_inventory_machines">, + OperationResponse<"list_machines">, { status: "success" } >["data"]; @@ -32,13 +32,13 @@ export const MachineListView: Component = () => { const [filter, setFilter] = createSignal({ tags: [] }); const inventoryQuery = createQuery(() => ({ - queryKey: [activeURI(), "list_inventory_machines"], + queryKey: [activeURI(), "list_machines"], placeholderData: {}, enabled: !!activeURI(), queryFn: async () => { const uri = activeURI(); if (uri) { - const response = await callApi("list_inventory_machines", { + const response = await callApi("list_machines", { flake_url: uri, }); if (response.status === "error") {