vars: make simplify vars store abstraction
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# !/usr/bin/env python3
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
|
||||
@@ -33,6 +34,17 @@ class StoreBase(ABC):
|
||||
def get(self, service: str, name: str, shared: bool = False) -> bytes:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def set(
|
||||
self,
|
||||
service: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def is_secret_store(self) -> bool:
|
||||
|
||||
@@ -153,7 +153,6 @@ def execute_generator(
|
||||
files = machine.vars_generators[generator_name]["files"]
|
||||
for file_name, file in files.items():
|
||||
is_deployed = file["deploy"]
|
||||
groups = machine.deployment["sops"]["defaultGroups"]
|
||||
|
||||
secret_file = tmpdir_out / file_name
|
||||
if not secret_file.is_file():
|
||||
@@ -165,7 +164,6 @@ def execute_generator(
|
||||
generator_name,
|
||||
file_name,
|
||||
secret_file.read_bytes(),
|
||||
groups,
|
||||
shared=is_shared,
|
||||
deployed=is_deployed,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from abc import abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.vars._types import StoreBase
|
||||
|
||||
|
||||
@@ -8,9 +5,3 @@ 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
|
||||
) -> Path | None:
|
||||
pass
|
||||
|
||||
@@ -21,7 +21,12 @@ class FactStore(FactStoreBase):
|
||||
return self.per_machine_folder / generator_name / name
|
||||
|
||||
def set(
|
||||
self, generator_name: str, name: str, value: bytes, shared: bool = False
|
||||
self,
|
||||
generator_name: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
if self.machine.flake.is_local():
|
||||
fact_path = self._var_path(generator_name, name, shared)
|
||||
|
||||
@@ -22,7 +22,12 @@ class FactStore(FactStoreBase):
|
||||
return fact_path.exists()
|
||||
|
||||
def set(
|
||||
self, service: str, name: str, value: bytes, shared: bool = False
|
||||
self,
|
||||
service: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
fact_path = self.dir / service / name
|
||||
fact_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -5,18 +5,6 @@ from clan_cli.vars._types import StoreBase
|
||||
|
||||
|
||||
class SecretStoreBase(StoreBase):
|
||||
@abstractmethod
|
||||
def set(
|
||||
self,
|
||||
service: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
groups: list[str],
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_secret_store(self) -> bool:
|
||||
return True
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import override
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.nix import nix_shell
|
||||
@@ -28,7 +29,6 @@ class SecretStore(SecretStoreBase):
|
||||
generator_name: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
groups: list[str],
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
@@ -111,8 +111,7 @@ class SecretStore(SecretStoreBase):
|
||||
hashes.sort()
|
||||
return b"\n".join(hashes)
|
||||
|
||||
# FIXME: add this when we switch to python3.12
|
||||
# @override
|
||||
@override
|
||||
def update_check(self) -> bool:
|
||||
local_hash = self.generate_hash()
|
||||
remote_hash = self.machine.target_host.run(
|
||||
|
||||
@@ -56,7 +56,6 @@ class SecretStore(SecretStoreBase):
|
||||
generator_name: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
groups: list[str],
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
@@ -66,7 +65,7 @@ class SecretStore(SecretStoreBase):
|
||||
path,
|
||||
value,
|
||||
add_machines=[self.machine.name],
|
||||
add_groups=groups,
|
||||
add_groups=self.machine.deployment["sops"]["defaultGroups"],
|
||||
meta={
|
||||
"deploy": deployed,
|
||||
},
|
||||
|
||||
@@ -18,7 +18,6 @@ class SecretStore(SecretStoreBase):
|
||||
service: str,
|
||||
name: str,
|
||||
value: bytes,
|
||||
groups: list[str],
|
||||
shared: bool = False,
|
||||
deployed: bool = True,
|
||||
) -> Path | None:
|
||||
|
||||
Reference in New Issue
Block a user