From 53592837a93f9bca52782137be31ea693d2ded10 Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 12 Sep 2024 16:52:35 +0200 Subject: [PATCH] vars: get rid of meta.json --- .../clanCore/vars/secret/sops/funcs.nix | 3 +-- pkgs/clan-cli/clan_cli/vars/_types.py | 22 ++++--------------- .../clan_cli/vars/public_modules/in_repo.py | 3 +++ .../vars/secret_modules/password_store.py | 2 -- .../clan_cli/vars/secret_modules/sops.py | 3 +++ 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/nixosModules/clanCore/vars/secret/sops/funcs.nix b/nixosModules/clanCore/vars/secret/sops/funcs.nix index a842bc2b8..cc7a321d6 100644 --- a/nixosModules/clanCore/vars/secret/sops/funcs.nix +++ b/nixosModules/clanCore/vars/secret/sops/funcs.nix @@ -21,8 +21,7 @@ in flip mapAttrsToList vars.generators ( gen_name: generator: flip mapAttrsToList (relevantFiles generator) ( - fname: file: - lib.trace file { + fname: _file: { name = fname; generator = gen_name; inherit (generator) share; diff --git a/pkgs/clan-cli/clan_cli/vars/_types.py b/pkgs/clan-cli/clan_cli/vars/_types.py index 79683b318..0bed00b09 100644 --- a/pkgs/clan-cli/clan_cli/vars/_types.py +++ b/pkgs/clan-cli/clan_cli/vars/_types.py @@ -1,4 +1,3 @@ -import json import shutil from abc import ABC, abstractmethod from dataclasses import dataclass @@ -98,6 +97,10 @@ class StoreBase(ABC): override this method to implement the actual creation of the file """ + @abstractmethod + def exists(self, generator_name: str, name: str, shared: bool = False) -> bool: + pass + @property @abstractmethod def is_secret_store(self) -> bool: @@ -117,17 +120,6 @@ class StoreBase(ABC): / self.rel_dir(generator_name, var_name, shared) ) - def exists(self, generator_name: str, name: str, shared: bool = False) -> bool: - directory = self.directory(generator_name, name, shared) - if not (directory / "meta.json").exists(): - return False - with (directory / "meta.json").open() as f: - meta = json.load(f) - # check if is secret, as secret and public store names could collide (eg. 'vm') - if meta.get("secret") != self.is_secret_store: - return False - return meta.get("store") == self.store_name - def set( self, generator_name: str, @@ -143,12 +135,6 @@ class StoreBase(ABC): # re-create directory directory.mkdir(parents=True, exist_ok=True) new_file = self._set(generator_name, var_name, value, shared, deployed) - meta = { - "secret": self.is_secret_store, - "store": self.store_name, - } - with (directory / "meta.json").open("w") as file: - json.dump(meta, file, indent=2) return new_file def get_all(self) -> list[Var]: diff --git a/pkgs/clan-cli/clan_cli/vars/public_modules/in_repo.py b/pkgs/clan-cli/clan_cli/vars/public_modules/in_repo.py index 41cd87a57..697fdcc43 100644 --- a/pkgs/clan-cli/clan_cli/vars/public_modules/in_repo.py +++ b/pkgs/clan-cli/clan_cli/vars/public_modules/in_repo.py @@ -35,3 +35,6 @@ class FactStore(FactStoreBase): # get a single fact def get(self, generator_name: str, name: str, shared: bool = False) -> bytes: return (self.directory(generator_name, name, shared) / "value").read_bytes() + + def exists(self, generator_name: str, name: str, shared: bool = False) -> bool: + return (self.directory(generator_name, name, shared) / "value").exists() diff --git a/pkgs/clan-cli/clan_cli/vars/secret_modules/password_store.py b/pkgs/clan-cli/clan_cli/vars/secret_modules/password_store.py index 2a4af966c..158d1c59f 100644 --- a/pkgs/clan-cli/clan_cli/vars/secret_modules/password_store.py +++ b/pkgs/clan-cli/clan_cli/vars/secret_modules/password_store.py @@ -66,8 +66,6 @@ class SecretStore(SecretStoreBase): ).stdout def exists(self, generator_name: str, name: str, shared: bool = False) -> bool: - if not super().exists(generator_name, name, shared): - return False return ( Path(self._password_store_dir) / f"{self.entry_dir(generator_name, name, shared)}.gpg" diff --git a/pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py b/pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py index a35860768..845de9438 100644 --- a/pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py +++ b/pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py @@ -78,3 +78,6 @@ class SecretStore(SecretStoreBase): sops_secrets_folder(self.machine.flake_dir) / key_name, ) (output_dir / "key.txt").write_text(key) + + def exists(self, generator_name: str, name: str, shared: bool = False) -> bool: + return (self.directory(generator_name, name, shared) / "secret").exists()