clan-lib: machines.py: Remove private_key attribute
This commit is contained in:
@@ -194,7 +194,7 @@ def install_command(args: argparse.Namespace) -> None:
|
|||||||
host_key_check=host_key_check,
|
host_key_check=host_key_check,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
target_host = machine.target_host().with_data(host_key_check=host_key_check)
|
target_host = machine.target_host().override(host_key_check=host_key_check)
|
||||||
|
|
||||||
if machine._class_ == "darwin":
|
if machine._class_ == "darwin":
|
||||||
msg = "Installing macOS machines is not yet supported"
|
msg = "Installing macOS machines is not yet supported"
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Machine:
|
|||||||
flake: Flake
|
flake: Flake
|
||||||
|
|
||||||
nix_options: list[str] = field(default_factory=list)
|
nix_options: list[str] = field(default_factory=list)
|
||||||
private_key: Path | None = None
|
|
||||||
host_key_check: HostKeyCheck = HostKeyCheck.STRICT
|
host_key_check: HostKeyCheck = HostKeyCheck.STRICT
|
||||||
|
|
||||||
def get_inv_machine(self) -> "InventoryMachine":
|
def get_inv_machine(self) -> "InventoryMachine":
|
||||||
@@ -149,18 +149,8 @@ class Machine:
|
|||||||
description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.",
|
description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.",
|
||||||
)
|
)
|
||||||
data = remote.data
|
data = remote.data
|
||||||
return Remote(
|
return data.override(
|
||||||
address=data.address,
|
|
||||||
user=data.user,
|
|
||||||
command_prefix=data.command_prefix,
|
|
||||||
port=data.port,
|
|
||||||
private_key=self.private_key,
|
|
||||||
password=data.password,
|
|
||||||
forward_agent=data.forward_agent,
|
|
||||||
host_key_check=self.host_key_check,
|
host_key_check=self.host_key_check,
|
||||||
verbose_ssh=data.verbose_ssh,
|
|
||||||
ssh_options=data.ssh_options,
|
|
||||||
tor_socks=data.tor_socks,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def build_host(self) -> Remote | None:
|
def build_host(self) -> Remote | None:
|
||||||
@@ -172,18 +162,8 @@ class Machine:
|
|||||||
|
|
||||||
if remote:
|
if remote:
|
||||||
data = remote.data
|
data = remote.data
|
||||||
return Remote(
|
return data.override(
|
||||||
address=data.address,
|
|
||||||
user=data.user,
|
|
||||||
command_prefix=data.command_prefix,
|
|
||||||
port=data.port,
|
|
||||||
private_key=self.private_key,
|
|
||||||
password=data.password,
|
|
||||||
forward_agent=data.forward_agent,
|
|
||||||
host_key_check=self.host_key_check,
|
host_key_check=self.host_key_check,
|
||||||
verbose_ssh=data.verbose_ssh,
|
|
||||||
ssh_options=data.ssh_options,
|
|
||||||
tor_socks=data.tor_socks,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -289,7 +269,6 @@ def get_host(
|
|||||||
machine_name=machine.name,
|
machine_name=machine.name,
|
||||||
address=host_str,
|
address=host_str,
|
||||||
host_key_check=machine.host_key_check,
|
host_key_check=machine.host_key_check,
|
||||||
private_key=machine.private_key,
|
|
||||||
),
|
),
|
||||||
source=source,
|
source=source,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -54,7 +54,12 @@ class Remote:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def with_data(self, host_key_check: HostKeyCheck | None = None) -> "Remote":
|
def override(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
host_key_check: HostKeyCheck | None = None,
|
||||||
|
private_key: Path | None = None,
|
||||||
|
) -> "Remote":
|
||||||
"""
|
"""
|
||||||
Returns a new Remote instance with the same data but with a different host_key_check.
|
Returns a new Remote instance with the same data but with a different host_key_check.
|
||||||
"""
|
"""
|
||||||
@@ -63,7 +68,7 @@ class Remote:
|
|||||||
user=self.user,
|
user=self.user,
|
||||||
command_prefix=self.command_prefix,
|
command_prefix=self.command_prefix,
|
||||||
port=self.port,
|
port=self.port,
|
||||||
private_key=self.private_key,
|
private_key=private_key if private_key is not None else self.private_key,
|
||||||
password=self.password,
|
password=self.password,
|
||||||
forward_agent=self.forward_agent,
|
forward_agent=self.forward_agent,
|
||||||
host_key_check=host_key_check
|
host_key_check=host_key_check
|
||||||
|
|||||||
@@ -192,10 +192,7 @@ def test_clan_create_api(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
machine = Machine(
|
machine = Machine(
|
||||||
name=vm_name,
|
name=vm_name, flake=clan_dir_flake, host_key_check=HostKeyCheck.NONE
|
||||||
flake=clan_dir_flake,
|
|
||||||
host_key_check=HostKeyCheck.NONE,
|
|
||||||
private_key=private_key,
|
|
||||||
)
|
)
|
||||||
machines.append(machine)
|
machines.append(machine)
|
||||||
assert len(machines) == 1
|
assert len(machines) == 1
|
||||||
@@ -203,7 +200,8 @@ def test_clan_create_api(
|
|||||||
# Invalidate cache because of new machine creation
|
# Invalidate cache because of new machine creation
|
||||||
clan_dir_flake.invalidate_cache()
|
clan_dir_flake.invalidate_cache()
|
||||||
|
|
||||||
result = check_machine_online(machine.target_host())
|
target_host = machine.target_host().override(private_key=private_key)
|
||||||
|
result = check_machine_online(target_host)
|
||||||
assert result == "Online", f"Machine {machine.name} is not online"
|
assert result == "Online", f"Machine {machine.name} is not online"
|
||||||
|
|
||||||
ssh_keys = [
|
ssh_keys = [
|
||||||
|
|||||||
Reference in New Issue
Block a user