Merge pull request 'configure ControlMaster and ControlPath for SSH connections' (#3485) from control-master into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3485
This commit is contained in:
@@ -41,6 +41,22 @@ class Host:
|
|||||||
self.command_prefix = self.host
|
self.command_prefix = self.host
|
||||||
if not self.user:
|
if not self.user:
|
||||||
self.user = "root"
|
self.user = "root"
|
||||||
|
home = Path.home()
|
||||||
|
if home.exists() and os.access(home, os.W_OK):
|
||||||
|
control_path = home / ".ssh"
|
||||||
|
if not control_path.exists():
|
||||||
|
try:
|
||||||
|
control_path.mkdir(exist_ok=True)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.ssh_options["ControlMaster"] = "auto"
|
||||||
|
# Can we make this a temporary directory?
|
||||||
|
self.ssh_options["ControlPath"] = str(
|
||||||
|
control_path / "clan-%h-%p-%r"
|
||||||
|
)
|
||||||
|
# We use a short ttl because we want to mainly re-use the connection during the cli run
|
||||||
|
self.ssh_options["ControlPersist"] = "1m"
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.target
|
return self.target
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ def test_parse_deployment_address(
|
|||||||
assert result.user == expected_user or (
|
assert result.user == expected_user or (
|
||||||
expected_user == "" and result.user == "root"
|
expected_user == "" and result.user == "root"
|
||||||
)
|
)
|
||||||
assert result.ssh_options == expected_options
|
|
||||||
|
for key, value in expected_options.items():
|
||||||
|
assert result.ssh_options[key] == value
|
||||||
|
|
||||||
|
|
||||||
def test_parse_ssh_options() -> None:
|
def test_parse_ssh_options() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user