Merge pull request 'chore(API): cleanup remove unnused functions' (#3516) from hsjobeki/clan-core:api-cleanup-2 into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3516
This commit is contained in:
hsjobeki
2025-05-06 10:42:37 +00:00
9 changed files with 14 additions and 77 deletions

View File

@@ -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,

View File

@@ -35,6 +35,7 @@ class Disk:
device: str
# TODO: unify this with machine install
@API.register
def flash_machine(
machine: Machine,

View File

@@ -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

View File

@@ -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:
"""

View File

@@ -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:

View File

@@ -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}'",
# )

View File

@@ -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;

View File

@@ -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<StepIdx, string> = {
"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,
});

View File

@@ -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<Filter>({ tags: [] });
const inventoryQuery = createQuery<MachinesModel>(() => ({
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") {