persistence: invert all writeability logic into not readonly

This commit is contained in:
Johannes Kirschbauer
2025-10-16 13:01:19 +02:00
parent 892cb1baae
commit 727474055e
4 changed files with 11 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ from clan_lib.machines.actions import FieldSchema
from clan_lib.nix_models.clan import InventoryMeta
from clan_lib.persist.introspection import retrieve_typed_field_names
from clan_lib.persist.inventory_store import InventoryStore
from clan_lib.persist.write_rules import is_writeable_key
from clan_lib.persist.write_rules import is_readonly_key
log = logging.getLogger(__name__)
@@ -57,7 +57,7 @@ def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]:
return {
field: {
"readonly": not is_writeable_key(f"meta.{field}", write_info),
"readonly": is_readonly_key(f"meta.{field}", write_info),
# TODO: Provide a meaningful reason
"reason": None,
"readonly_members": [],

View File

@@ -18,7 +18,7 @@ from clan_lib.persist.path_utils import (
list_difference,
set_value_by_path,
)
from clan_lib.persist.write_rules import is_writeable_key
from clan_lib.persist.write_rules import is_readonly_key
@dataclass
@@ -195,7 +195,7 @@ def get_machine_fields_schema(machine: Machine) -> dict[str, FieldSchema]:
"readonly": (
True
if field in protected_fields
else not is_writeable_key(
else is_readonly_key(
f"machines.{machine.name}.{field}",
write_info,
)

View File

@@ -7,7 +7,7 @@ from clan_lib.persist.path_utils import (
path_starts_with,
path_to_string,
)
from clan_lib.persist.write_rules import AttributeMap, is_writeable_path
from clan_lib.persist.write_rules import AttributeMap, is_readonly_path
def validate_no_static_deletion(
@@ -22,7 +22,7 @@ def validate_no_static_deletion(
def validate_not_readonly(path: PathTuple, writeables: AttributeMap) -> None:
"""Validate that a path is writeable."""
if not is_writeable_path(path, writeables):
if is_readonly_path(path, writeables):
msg = f"Path '{path_to_string(path)}' is readonly. - It seems its value is statically defined in nix."
raise ClanError(msg)

View File

@@ -16,7 +16,7 @@ class PersistenceAttribute(Enum):
type AttributeMap = dict[PathTuple, set[PersistenceAttribute]]
def is_writeable_path(
def is_readonly_path(
key: PathTuple,
attributes: AttributeMap,
) -> bool:
@@ -30,9 +30,9 @@ def is_writeable_path(
current_path = remaining
if current_path in attributes:
if PersistenceAttribute.WRITE in attributes[current_path]:
return True
if PersistenceAttribute.READONLY in attributes[current_path]:
return False
if PersistenceAttribute.READONLY in attributes[current_path]:
return True
# Check the parent path
remaining = remaining[:-1]
@@ -40,7 +40,7 @@ def is_writeable_path(
raise ClanError(msg)
def is_writeable_key(
def is_readonly_key(
key: str,
attributes: AttributeMap,
) -> bool:
@@ -51,7 +51,7 @@ def is_writeable_key(
In case of ambiguity use is_writeable_path with tuple keys.
"""
items = key.split(".")
return is_writeable_path(tuple(items), attributes)
return is_readonly_path(tuple(items), attributes)
def get_priority(value: Any) -> int | None: