From b17466c84b0b2135b60ed3816aed471ebdd8bd7b Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 11 Aug 2025 17:30:35 +0200 Subject: [PATCH] api/machines: expose readonly tags --- pkgs/clan-cli/clan_lib/machines/actions.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/machines/actions.py b/pkgs/clan-cli/clan_lib/machines/actions.py index a859f2df2..55201fe1a 100644 --- a/pkgs/clan-cli/clan_lib/machines/actions.py +++ b/pkgs/clan-cli/clan_lib/machines/actions.py @@ -12,6 +12,7 @@ from clan_lib.persist.util import ( is_writeable_key, retrieve_typed_field_names, set_value_by_path, + unmerge_lists, ) @@ -101,6 +102,7 @@ def set_machine(machine: Machine, update: InventoryMachine) -> None: class FieldSchema(TypedDict): readonly: bool reason: str | None + readonly_members: list[str] @API.register @@ -126,10 +128,15 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]: "name", # name is always readonly "machineClass", # machineClass can only be set during create } - # TODO: handle this more generically. I.e via json schema - # persisted_data = inventory_store._get_persisted() # - # unmerge_lists(all_list, persisted_data) + # TODO: handle this more generically. I.e via json schema + persisted_data = inventory_store._get_persisted() # noqa: SLF001 + inventory = inventory_store.read() # + all_tags = inventory.get("machines", {}).get(machine.name, {}).get("tags", []) + persisted_tags = ( + persisted_data.get("machines", {}).get(machine.name, {}).get("tags", []) + ) + nix_tags = unmerge_lists(all_tags, persisted_tags) return { field: { @@ -142,6 +149,7 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]: ), # TODO: Provide a meaningful reason "reason": None, + "readonly_members": nix_tags if field == "tags" else [], } for field in field_names }