setup-ssh-cli 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {setup_ssh_cli-0.1.0/src/setup_ssh_cli.egg-info → setup_ssh_cli-0.2.0}/PKG-INFO +22 -2
  2. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/README.md +19 -1
  3. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/docs/usage.md +39 -0
  4. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/pyproject.toml +4 -1
  5. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/__init__.py +1 -1
  6. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/cli.py +89 -1
  7. setup_ssh_cli-0.2.0/src/setup_ssh/dashboard.py +175 -0
  8. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/fleet.py +33 -24
  9. setup_ssh_cli-0.2.0/src/setup_ssh/local_setup.py +104 -0
  10. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/render.py +5 -1
  11. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/state.py +14 -3
  12. setup_ssh_cli-0.2.0/src/setup_ssh/status.py +66 -0
  13. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/templates/posix.sh +13 -2
  14. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/templates/windows.ps1 +12 -2
  15. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0/src/setup_ssh_cli.egg-info}/PKG-INFO +22 -2
  16. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh_cli.egg-info/SOURCES.txt +5 -0
  17. setup_ssh_cli-0.2.0/src/setup_ssh_cli.egg-info/requires.txt +4 -0
  18. setup_ssh_cli-0.2.0/tests/test_dashboard.py +144 -0
  19. setup_ssh_cli-0.2.0/tests/test_local_setup.py +52 -0
  20. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_posix.py +34 -1
  21. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/uv.lock +106 -2
  22. setup_ssh_cli-0.1.0/src/setup_ssh_cli.egg-info/requires.txt +0 -1
  23. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/CONTRIBUTING.md +0 -0
  24. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/LICENSE +0 -0
  25. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/MANIFEST.in +0 -0
  26. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/SECURITY.md +0 -0
  27. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/dev.ps1 +0 -0
  28. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/dev.sh +0 -0
  29. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/docs/development.md +0 -0
  30. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/docs/publishing.md +0 -0
  31. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/docs/troubleshooting.md +0 -0
  32. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/scripts/dev.py +0 -0
  33. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/setup.cfg +0 -0
  34. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/__main__.py +0 -0
  35. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh/transport.py +0 -0
  36. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh_cli.egg-info/dependency_links.txt +0 -0
  37. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh_cli.egg-info/entry_points.txt +0 -0
  38. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/src/setup_ssh_cli.egg-info/top_level.txt +0 -0
  39. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_cli.py +0 -0
  40. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_dev.py +0 -0
  41. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_fleet_integration.py +0 -0
  42. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_powershell.py +0 -0
  43. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_state.py +0 -0
  44. {setup_ssh_cli-0.1.0 → setup_ssh_cli-0.2.0}/tests/test_transport.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: setup-ssh-cli
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Set up passwordless SSH between your Linux, Windows, and macOS devices.
5
5
  Author: beepboopbit
6
6
  License-Expression: MIT
@@ -20,8 +20,14 @@ Requires-Python: >=3.11
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: paramiko<5,>=3.4
23
+ Provides-Extra: dashboard
24
+ Requires-Dist: textual>=1; extra == "dashboard"
23
25
  Dynamic: license-file
24
26
 
27
+ <p align="center">
28
+ <img src="assets/icon.png" alt="setup-ssh icon" width="160" height="160">
29
+ </p>
30
+
25
31
  # setup-ssh
26
32
 
27
33
  I made this because my lazy ass got tired of setting up SSH keys and remembering
@@ -75,7 +81,18 @@ key, and you don't need to run setup again just to SSH into something.
75
81
 
76
82
  ## Add another computer
77
83
 
78
- Enable SSH on it, then run these from your original setup computer:
84
+ On a Linux target with systemd and UFW, run the guided preparation locally as
85
+ your normal user. Repeat `--allow-from` for each trusted peer source IP.
86
+
87
+ ```sh
88
+ setup-ssh prepare-local --allow-from 10.10.0.20 --allow-from 10.10.0.23
89
+ ```
90
+
91
+ The command previews the changes and asks before using sudo to generate missing
92
+ host keys, enable OpenSSH, and add the specified UFW rules. Use `--dry-run` to
93
+ preview without invoking sudo. For other platforms and firewalls, see
94
+ `setup-ssh doctor`. Once SSH is reachable, run these from your original setup
95
+ computer:
79
96
 
80
97
  ```sh
81
98
  setup-ssh add --no-sync
@@ -90,6 +107,7 @@ does both steps for you.
90
107
 
91
108
  ```sh
92
109
  setup-ssh list # saved devices
110
+ setup-ssh dashboard # live device and connection status (optional extra)
93
111
  setup-ssh sync --skip-offline # update the ones that are online
94
112
  setup-ssh --batch sync --skip-offline # same, with no password/trust prompts
95
113
  setup-ssh check # test every direction; all devices online
@@ -98,6 +116,8 @@ setup-ssh doctor --os windows # SSH setup instructions for an OS
98
116
  setup-ssh --help
99
117
  ```
100
118
 
119
+ [Install the dashboard and copy an inventory to another enrolled device](docs/usage.md#dashboard-and-portable-inventory).
120
+
101
121
  Removing a device needs to reach the other computers to revoke its access there.
102
122
  If some are offline, sync them later.
103
123
 
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="assets/icon.png" alt="setup-ssh icon" width="160" height="160">
3
+ </p>
4
+
1
5
  # setup-ssh
2
6
 
3
7
  I made this because my lazy ass got tired of setting up SSH keys and remembering
@@ -51,7 +55,18 @@ key, and you don't need to run setup again just to SSH into something.
51
55
 
52
56
  ## Add another computer
53
57
 
54
- Enable SSH on it, then run these from your original setup computer:
58
+ On a Linux target with systemd and UFW, run the guided preparation locally as
59
+ your normal user. Repeat `--allow-from` for each trusted peer source IP.
60
+
61
+ ```sh
62
+ setup-ssh prepare-local --allow-from 10.10.0.20 --allow-from 10.10.0.23
63
+ ```
64
+
65
+ The command previews the changes and asks before using sudo to generate missing
66
+ host keys, enable OpenSSH, and add the specified UFW rules. Use `--dry-run` to
67
+ preview without invoking sudo. For other platforms and firewalls, see
68
+ `setup-ssh doctor`. Once SSH is reachable, run these from your original setup
69
+ computer:
55
70
 
56
71
  ```sh
57
72
  setup-ssh add --no-sync
@@ -66,6 +81,7 @@ does both steps for you.
66
81
 
67
82
  ```sh
68
83
  setup-ssh list # saved devices
84
+ setup-ssh dashboard # live device and connection status (optional extra)
69
85
  setup-ssh sync --skip-offline # update the ones that are online
70
86
  setup-ssh --batch sync --skip-offline # same, with no password/trust prompts
71
87
  setup-ssh check # test every direction; all devices online
@@ -74,6 +90,8 @@ setup-ssh doctor --os windows # SSH setup instructions for an OS
74
90
  setup-ssh --help
75
91
  ```
76
92
 
93
+ [Install the dashboard and copy an inventory to another enrolled device](docs/usage.md#dashboard-and-portable-inventory).
94
+
77
95
  Removing a device needs to reach the other computers to revoke its access there.
78
96
  If some are offline, sync them later.
79
97
 
@@ -259,3 +259,42 @@ key is missing, then re-enroll and sync. Setup deliberately refuses to silently
259
259
  replace an orphaned or changed key.
260
260
 
261
261
  See [troubleshooting](troubleshooting.md) for common failures and recovery steps.
262
+
263
+ ## Dashboard and portable inventory
264
+
265
+ Install the optional dashboard dependencies with
266
+ `uv tool install "setup-ssh-cli[dashboard]"`, or use
267
+ `uv run --extra dashboard setup-ssh dashboard` from a repository checkout.
268
+
269
+ ```sh
270
+ setup-ssh dashboard
271
+ ```
272
+
273
+ The Connections tab shows one result per source and destination. The Devices
274
+ tab shows whether the dashboard can reach each source and use it for checks.
275
+ Highlight a row or cell for the latest result, timestamp, and error detail.
276
+ Press `r` to refresh and `q` to quit.
277
+
278
+ Checks use batch SSH with strict host verification. A source that cannot be
279
+ opened has untested outgoing connections. Other sources still try that device
280
+ as a destination if it has completed setup. The dashboard leaves SSH files
281
+ and the inventory unchanged.
282
+
283
+ To view the same fleet on an already enrolled computer, export the inventory,
284
+ transfer the JSON using a method you trust, then import it on the receiving
285
+ account. For example, to open the dashboard on `mac`:
286
+
287
+ ```sh
288
+ setup-ssh export fleet.json
289
+ scp fleet.json mac:~/
290
+ # Run these two commands on mac:
291
+ setup-ssh import ~/fleet.json --local mac
292
+ setup-ssh dashboard
293
+ ```
294
+
295
+ The export includes public keys, verified host keys, and network details.
296
+ Private keys stay on each enrolled computer. Import creates a read-only
297
+ inventory for viewing and checking the fleet. Use the original inventory for
298
+ `add`, `remove`, and `sync`. To update the copy, export to a fresh file and
299
+ import it again. Import can replace a read-only copy of the same fleet. Use
300
+ `--config` before the command to choose a separate inventory file if needed.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "setup-ssh-cli"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "Set up passwordless SSH between your Linux, Windows, and macOS devices."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -24,6 +24,9 @@ classifiers = [
24
24
  ]
25
25
  dependencies = ["paramiko>=3.4,<5"]
26
26
 
27
+ [project.optional-dependencies]
28
+ dashboard = ["textual>=1"]
29
+
27
30
  [project.urls]
28
31
  Repository = "https://github.com/BeepBoopBit/setup-ssh"
29
32
  Issues = "https://github.com/BeepBoopBit/setup-ssh/issues"
@@ -1,3 +1,3 @@
1
1
  """Manage a small, cross-platform group of SSH devices."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.2.0"
@@ -4,12 +4,14 @@ import argparse
4
4
  import getpass
5
5
  import socket
6
6
  import sys
7
+ from dataclasses import replace
7
8
  from pathlib import Path
8
9
 
9
10
  import paramiko
10
11
 
11
12
  from . import __version__
12
13
  from .fleet import Check, Fleet
14
+ from .local_setup import prepare_local
13
15
  from .state import Device, Inventory, SetupError, default_path
14
16
  from .transport import (
15
17
  Connector,
@@ -66,6 +68,22 @@ def make_parser() -> argparse.ArgumentParser:
66
68
  parser.add_argument("--batch", action="store_true", help="No password or host-trust prompts")
67
69
  commands = parser.add_subparsers(dest="command", required=True)
68
70
  commands.add_parser("init", help="Guided enrollment and setup for a new group")
71
+ prepare = commands.add_parser(
72
+ "prepare-local", help="Enable local OpenSSH and allow peers through UFW"
73
+ )
74
+ prepare.add_argument(
75
+ "--allow-from",
76
+ action="append",
77
+ default=[],
78
+ metavar="IP",
79
+ help="Peer source IP (repeat for each address)",
80
+ )
81
+ prepare.add_argument(
82
+ "--port", type=int, default=22, help="Existing sshd port to allow (default: 22)"
83
+ )
84
+ prepare.add_argument(
85
+ "--dry-run", action="store_true", help="Show commands without running sudo"
86
+ )
69
87
  add = commands.add_parser("add", help="Enroll a device, then synchronize the group")
70
88
  add.add_argument("--name")
71
89
  add.add_argument("--host", help="LAN or NetBird address")
@@ -85,6 +103,12 @@ def make_parser() -> argparse.ArgumentParser:
85
103
  "--dry-run", action="store_true", help="Show the saved plan without connecting"
86
104
  )
87
105
  commands.add_parser("check", help="Test all connection directions without editing SSH files")
106
+ commands.add_parser("dashboard", help="Inspect devices and live peer SSH connections")
107
+ export = commands.add_parser("export", help="Export a portable public inventory")
108
+ export.add_argument("file", type=Path)
109
+ import_command = commands.add_parser("import", help="Import a read-only fleet inventory")
110
+ import_command.add_argument("file", type=Path)
111
+ import_command.add_argument("--local", required=True, help="Alias of this enrolled account")
88
112
  commands.add_parser("list", help="List enrolled devices")
89
113
  commands.add_parser("plan", help="Show the saved plan without connecting or modifying files")
90
114
  remove = commands.add_parser("remove", help="Remove a device and revoke its key on peers")
@@ -115,12 +139,45 @@ def report(checks: list[Check]) -> int:
115
139
  return 1 if failures else 0
116
140
 
117
141
 
142
+ def import_inventory(
143
+ path: Path, existing: Inventory, source: Path, local: str, batch: bool
144
+ ) -> None:
145
+ portable = Inventory.load(source.expanduser())
146
+ if not portable.devices:
147
+ raise SetupError("The source file has no enrolled devices.")
148
+ selected = portable.find(local)
149
+ if not current_account_matches(selected.user):
150
+ raise SetupError(f"Run the import as the enrolled account {selected.user}.")
151
+ if selected.platform not in {"auto", local_platform()}:
152
+ raise SetupError(f"{selected.name} is enrolled as {selected.platform}.")
153
+ if not selected.public_key or not selected.host_key:
154
+ raise SetupError(f"Finish syncing {selected.name} on the management machine before import.")
155
+ if path.exists() and (not existing.read_only or existing.group_id != portable.group_id):
156
+ raise SetupError(
157
+ "Choose a different --config path. The destination contains another inventory."
158
+ )
159
+ imported = replace(
160
+ portable,
161
+ devices=[replace(device, local=device.id == selected.id) for device in portable.devices],
162
+ version=2,
163
+ )
164
+ print(f"Read-only inventory for {selected.name} at {path}")
165
+ for device in imported.devices:
166
+ print(f" {device.name:16} {device.user}@{device.host}:{device.port}")
167
+ if batch or confirm("Save this inventory?"):
168
+ imported.save(path, overwrite=existing.read_only)
169
+ print("Inventory saved. Run setup-ssh dashboard to inspect connections.")
170
+
171
+
118
172
  def main(argv: list[str] | None = None) -> int:
119
173
  parser = make_parser()
120
174
  args = parser.parse_args(argv)
121
175
  if not 1 <= args.timeout <= 300:
122
176
  parser.error("--timeout must be between 1 and 300 seconds")
123
177
  try:
178
+ if args.command == "prepare-local":
179
+ prepare_local(args.allow_from, args.port, args.dry_run, args.batch, confirm)
180
+ return 0
124
181
  if args.command == "doctor":
125
182
  print("\n".join(diagnostics()))
126
183
  print("\n" + doctor_instructions(args.os or local_platform()))
@@ -132,6 +189,37 @@ def main(argv: list[str] | None = None) -> int:
132
189
  return 0
133
190
  path = args.config.expanduser().absolute()
134
191
  inventory = Inventory.load(path)
192
+ if inventory.read_only and args.command in {"init", "add", "sync", "remove"}:
193
+ raise SetupError(
194
+ "This inventory is read-only. Run management commands on the original machine."
195
+ )
196
+ if args.command == "import":
197
+ import_inventory(path, inventory, args.file, args.local, args.batch)
198
+ return 0
199
+ if args.command == "export":
200
+ if not inventory.devices:
201
+ raise SetupError("There are no enrolled devices to export.")
202
+ portable = replace(
203
+ inventory,
204
+ devices=[replace(device, local=False) for device in inventory.devices],
205
+ version=2,
206
+ )
207
+ portable.save(args.file.expanduser(), overwrite=False)
208
+ print(f"Exported public inventory to {args.file}.")
209
+ return 0
210
+ if args.command == "dashboard":
211
+ try:
212
+ from .dashboard import Dashboard
213
+ except ModuleNotFoundError as exc:
214
+ if exc.name != "textual":
215
+ raise
216
+ raise SetupError(
217
+ 'Install the dashboard extra with uv tool install "setup-ssh-cli[dashboard]".'
218
+ ) from exc
219
+ if not sys.stdin.isatty() or not sys.stdout.isatty():
220
+ raise SetupError("The dashboard requires an interactive terminal.")
221
+ Dashboard(path, args.timeout).run()
222
+ return 0
135
223
  if args.command == "list":
136
224
  if not inventory.devices:
137
225
  print("No devices yet. Run setup-ssh init.")
@@ -151,7 +239,7 @@ def main(argv: list[str] | None = None) -> int:
151
239
  connector = Connector(
152
240
  inventory,
153
241
  timeout=args.timeout,
154
- batch=args.batch,
242
+ batch=args.batch or inventory.read_only,
155
243
  confirm=confirm,
156
244
  save=lambda: inventory.save(path),
157
245
  )
@@ -0,0 +1,175 @@
1
+ """Textual interface for inspecting an enrolled fleet."""
2
+
3
+ from contextlib import closing
4
+ from pathlib import Path
5
+
6
+ from rich.text import Text
7
+ from textual import work
8
+ from textual.app import App, ComposeResult
9
+ from textual.message import Message
10
+ from textual.widgets import DataTable, Footer, Label, TabbedContent, TabPane
11
+ from textual.worker import Worker, WorkerState, get_current_worker
12
+
13
+ from .state import Inventory, SetupError
14
+ from .status import Observation, inspect
15
+
16
+
17
+ class Observed(Message):
18
+ def __init__(self, observation: Observation):
19
+ super().__init__()
20
+ self.observation = observation
21
+
22
+
23
+ class Dashboard(App):
24
+ TITLE = "setup-ssh dashboard"
25
+ BINDINGS = [("r", "refresh_fleet", "Refresh"), ("q", "quit", "Quit")]
26
+ CSS = """
27
+ TabbedContent { height: 1fr; }
28
+ DataTable { height: 1fr; }
29
+ #summary { padding: 0 1; }
30
+ #detail { padding: 0 1; max-height: 6; overflow-y: auto; }
31
+ """
32
+
33
+ def __init__(self, path: Path, timeout: int):
34
+ super().__init__()
35
+ self.path = path
36
+ self.timeout = timeout
37
+ self.inventory = Inventory.load(path)
38
+ self.results: dict[tuple[str, str | None], Observation] = {}
39
+ self.selection: tuple[str, str | None] | None = None
40
+ self.probe: Worker | None = None
41
+
42
+ def compose(self) -> ComposeResult:
43
+ yield Label(id="summary")
44
+ with TabbedContent():
45
+ with TabPane("Connections", id="connections"):
46
+ yield DataTable(id="matrix", cursor_type="cell", fixed_columns=1)
47
+ with TabPane("Devices", id="devices"):
48
+ yield DataTable(id="hosts", cursor_type="row")
49
+ yield Label(id="detail")
50
+ yield Footer()
51
+
52
+ def on_mount(self) -> None:
53
+ self.action_refresh_fleet()
54
+
55
+ def action_refresh_fleet(self) -> None:
56
+ if self.probe is not None:
57
+ return
58
+ summary = self.query_one("#summary", Label)
59
+ try:
60
+ self.inventory = Inventory.load(self.path)
61
+ except SetupError as exc:
62
+ summary.update(Text(str(exc)))
63
+ return
64
+ devices = self.inventory.devices
65
+ matrix = self.query_one("#matrix", DataTable)
66
+ hosts = self.query_one("#hosts", DataTable)
67
+ matrix.clear(columns=True)
68
+ hosts.clear(columns=True)
69
+ matrix.add_column("From / To", key="source")
70
+ hosts.add_columns("Alias", "Account", "Status")
71
+ for device in devices:
72
+ matrix.add_column(device.name, key=device.id)
73
+ for device in devices:
74
+ matrix.add_row(
75
+ device.name,
76
+ *("—" if peer.id == device.id else "Pending" for peer in devices),
77
+ key=device.id,
78
+ )
79
+ account = f"{device.user}@{device.host}:{device.port}"
80
+ hosts.add_row(device.name, Text(account), "Pending", key=device.id)
81
+ self.results.clear()
82
+ self.selection = (devices[0].id, None) if devices else None
83
+ self.show_detail()
84
+ if not devices:
85
+ summary.update("No enrolled devices")
86
+ self.query_one("#detail", Label).update(
87
+ Text(
88
+ f"Inventory: {self.path}\n"
89
+ "Run setup-ssh init to set up a fleet, or import an existing inventory.\n"
90
+ "Press r after saving the inventory."
91
+ )
92
+ )
93
+ return
94
+ summary.update("Checking devices and SSH connections…")
95
+ self.probe = self.run_checks(self.inventory)
96
+
97
+ @work(thread=True, exit_on_error=False)
98
+ def run_checks(self, inventory: Inventory) -> None:
99
+ worker = get_current_worker()
100
+ with closing(inspect(inventory, self.timeout)) as observations:
101
+ for observation in observations:
102
+ if worker.is_cancelled:
103
+ break
104
+ self.post_message(Observed(observation))
105
+
106
+ def on_observed(self, message: Observed) -> None:
107
+ result = message.observation
108
+ self.results[result.source, result.destination] = result
109
+ color = {
110
+ "OK": "green",
111
+ "Ready": "green",
112
+ "Failed": "red",
113
+ "Unreachable": "red",
114
+ "Blocked": "yellow",
115
+ "Setup pending": "yellow",
116
+ "Untested": "dim",
117
+ }[result.status]
118
+ value = Text(result.status, style=color)
119
+ if result.destination is None:
120
+ table = self.query_one("#hosts", DataTable)
121
+ table.update_cell_at((table.get_row_index(result.source), 2), value)
122
+ else:
123
+ self.query_one("#matrix", DataTable).update_cell(
124
+ result.source, result.destination, value
125
+ )
126
+ if self.selection == (result.source, result.destination):
127
+ self.show_detail()
128
+
129
+ def on_worker_state_changed(self, event: Worker.StateChanged) -> None:
130
+ if event.worker is not self.probe:
131
+ return
132
+ summary = self.query_one("#summary", Label)
133
+ if event.state == WorkerState.SUCCESS:
134
+ self.probe = None
135
+ checks = [result for result in self.results.values() if result.destination is not None]
136
+ passed = sum(result.status == "OK" for result in checks)
137
+ failed = sum(result.status == "Failed" for result in checks)
138
+ summary.update(
139
+ f"{passed} passed · {failed} failed · {len(checks) - passed - failed} untested"
140
+ )
141
+ elif event.state == WorkerState.ERROR:
142
+ self.probe = None
143
+ summary.update(Text(f"Refresh interrupted. {event.worker.error}"))
144
+
145
+ def on_data_table_cell_highlighted(self, event: DataTable.CellHighlighted) -> None:
146
+ source, destination = event.cell_key
147
+ self.selection = source.value, None if destination.value == "source" else destination.value
148
+ self.show_detail()
149
+
150
+ def on_data_table_row_highlighted(self, event: DataTable.RowHighlighted) -> None:
151
+ self.selection = event.row_key.value, None
152
+ self.show_detail()
153
+
154
+ def show_detail(self) -> None:
155
+ detail = self.query_one("#detail", Label)
156
+ if self.selection is None:
157
+ detail.update("")
158
+ return
159
+ source, destination = self.selection
160
+ names = {device.id: device.name for device in self.inventory.devices}
161
+ if source not in names or (destination is not None and destination not in names):
162
+ detail.update("")
163
+ return
164
+ if source == destination:
165
+ detail.update("Each device checks the other peers.")
166
+ return
167
+ title = names[source] if destination is None else f"{names[source]} → {names[destination]}"
168
+ result = self.results.get(self.selection)
169
+ if result is None:
170
+ detail.update(Text(f"{title} · Waiting for refresh"))
171
+ return
172
+ message = "".join(
173
+ char if char.isprintable() or char == "\n" else " " for char in result.detail
174
+ )
175
+ detail.update(Text(f"{title} · {result.status} · {result.at:%H:%M:%S %Z}\n{message}"))
@@ -25,7 +25,7 @@ class Fleet:
25
25
  def __init__(
26
26
  self,
27
27
  inventory: Inventory,
28
- path: Path,
28
+ path: Path | None,
29
29
  connector: Connector,
30
30
  output: Callable[[str], None] = print,
31
31
  ):
@@ -35,6 +35,8 @@ class Fleet:
35
35
  self.output = output
36
36
 
37
37
  def save(self) -> None:
38
+ if self.path is None or self.inventory.read_only:
39
+ raise SetupError("This inventory is read-only.")
38
40
  self.inventory.save(self.path)
39
41
 
40
42
  def connect_all(self, *, skip_offline: bool = False) -> dict[str, Session]:
@@ -65,6 +67,8 @@ class Fleet:
65
67
  raise
66
68
 
67
69
  def sync(self, *, check: bool = True, skip_offline: bool = False) -> list[Check]:
70
+ if self.path is None or self.inventory.read_only:
71
+ raise SetupError("This inventory is read-only.")
68
72
  if not self.inventory.devices:
69
73
  raise SetupError("No devices are enrolled. Run setup-ssh init or add first.")
70
74
  sessions = self.connect_all(skip_offline=skip_offline)
@@ -136,32 +140,35 @@ class Fleet:
136
140
  for destination in available:
137
141
  if source.id == destination.id:
138
142
  continue
139
- try:
140
- result = sessions[source.id].run(
141
- script(
142
- self.inventory,
143
- source,
144
- "check",
145
- destination=destination,
146
- timeout=self.connector.timeout,
147
- ),
148
- timeout=self.connector.timeout + 15,
149
- )
150
- ok = result.code == 0 and "setup-ssh-ok" in result.stdout.splitlines()
151
- detail = (
152
- ""
153
- if ok
154
- else (result.stderr or result.stdout or f"exit {result.code}").strip()
155
- )
156
- except (SetupError, OSError, paramiko.SSHException) as exc:
157
- ok, detail = False, str(exc)
158
- check = Check(source.name, destination.name, ok, detail)
143
+ check = self.check_direction(sessions[source.id], source, destination)
159
144
  checks.append(check)
160
- self.output(f" {source.name} -> {destination.name}: {'OK' if ok else 'FAILED'}")
161
- if detail:
162
- self.output(f" {detail}")
145
+ self.output(
146
+ f" {source.name} -> {destination.name}: {'OK' if check.ok else 'FAILED'}"
147
+ )
148
+ if check.detail:
149
+ self.output(f" {check.detail}")
163
150
  return checks
164
151
 
152
+ def check_direction(
153
+ self, session: Session, source: Device, destination: Device, *, normal_alias: bool = False
154
+ ) -> Check:
155
+ try:
156
+ result = session.run(
157
+ script(
158
+ self.inventory,
159
+ source,
160
+ "check-alias" if normal_alias else "check",
161
+ destination=destination,
162
+ timeout=self.connector.timeout,
163
+ ),
164
+ timeout=self.connector.timeout + 15,
165
+ )
166
+ ok = result.code == 0 and "setup-ssh-ok" in result.stdout.splitlines()
167
+ detail = "" if ok else (result.stderr or result.stdout or f"exit {result.code}").strip()
168
+ except (SetupError, OSError, EOFError, paramiko.SSHException) as exc:
169
+ ok, detail = False, str(exc)
170
+ return Check(source.name, destination.name, ok, detail)
171
+
165
172
  def check(self) -> list[Check]:
166
173
  if len(self.inventory.devices) < 2:
167
174
  raise SetupError("Add at least two devices first.")
@@ -175,6 +182,8 @@ class Fleet:
175
182
  session.close()
176
183
 
177
184
  def remove(self, device: Device) -> list[str]:
185
+ if self.path is None or self.inventory.read_only:
186
+ raise SetupError("This inventory is read-only.")
178
187
  # Save revocation intent first: a future sync must never reauthorize this device.
179
188
  self.inventory.devices.remove(device)
180
189
  self.save()