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]
|
[tool.setuptools.package-data]
|
||||||
test_driver = ["py.typed"]
|
test_driver = ["py.typed"]
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.11"
|
python_version = "3.12"
|
||||||
warn_redundant_casts = true
|
warn_redundant_casts = true
|
||||||
disallow_untyped_calls = true
|
disallow_untyped_calls = true
|
||||||
disallow_untyped_defs = true
|
disallow_untyped_defs = true
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# !/usr/bin/env python3
|
# !/usr/bin/env python3
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_cli.machines.machines import Machine
|
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:
|
def get(self, service: str, name: str, shared: bool = False) -> bytes:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set(
|
||||||
|
self,
|
||||||
|
service: str,
|
||||||
|
name: str,
|
||||||
|
value: bytes,
|
||||||
|
shared: bool = False,
|
||||||
|
deployed: bool = True,
|
||||||
|
) -> Path | None:
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_secret_store(self) -> bool:
|
def is_secret_store(self) -> bool:
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ def execute_generator(
|
|||||||
files = machine.vars_generators[generator_name]["files"]
|
files = machine.vars_generators[generator_name]["files"]
|
||||||
for file_name, file in files.items():
|
for file_name, file in files.items():
|
||||||
is_deployed = file["deploy"]
|
is_deployed = file["deploy"]
|
||||||
groups = machine.deployment["sops"]["defaultGroups"]
|
|
||||||
|
|
||||||
secret_file = tmpdir_out / file_name
|
secret_file = tmpdir_out / file_name
|
||||||
if not secret_file.is_file():
|
if not secret_file.is_file():
|
||||||
@@ -165,7 +164,6 @@ def execute_generator(
|
|||||||
generator_name,
|
generator_name,
|
||||||
file_name,
|
file_name,
|
||||||
secret_file.read_bytes(),
|
secret_file.read_bytes(),
|
||||||
groups,
|
|
||||||
shared=is_shared,
|
shared=is_shared,
|
||||||
deployed=is_deployed,
|
deployed=is_deployed,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
from abc import abstractmethod
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from clan_cli.vars._types import StoreBase
|
from clan_cli.vars._types import StoreBase
|
||||||
|
|
||||||
|
|
||||||
@@ -8,9 +5,3 @@ class FactStoreBase(StoreBase):
|
|||||||
@property
|
@property
|
||||||
def is_secret_store(self) -> bool:
|
def is_secret_store(self) -> bool:
|
||||||
return False
|
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
|
return self.per_machine_folder / generator_name / name
|
||||||
|
|
||||||
def set(
|
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:
|
) -> Path | None:
|
||||||
if self.machine.flake.is_local():
|
if self.machine.flake.is_local():
|
||||||
fact_path = self._var_path(generator_name, name, shared)
|
fact_path = self._var_path(generator_name, name, shared)
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ class FactStore(FactStoreBase):
|
|||||||
return fact_path.exists()
|
return fact_path.exists()
|
||||||
|
|
||||||
def set(
|
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:
|
) -> Path | None:
|
||||||
fact_path = self.dir / service / name
|
fact_path = self.dir / service / name
|
||||||
fact_path.parent.mkdir(parents=True, exist_ok=True)
|
fact_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
@@ -5,18 +5,6 @@ from clan_cli.vars._types import StoreBase
|
|||||||
|
|
||||||
|
|
||||||
class SecretStoreBase(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
|
@property
|
||||||
def is_secret_store(self) -> bool:
|
def is_secret_store(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import override
|
||||||
|
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
from clan_cli.nix import nix_shell
|
from clan_cli.nix import nix_shell
|
||||||
@@ -28,7 +29,6 @@ class SecretStore(SecretStoreBase):
|
|||||||
generator_name: str,
|
generator_name: str,
|
||||||
name: str,
|
name: str,
|
||||||
value: bytes,
|
value: bytes,
|
||||||
groups: list[str],
|
|
||||||
shared: bool = False,
|
shared: bool = False,
|
||||||
deployed: bool = True,
|
deployed: bool = True,
|
||||||
) -> Path | None:
|
) -> Path | None:
|
||||||
@@ -111,8 +111,7 @@ class SecretStore(SecretStoreBase):
|
|||||||
hashes.sort()
|
hashes.sort()
|
||||||
return b"\n".join(hashes)
|
return b"\n".join(hashes)
|
||||||
|
|
||||||
# FIXME: add this when we switch to python3.12
|
@override
|
||||||
# @override
|
|
||||||
def update_check(self) -> bool:
|
def update_check(self) -> bool:
|
||||||
local_hash = self.generate_hash()
|
local_hash = self.generate_hash()
|
||||||
remote_hash = self.machine.target_host.run(
|
remote_hash = self.machine.target_host.run(
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class SecretStore(SecretStoreBase):
|
|||||||
generator_name: str,
|
generator_name: str,
|
||||||
name: str,
|
name: str,
|
||||||
value: bytes,
|
value: bytes,
|
||||||
groups: list[str],
|
|
||||||
shared: bool = False,
|
shared: bool = False,
|
||||||
deployed: bool = True,
|
deployed: bool = True,
|
||||||
) -> Path | None:
|
) -> Path | None:
|
||||||
@@ -66,7 +65,7 @@ class SecretStore(SecretStoreBase):
|
|||||||
path,
|
path,
|
||||||
value,
|
value,
|
||||||
add_machines=[self.machine.name],
|
add_machines=[self.machine.name],
|
||||||
add_groups=groups,
|
add_groups=self.machine.deployment["sops"]["defaultGroups"],
|
||||||
meta={
|
meta={
|
||||||
"deploy": deployed,
|
"deploy": deployed,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class SecretStore(SecretStoreBase):
|
|||||||
service: str,
|
service: str,
|
||||||
name: str,
|
name: str,
|
||||||
value: bytes,
|
value: bytes,
|
||||||
groups: list[str],
|
|
||||||
shared: bool = False,
|
shared: bool = False,
|
||||||
deployed: bool = True,
|
deployed: bool = True,
|
||||||
) -> Path | None:
|
) -> Path | None:
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ testpaths = "tests"
|
|||||||
faulthandler_timeout = 60
|
faulthandler_timeout = 60
|
||||||
log_level = "DEBUG"
|
log_level = "DEBUG"
|
||||||
log_format = "%(levelname)s: %(message)s\n %(pathname)s:%(lineno)d::%(funcName)s"
|
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"
|
norecursedirs = "tests/helpers"
|
||||||
markers = ["impure", "with_core"]
|
markers = ["impure", "with_core"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.11"
|
python_version = "3.12"
|
||||||
warn_redundant_casts = true
|
warn_redundant_casts = true
|
||||||
disallow_untyped_calls = true
|
disallow_untyped_calls = true
|
||||||
disallow_untyped_defs = true
|
disallow_untyped_defs = true
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ norecursedirs = "tests/helpers"
|
|||||||
markers = ["impure"]
|
markers = ["impure"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.11"
|
python_version = "3.12"
|
||||||
warn_redundant_casts = true
|
warn_redundant_casts = true
|
||||||
disallow_untyped_calls = true
|
disallow_untyped_calls = true
|
||||||
disallow_untyped_defs = true
|
disallow_untyped_defs = true
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.11"
|
python_version = "3.12"
|
||||||
pretty = true
|
pretty = true
|
||||||
warn_redundant_casts = true
|
warn_redundant_casts = true
|
||||||
disallow_untyped_calls = true
|
disallow_untyped_calls = true
|
||||||
|
|||||||
Reference in New Issue
Block a user