clan-lib: machines.py: Remove host_key attribute
This commit is contained in:
@@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from clan_cli.facts import public_modules as facts_public_modules
|
||||
from clan_cli.facts import secret_modules as facts_secret_modules
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
from clan_cli.vars._types import StoreBase
|
||||
|
||||
from clan_lib.api import API
|
||||
@@ -33,8 +32,6 @@ class Machine:
|
||||
|
||||
nix_options: list[str] = field(default_factory=list)
|
||||
|
||||
host_key_check: HostKeyCheck = HostKeyCheck.STRICT
|
||||
|
||||
def get_inv_machine(self) -> "InventoryMachine":
|
||||
return get_machine(self.flake, self.name)
|
||||
|
||||
@@ -149,9 +146,7 @@ class Machine:
|
||||
description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.",
|
||||
)
|
||||
data = remote.data
|
||||
return data.override(
|
||||
host_key_check=self.host_key_check,
|
||||
)
|
||||
return data
|
||||
|
||||
def build_host(self) -> Remote | None:
|
||||
"""
|
||||
@@ -162,9 +157,7 @@ class Machine:
|
||||
|
||||
if remote:
|
||||
data = remote.data
|
||||
return data.override(
|
||||
host_key_check=self.host_key_check,
|
||||
)
|
||||
return data
|
||||
|
||||
return None
|
||||
|
||||
@@ -266,9 +259,7 @@ def get_host(
|
||||
|
||||
return RemoteSource(
|
||||
data=Remote.from_deployment_address(
|
||||
machine_name=machine.name,
|
||||
address=host_str,
|
||||
host_key_check=machine.host_key_check,
|
||||
machine_name=machine.name, address=host_str
|
||||
),
|
||||
source=source,
|
||||
)
|
||||
|
||||
@@ -3,8 +3,6 @@ import urllib.parse
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -15,7 +13,6 @@ def parse_deployment_address(
|
||||
*,
|
||||
machine_name: str,
|
||||
address: str,
|
||||
host_key_check: HostKeyCheck,
|
||||
forward_agent: bool = True,
|
||||
meta: dict[str, Any] | None = None,
|
||||
private_key: Path | None = None,
|
||||
@@ -73,7 +70,6 @@ def parse_deployment_address(
|
||||
port=port,
|
||||
private_key=private_key,
|
||||
password=password,
|
||||
host_key_check=host_key_check,
|
||||
command_prefix=machine_name,
|
||||
forward_agent=forward_agent,
|
||||
ssh_options=options,
|
||||
|
||||
@@ -91,7 +91,6 @@ class Remote:
|
||||
*,
|
||||
machine_name: str,
|
||||
address: str,
|
||||
host_key_check: HostKeyCheck,
|
||||
forward_agent: bool = True,
|
||||
private_key: Path | None = None,
|
||||
password: str | None = None,
|
||||
@@ -104,7 +103,6 @@ class Remote:
|
||||
return parse_deployment_address(
|
||||
machine_name=machine_name,
|
||||
address=address,
|
||||
host_key_check=host_key_check,
|
||||
forward_agent=forward_agent,
|
||||
private_key=private_key,
|
||||
password=password,
|
||||
|
||||
@@ -114,8 +114,7 @@ def test_parse_deployment_address(
|
||||
result = Remote.from_deployment_address(
|
||||
machine_name=machine_name,
|
||||
address=test_addr,
|
||||
host_key_check=HostKeyCheck.STRICT,
|
||||
)
|
||||
).override(host_key_check=HostKeyCheck.STRICT)
|
||||
|
||||
if expected_exception:
|
||||
return
|
||||
@@ -132,8 +131,8 @@ def test_parse_deployment_address(
|
||||
|
||||
def test_parse_ssh_options() -> None:
|
||||
addr = "root@example.com:2222?IdentityFile=/path/to/private/key&StrictRemoteKeyChecking=yes"
|
||||
host = Remote.from_deployment_address(
|
||||
machine_name="foo", address=addr, host_key_check=HostKeyCheck.STRICT
|
||||
host = Remote.from_deployment_address(machine_name="foo", address=addr).override(
|
||||
host_key_check=HostKeyCheck.STRICT
|
||||
)
|
||||
assert host.address == "example.com"
|
||||
assert host.port == 2222
|
||||
|
||||
@@ -191,16 +191,16 @@ def test_clan_create_api(
|
||||
clan_dir_flake, inv_machine, target_host=f"{host.target}:{ssh_port_var}"
|
||||
)
|
||||
)
|
||||
machine = Machine(
|
||||
name=vm_name, flake=clan_dir_flake, host_key_check=HostKeyCheck.NONE
|
||||
)
|
||||
machine = Machine(name=vm_name, flake=clan_dir_flake)
|
||||
machines.append(machine)
|
||||
assert len(machines) == 1
|
||||
|
||||
# Invalidate cache because of new machine creation
|
||||
clan_dir_flake.invalidate_cache()
|
||||
|
||||
target_host = machine.target_host().override(private_key=private_key)
|
||||
target_host = machine.target_host().override(
|
||||
private_key=private_key, host_key_check=HostKeyCheck.NONE
|
||||
)
|
||||
result = check_machine_online(target_host)
|
||||
assert result == "Online", f"Machine {machine.name} is not online"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user