persistence: align some more variable names

This commit is contained in:
Johannes Kirschbauer
2025-10-16 13:04:24 +02:00
parent 727474055e
commit 17c35c4259
4 changed files with 15 additions and 13 deletions

View File

@@ -51,13 +51,13 @@ def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]:
""" """
inventory_store = InventoryStore(flake) inventory_store = InventoryStore(flake)
write_info = inventory_store.get_attribute_props() attribute_props = inventory_store.get_attribute_props()
field_names = retrieve_typed_field_names(InventoryMeta) field_names = retrieve_typed_field_names(InventoryMeta)
return { return {
field: { field: {
"readonly": is_readonly_key(f"meta.{field}", write_info), "readonly": is_readonly_key(f"meta.{field}", attribute_props),
# TODO: Provide a meaningful reason # TODO: Provide a meaningful reason
"reason": None, "reason": None,
"readonly_members": [], "readonly_members": [],

View File

@@ -170,7 +170,7 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]:
""" """
inventory_store = InventoryStore(machine.flake) inventory_store = InventoryStore(machine.flake)
write_info = inventory_store.get_attribute_props() attribute_props = inventory_store.get_attribute_props()
field_names = retrieve_typed_field_names(InventoryMachine) field_names = retrieve_typed_field_names(InventoryMachine)
@@ -197,7 +197,7 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]:
if field in protected_fields if field in protected_fields
else is_readonly_key( else is_readonly_key(
f"machines.{machine.name}.{field}", f"machines.{machine.name}.{field}",
write_info, attribute_props,
) )
), ),
# TODO: Provide a meaningful reason # TODO: Provide a meaningful reason

View File

@@ -249,13 +249,15 @@ def test_get_machine_writeability(clan_flake: Callable[..., Flake]) -> None:
persisted = inventory_store._get_persisted() persisted = inventory_store._get_persisted()
assert get_value_by_path(persisted, "machines.jon.tags", []) == new_tags assert get_value_by_path(persisted, "machines.jon.tags", []) == new_tags
write_info = get_machine_fields_schema(Machine("jon", flake)) attribute_props = get_machine_fields_schema(Machine("jon", flake))
# {'tags': {'writable': True, 'reason': None}, 'machineClass': {'writable': False, 'reason': None}, 'name': {'writable': False, 'reason': None}, 'description': {'writable': True, 'reason': None}, 'deploy.buildHost': {'writable': True, 'reason': None}, 'icon': {'writable': True, 'reason': None}, 'deploy.targetHost': {'writable': True, 'reason': None}} # {'tags': {'writable': True, 'reason': None}, 'machineClass': {'writable': False, 'reason': None}, 'name': {'writable': False, 'reason': None}, 'description': {'writable': True, 'reason': None}, 'deploy.buildHost': {'writable': True, 'reason': None}, 'icon': {'writable': True, 'reason': None}, 'deploy.targetHost': {'writable': True, 'reason': None}}
writeable_fields = { writeable_fields = {
field for field, info in write_info.items() if not info["readonly"] field for field, info in attribute_props.items() if not info["readonly"]
}
read_only_fields = {
field for field, info in attribute_props.items() if info["readonly"]
} }
read_only_fields = {field for field, info in write_info.items() if info["readonly"]}
assert writeable_fields == { assert writeable_fields == {
"tags", "tags",
@@ -267,7 +269,7 @@ def test_get_machine_writeability(clan_flake: Callable[..., Flake]) -> None:
} }
assert read_only_fields == {"machineClass", "name"} assert read_only_fields == {"machineClass", "name"}
assert write_info["tags"]["readonly_members"] == ["nix1", "all", "nixos"] assert attribute_props["tags"]["readonly_members"] == ["nix1", "all", "nixos"]
@pytest.mark.with_core @pytest.mark.with_core

View File

@@ -265,15 +265,15 @@ class InventoryStore:
"""Write the inventory to the flake directory """Write the inventory to the flake directory
and commit it to git with the given message and commit it to git with the given message
""" """
write_info = self._get_persistence_info() persistence_info = self._get_persistence_info()
patchset, delete_set = calc_patches( patchset, delete_set = calc_patches(
dict(write_info.data_disk), dict(persistence_info.data_disk),
dict(update), dict(update),
dict(write_info.data_eval), dict(persistence_info.data_eval),
write_info.attribute_props, persistence_info.attribute_props,
) )
persisted = dict(write_info.data_disk) persisted = dict(persistence_info.data_disk)
for patch_path, data in patchset.items(): for patch_path, data in patchset.items():
set_value_by_path_tuple(persisted, patch_path, data) set_value_by_path_tuple(persisted, patch_path, data)