make facts stores inherit from an interface
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from clan_cli.machines.machines import Machine
|
||||||
|
|
||||||
|
|
||||||
|
class FactStoreBase(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
def __init__(self, machine: Machine) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def exists(self, service: str, name: str) -> bool:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set(self, service: str, name: str, value: bytes) -> Path | None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# get a single fact
|
||||||
|
@abstractmethod
|
||||||
|
def get(self, service: str, name: str) -> bytes:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# get all facts
|
||||||
|
@abstractmethod
|
||||||
|
def get_all(self) -> dict[str, dict[str, bytes]]:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ from pathlib import Path
|
|||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
|
|
||||||
|
from . import FactStoreBase
|
||||||
|
|
||||||
class FactStore:
|
|
||||||
|
class FactStore(FactStoreBase):
|
||||||
def __init__(self, machine: Machine) -> None:
|
def __init__(self, machine: Machine) -> None:
|
||||||
self.machine = machine
|
self.machine = machine
|
||||||
self.works_remotely = False
|
self.works_remotely = False
|
||||||
|
|
||||||
def set(self, _service: str, name: str, value: bytes) -> Path | None:
|
def set(self, service: str, name: str, value: bytes) -> Path | None:
|
||||||
if isinstance(self.machine.flake, Path):
|
if isinstance(self.machine.flake, Path):
|
||||||
fact_path = (
|
fact_path = (
|
||||||
self.machine.flake / "machines" / self.machine.name / "facts" / name
|
self.machine.flake / "machines" / self.machine.name / "facts" / name
|
||||||
@@ -23,14 +25,14 @@ class FactStore:
|
|||||||
f"in_flake fact storage is only supported for local flakes: {self.machine.flake}"
|
f"in_flake fact storage is only supported for local flakes: {self.machine.flake}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def exists(self, _service: str, name: str) -> bool:
|
def exists(self, service: str, name: str) -> bool:
|
||||||
fact_path = (
|
fact_path = (
|
||||||
self.machine.flake_dir / "machines" / self.machine.name / "facts" / name
|
self.machine.flake_dir / "machines" / self.machine.name / "facts" / name
|
||||||
)
|
)
|
||||||
return fact_path.exists()
|
return fact_path.exists()
|
||||||
|
|
||||||
# get a single fact
|
# get a single fact
|
||||||
def get(self, _service: str, name: str) -> bytes:
|
def get(self, service: str, name: str) -> bytes:
|
||||||
fact_path = (
|
fact_path = (
|
||||||
self.machine.flake_dir / "machines" / self.machine.name / "facts" / name
|
self.machine.flake_dir / "machines" / self.machine.name / "facts" / name
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ from clan_cli.dirs import vm_state_dir
|
|||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
|
|
||||||
|
from . import FactStoreBase
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FactStore:
|
class FactStore(FactStoreBase):
|
||||||
def __init__(self, machine: Machine) -> None:
|
def __init__(self, machine: Machine) -> None:
|
||||||
self.machine = machine
|
self.machine = machine
|
||||||
self.works_remotely = False
|
self.works_remotely = False
|
||||||
|
|||||||
Reference in New Issue
Block a user