Feat(inventory): remove legacy action functions

Inventory should only and always be accessed through the inventory store.
Manually reading and writing to the json file is highly insecure
This commit is contained in:
Johannes Kirschbauer
2025-05-27 17:20:04 +02:00
parent c32d196428
commit e6d1f71907
4 changed files with 21 additions and 219 deletions

View File

@@ -21,8 +21,11 @@ log = logging.getLogger(__name__)
@API.register
def delete_machine(machine: Machine) -> None:
inventory_store = inventory.InventoryStore(machine.flake)
try:
inventory.delete(machine.flake, {f"machines.{machine.name}"})
inventory_store.delete(
{f"machines.{machine.name}"},
)
except KeyError as exc:
# louis@(2025-03-09): test infrastructure does not seem to set the
# inventory properly, but more importantly only one machine in my

View File

@@ -5,7 +5,7 @@ from clan_cli.tests.age_keys import SopsSetup, assert_secrets_file_recipients
from clan_cli.tests.helpers import cli
from clan_cli.tests.stdout import CaptureOutput
from clan_lib.flake import Flake
from clan_lib.inventory import load_inventory_json
from clan_lib.persist.inventory_store import InventoryStore
@pytest.mark.impure
@@ -25,7 +25,8 @@ def test_machine_subcommands(
]
)
inventory: dict = dict(load_inventory_json(Flake(str(test_flake_with_core.path))))
inventory_store = InventoryStore(Flake(str(test_flake_with_core.path)))
inventory: dict = dict(inventory_store.read())
assert "machine1" in inventory["machines"]
assert "service" not in inventory
@@ -41,7 +42,7 @@ def test_machine_subcommands(
["machines", "delete", "--flake", str(test_flake_with_core.path), "machine1"]
)
inventory_2: dict = dict(load_inventory_json(Flake(str(test_flake_with_core.path))))
inventory_2: dict = dict(inventory_store.read())
assert "machine1" not in inventory_2["machines"]
assert "service" not in inventory_2