Merge pull request 'vars: make simplify vars store abstraction' (#2021) from DavHau/clan-core:DavHau-dave into main
This commit is contained in:
@@ -15,7 +15,7 @@ find = {}
|
||||
[tool.setuptools.package-data]
|
||||
test_driver = ["py.typed"]
|
||||
[tool.mypy]
|
||||
python_version = "3.11"
|
||||
python_version = "3.12"
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -32,12 +32,12 @@ testpaths = "tests"
|
||||
faulthandler_timeout = 60
|
||||
log_level = "DEBUG"
|
||||
log_format = "%(levelname)s: %(message)s\n %(pathname)s:%(lineno)d::%(funcName)s"
|
||||
addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail --durations 5 --color=yes --new-first" # Add --pdb for debugging
|
||||
addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail --durations 5 --color=yes --new-first -n auto" # Add --pdb for debugging
|
||||
norecursedirs = "tests/helpers"
|
||||
markers = ["impure", "with_core"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.11"
|
||||
python_version = "3.12"
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
|
||||
@@ -30,7 +30,7 @@ norecursedirs = "tests/helpers"
|
||||
markers = ["impure"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.11"
|
||||
python_version = "3.12"
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[tool.mypy]
|
||||
python_version = "3.11"
|
||||
python_version = "3.12"
|
||||
pretty = true
|
||||
warn_redundant_casts = true
|
||||
disallow_untyped_calls = true
|
||||
|
||||
Reference in New Issue
Block a user