3"""Install or render the declaration-derived fleet SSH configuration."""
5from __future__
import annotations
7from pathlib
import Path
10import fleet_reach
as fr
13def _ensure_include(config: Path) -> str:
14 """Put the generated fragment's Include line first in one SSH config."""
16 "# ra8-firmware: the CI fleet's machines, GENERATED from infra/fleet.yml.\n"
17 "# Refresh with `just infra::ssh_config`.\n"
18 f
"{fr.SSH_INCLUDE_LINE}\n"
20 if not config.exists():
21 config.write_text(header, encoding=
"utf-8")
23 return f
"created {config} with the include line"
24 existing = config.read_text(encoding=
"utf-8")
25 if any(line.strip() == fr.SSH_INCLUDE_LINE
for line
in existing.splitlines()):
26 return f
"{config} already includes it"
27 config.write_text(f
"{header}\n{existing}", encoding=
"utf-8")
28 return f
"prepended the include line to {config}"
31def command(data: dict[str, Any], *, install: bool) -> int:
32 """Print or install the fleet's generated SSH config fragment."""
33 body = fr.render_ssh_config(data)
37 ssh_dir = Path.home() /
".ssh"
38 ssh_dir.mkdir(mode=0o700, parents=
True, exist_ok=
True)
39 fragment = ssh_dir / fr.SSH_FRAGMENT_NAME
40 fragment.write_text(body, encoding=
"utf-8")
42 print(f
"wrote {fragment} ({len(data['hosts'])} host(s))")
43 print(_ensure_include(ssh_dir /
"config"))