clan-cli: Rename Host -> Remote move to clan_lib and mark as frozen
This commit is contained in:
@@ -6,8 +6,8 @@ from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from clan_cli.machines import machines
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .generate import Generator, Var
|
||||
@@ -184,5 +184,5 @@ class StoreBase(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
pass
|
||||
|
||||
@@ -3,10 +3,10 @@ from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.vars._types import StoreBase
|
||||
from clan_cli.vars.generate import Generator, Var
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
|
||||
class FactStore(StoreBase):
|
||||
@@ -73,6 +73,6 @@ class FactStore(StoreBase):
|
||||
msg = "populate_dir is not implemented for public vars stores"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
msg = "upload is not implemented for public vars stores"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
@@ -4,11 +4,11 @@ from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.vars._types import StoreBase
|
||||
from clan_cli.vars.generate import Generator, Var
|
||||
from clan_lib.dirs import vm_state_dir
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -70,6 +70,6 @@ class FactStore(StoreBase):
|
||||
msg = "populate_dir is not implemented for public vars stores"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
msg = "upload is not implemented for public vars stores"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
@@ -3,9 +3,9 @@ import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.vars._types import StoreBase
|
||||
from clan_cli.vars.generate import Generator, Var
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
|
||||
class SecretStore(StoreBase):
|
||||
@@ -46,6 +46,6 @@ class SecretStore(StoreBase):
|
||||
shutil.copytree(self.dir, output_dir)
|
||||
shutil.rmtree(self.dir)
|
||||
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
msg = "Cannot upload secrets with FS backend"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
@@ -8,12 +8,12 @@ from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.ssh.upload import upload
|
||||
from clan_cli.vars._types import StoreBase
|
||||
from clan_cli.vars.generate import Generator, Var
|
||||
from clan_lib.cmd import CmdOut, Log, RunOpts, run
|
||||
from clan_lib.nix import nix_shell
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -147,16 +147,17 @@ class SecretStore(StoreBase):
|
||||
manifest += hashes
|
||||
return b"\n".join(manifest)
|
||||
|
||||
def needs_upload(self, host: Host) -> bool:
|
||||
def needs_upload(self, host: Remote) -> bool:
|
||||
local_hash = self.generate_hash()
|
||||
remote_hash = host.run(
|
||||
# TODO get the path to the secrets from the machine
|
||||
[
|
||||
"cat",
|
||||
f"{self.machine.deployment['password-store']['secretLocation']}/.{self._store_backend}_info",
|
||||
],
|
||||
RunOpts(log=Log.STDERR, check=False),
|
||||
).stdout.strip()
|
||||
with host.ssh_control_master() as ssh:
|
||||
remote_hash = ssh.run(
|
||||
# TODO get the path to the secrets from the machine
|
||||
[
|
||||
"cat",
|
||||
f"{self.machine.deployment['password-store']['secretLocation']}/.{self._store_backend}_info",
|
||||
],
|
||||
RunOpts(log=Log.STDERR, check=False),
|
||||
).stdout.strip()
|
||||
|
||||
if not remote_hash:
|
||||
print("remote hash is empty")
|
||||
@@ -226,7 +227,7 @@ class SecretStore(StoreBase):
|
||||
|
||||
(output_dir / f".{self._store_backend}_info").write_bytes(self.generate_hash())
|
||||
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
if "partitioning" in phases:
|
||||
msg = "Cannot upload partitioning secrets"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
@@ -22,12 +22,12 @@ from clan_cli.secrets.secrets import (
|
||||
groups_folder,
|
||||
has_secret,
|
||||
)
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.ssh.upload import upload
|
||||
from clan_cli.vars._types import StoreBase
|
||||
from clan_cli.vars.generate import Generator
|
||||
from clan_cli.vars.var import Var
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -224,7 +224,7 @@ class SecretStore(StoreBase):
|
||||
target_path.chmod(file.mode)
|
||||
|
||||
@override
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
if "partitioning" in phases:
|
||||
msg = "Cannot upload partitioning secrets"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
@@ -3,10 +3,10 @@ from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.vars._types import StoreBase
|
||||
from clan_cli.vars.generate import Generator, Var
|
||||
from clan_lib.dirs import vm_state_dir
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
|
||||
class SecretStore(StoreBase):
|
||||
@@ -61,6 +61,6 @@ class SecretStore(StoreBase):
|
||||
shutil.rmtree(output_dir)
|
||||
shutil.copytree(self.dir, output_dir)
|
||||
|
||||
def upload(self, host: Host, phases: list[str]) -> None:
|
||||
def upload(self, host: Remote, phases: list[str]) -> None:
|
||||
msg = "Cannot upload secrets to VMs"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
@@ -4,12 +4,12 @@ from pathlib import Path
|
||||
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_lib.ssh.remote import Remote
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upload_secret_vars(machine: Machine, host: Host) -> None:
|
||||
def upload_secret_vars(machine: Machine, host: Remote) -> None:
|
||||
machine.secret_vars_store.upload(host, phases=["activation", "users", "services"])
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ def upload_command(args: argparse.Namespace) -> None:
|
||||
populate_secret_vars(machine, directory)
|
||||
return
|
||||
|
||||
with machine.target_host() as host:
|
||||
upload_secret_vars(machine, host)
|
||||
host = machine.target_host()
|
||||
upload_secret_vars(machine, host)
|
||||
|
||||
|
||||
def register_upload_parser(parser: argparse.ArgumentParser) -> None:
|
||||
|
||||
Reference in New Issue
Block a user