Merge pull request 'api/machines: expose readonly tags' (#4690) from readonly-tags into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4690
This commit is contained in:
@@ -12,6 +12,7 @@ from clan_lib.persist.util import (
|
|||||||
is_writeable_key,
|
is_writeable_key,
|
||||||
retrieve_typed_field_names,
|
retrieve_typed_field_names,
|
||||||
set_value_by_path,
|
set_value_by_path,
|
||||||
|
unmerge_lists,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -101,6 +102,7 @@ def set_machine(machine: Machine, update: InventoryMachine) -> None:
|
|||||||
class FieldSchema(TypedDict):
|
class FieldSchema(TypedDict):
|
||||||
readonly: bool
|
readonly: bool
|
||||||
reason: str | None
|
reason: str | None
|
||||||
|
readonly_members: list[str]
|
||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
@@ -126,10 +128,15 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]:
|
|||||||
"name", # name is always readonly
|
"name", # name is always readonly
|
||||||
"machineClass", # machineClass can only be set during create
|
"machineClass", # machineClass can only be set during create
|
||||||
}
|
}
|
||||||
# TODO: handle this more generically. I.e via json schema
|
|
||||||
|
|
||||||
# persisted_data = inventory_store._get_persisted() #
|
# TODO: handle this more generically. I.e via json schema
|
||||||
# unmerge_lists(all_list, persisted_data)
|
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 {
|
return {
|
||||||
field: {
|
field: {
|
||||||
@@ -142,6 +149,7 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]:
|
|||||||
),
|
),
|
||||||
# TODO: Provide a meaningful reason
|
# TODO: Provide a meaningful reason
|
||||||
"reason": None,
|
"reason": None,
|
||||||
|
"readonly_members": nix_tags if field == "tags" else [],
|
||||||
}
|
}
|
||||||
for field in field_names
|
for field in field_names
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user