cli: add morph command

This commit is contained in:
Michael Hoang
2025-02-13 15:09:17 +07:00
parent c4f77989fb
commit 4e2ae0f9f6
10 changed files with 330 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
import shutil
from pathlib import Path
from clan_cli.machines.machines import Machine
from clan_cli.vars._types import StoreBase
from clan_cli.vars.generate import Generator, Var
class SecretStore(StoreBase):
@property
def is_secret_store(self) -> bool:
return True
def __init__(self, machine: Machine) -> None:
self.machine = machine
self.dir = Path("/run/secrets")
self.dir.mkdir(parents=True, exist_ok=True)
@property
def store_name(self) -> str:
return "fs"
def _set(
self,
generator: Generator,
var: Var,
value: bytes,
) -> Path | None:
secret_file = self.dir / generator.name / var.name
secret_file.parent.mkdir(parents=True, exist_ok=True)
secret_file.write_bytes(value)
return None # we manage the files outside of the git repo
def exists(self, generator: "Generator", name: str) -> bool:
return (self.dir / generator.name / name).exists()
def get(self, generator: Generator, name: str) -> bytes:
secret_file = self.dir / generator.name / name
return secret_file.read_bytes()
def populate_dir(self, output_dir: Path, phases: list[str]) -> None:
if output_dir.exists():
shutil.rmtree(output_dir)
shutil.copytree(self.dir, output_dir)
def upload(self, phases: list[str]) -> None:
msg = "Cannot upload secrets with FS backend"
raise NotImplementedError(msg)