From 2621a961e7992b5474618510c4a6eb891a4a8953 Mon Sep 17 00:00:00 2001 From: DavHau Date: Mon, 2 Sep 2024 17:41:38 +0200 Subject: [PATCH] vars: make simplify vars store abstraction --- checks/lib/container-driver/pyproject.toml | 2 +- pkgs/clan-cli/clan_cli/vars/_types.py | 12 ++++++++++++ pkgs/clan-cli/clan_cli/vars/generate.py | 2 -- .../clan_cli/vars/public_modules/__init__.py | 9 --------- .../clan-cli/clan_cli/vars/public_modules/in_repo.py | 7 ++++++- pkgs/clan-cli/clan_cli/vars/public_modules/vm.py | 7 ++++++- .../clan_cli/vars/secret_modules/__init__.py | 12 ------------ .../clan_cli/vars/secret_modules/password_store.py | 5 ++--- pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py | 3 +-- pkgs/clan-cli/clan_cli/vars/secret_modules/vm.py | 1 - pkgs/clan-cli/pyproject.toml | 4 ++-- pkgs/clan-vm-manager/pyproject.toml | 2 +- pyproject.toml | 2 +- 13 files changed, 32 insertions(+), 36 deletions(-) diff --git a/checks/lib/container-driver/pyproject.toml b/checks/lib/container-driver/pyproject.toml index 136c15a1d..c9c3abf54 100644 --- a/checks/lib/container-driver/pyproject.toml +++ b/checks/lib/container-driver/pyproject.toml @@ -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 diff --git a/pkgs/clan-cli/clan_cli/vars/_types.py b/pkgs/clan-cli/clan_cli/vars/_types.py index 9612af8c6..7dc9b7a76 100644 --- a/pkgs/clan-cli/clan_cli/vars/_types.py +++ b/pkgs/clan-cli/clan_cli/vars/_types.py @@ -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: diff --git a/pkgs/clan-cli/clan_cli/vars/generate.py b/pkgs/clan-cli/clan_cli/vars/generate.py index d13eb4e5d..da5349059 100644 --- a/pkgs/clan-cli/clan_cli/vars/generate.py +++ b/pkgs/clan-cli/clan_cli/vars/generate.py @@ -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, ) diff --git a/pkgs/clan-cli/clan_cli/vars/public_modules/__init__.py b/pkgs/clan-cli/clan_cli/vars/public_modules/__init__.py index add64b018..5731afe50 100644 --- a/pkgs/clan-cli/clan_cli/vars/public_modules/__init__.py +++ b/pkgs/clan-cli/clan_cli/vars/public_modules/__init__.py @@ -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 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 272ff3154..2220f8340 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 @@ -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) diff --git a/pkgs/clan-cli/clan_cli/vars/public_modules/vm.py b/pkgs/clan-cli/clan_cli/vars/public_modules/vm.py index 45aeb617d..44ce934dc 100644 --- a/pkgs/clan-cli/clan_cli/vars/public_modules/vm.py +++ b/pkgs/clan-cli/clan_cli/vars/public_modules/vm.py @@ -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) diff --git a/pkgs/clan-cli/clan_cli/vars/secret_modules/__init__.py b/pkgs/clan-cli/clan_cli/vars/secret_modules/__init__.py index 41d107220..77e1b8113 100644 --- a/pkgs/clan-cli/clan_cli/vars/secret_modules/__init__.py +++ b/pkgs/clan-cli/clan_cli/vars/secret_modules/__init__.py @@ -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 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 06666e224..468e78559 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 @@ -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( 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 20c7f96b9..cbbc0d208 100644 --- a/pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py +++ b/pkgs/clan-cli/clan_cli/vars/secret_modules/sops.py @@ -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, }, diff --git a/pkgs/clan-cli/clan_cli/vars/secret_modules/vm.py b/pkgs/clan-cli/clan_cli/vars/secret_modules/vm.py index 17ab5cc81..577ea4a7e 100644 --- a/pkgs/clan-cli/clan_cli/vars/secret_modules/vm.py +++ b/pkgs/clan-cli/clan_cli/vars/secret_modules/vm.py @@ -18,7 +18,6 @@ class SecretStore(SecretStoreBase): service: str, name: str, value: bytes, - groups: list[str], shared: bool = False, deployed: bool = True, ) -> Path | None: diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index 1fa279f2f..32990eb95 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -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 diff --git a/pkgs/clan-vm-manager/pyproject.toml b/pkgs/clan-vm-manager/pyproject.toml index 5e7c4eeeb..0762eb1a3 100644 --- a/pkgs/clan-vm-manager/pyproject.toml +++ b/pkgs/clan-vm-manager/pyproject.toml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 10ba518ce..61242d1cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.mypy] -python_version = "3.11" +python_version = "3.12" pretty = true warn_redundant_casts = true disallow_untyped_calls = true