vars: fix listing vars + add test

This commit is contained in:
DavHau
2024-09-01 16:10:00 +02:00
parent 8bf4fddbdc
commit 8ad90aa44f
5 changed files with 35 additions and 4 deletions

View File

@@ -33,10 +33,18 @@ class StoreBase(ABC):
def get(self, service: str, name: str, shared: bool = False) -> bytes:
pass
@property
@abstractmethod
def is_secret_store(self) -> bool:
pass
def get_all(self) -> list[Var]:
all_vars = []
for gen_name, generator in self.machine.vars_generators.items():
for f_name, file in generator["files"].items():
# only handle vars compatible to this store
if self.is_secret_store != file["secret"]:
continue
all_vars.append(
Var(
store=self,

View File

@@ -18,11 +18,17 @@ def get_all_vars(machine: Machine) -> list[Var]:
return public_vars_store.get_all() + secret_vars_store.get_all()
def stringify_vars(_vars: list[Var]) -> str:
return "\n".join([str(var) for var in _vars])
def stringify_all_vars(machine: Machine) -> str:
return stringify_vars(get_all_vars(machine))
def get_command(args: argparse.Namespace) -> None:
machine = Machine(name=args.machine, flake=args.flake)
for var in get_all_vars(machine):
print(var)
print(stringify_all_vars(machine))
def register_list_parser(parser: argparse.ArgumentParser) -> None:

View File

@@ -5,6 +5,10 @@ from clan_cli.vars._types import StoreBase
class FactStoreBase(StoreBase):
@property
def is_secret_store(self) -> bool:
return False
@abstractmethod
def set(
self, service: str, name: str, value: bytes, shared: bool = False

View File

@@ -17,6 +17,10 @@ class SecretStoreBase(StoreBase):
) -> Path | None:
pass
@property
def is_secret_store(self) -> bool:
return True
def update_check(self) -> bool:
return False