loft-cli 0.6.3__py3-none-any.whl

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 (61) hide show
  1. loft_cli/__init__.py +3 -0
  2. loft_cli/_builtins.py +269 -0
  3. loft_cli/addons/__init__.py +12 -0
  4. loft_cli/addons/goss/__init__.py +1 -0
  5. loft_cli/addons/goss/generator.py +202 -0
  6. loft_cli/addons/goss/renderer.py +207 -0
  7. loft_cli/addons/goss/shipper.py +174 -0
  8. loft_cli/agent_installer.py +65 -0
  9. loft_cli/checks/__init__.py +0 -0
  10. loft_cli/checks/compose.py +147 -0
  11. loft_cli/checks/container.py +24 -0
  12. loft_cli/checks/http.py +30 -0
  13. loft_cli/checks/nginx.py +21 -0
  14. loft_cli/checks/ports.py +24 -0
  15. loft_cli/checks/postgres.py +21 -0
  16. loft_cli/checks/ssh.py +66 -0
  17. loft_cli/checks/wireguard.py +21 -0
  18. loft_cli/cli.py +1161 -0
  19. loft_cli/compiler/__init__.py +0 -0
  20. loft_cli/compiler/normalizer.py +420 -0
  21. loft_cli/compiler/parser.py +42 -0
  22. loft_cli/compiler/planner.py +2543 -0
  23. loft_cli/local/__init__.py +0 -0
  24. loft_cli/local/ddl/__init__.py +0 -0
  25. loft_cli/local/ddl/bootstrap_tables.py +75 -0
  26. loft_cli/local/ddl/versionize_system.py +374 -0
  27. loft_cli/local/inventory.py +449 -0
  28. loft_cli/local/inventory_db.py +255 -0
  29. loft_cli/local/keys.py +45 -0
  30. loft_cli/local/remove.py +135 -0
  31. loft_cli/local/ssh_config.py +118 -0
  32. loft_cli/local/tunnel.py +228 -0
  33. loft_cli/local/wireguard_store.py +138 -0
  34. loft_cli/logs/__init__.py +0 -0
  35. loft_cli/logs/reader.py +55 -0
  36. loft_cli/logs/writer.py +58 -0
  37. loft_cli/runtime/__init__.py +0 -0
  38. loft_cli/runtime/agent_transport.py +115 -0
  39. loft_cli/runtime/executor.py +798 -0
  40. loft_cli/runtime/fabric_transport.py +68 -0
  41. loft_cli/runtime/secret_rotation.py +99 -0
  42. loft_cli/runtime/ssh.py +147 -0
  43. loft_cli/runtime/steps/__init__.py +0 -0
  44. loft_cli/runtime/steps/backup.py +72 -0
  45. loft_cli/runtime/steps/bootstrap.py +227 -0
  46. loft_cli/runtime/steps/compose.py +43 -0
  47. loft_cli/runtime/steps/container.py +40 -0
  48. loft_cli/runtime/steps/docker.py +15 -0
  49. loft_cli/runtime/steps/file_template.py +25 -0
  50. loft_cli/runtime/steps/nginx.py +126 -0
  51. loft_cli/runtime/steps/postgres.py +101 -0
  52. loft_cli/runtime/steps/postgres_ensure.py +141 -0
  53. loft_cli/runtime/steps/systemd.py +131 -0
  54. loft_cli/runtime/steps/wireguard.py +76 -0
  55. loft_cli/runtime/transport.py +43 -0
  56. loft_cli/updater.py +208 -0
  57. loft_cli-0.6.3.dist-info/METADATA +19 -0
  58. loft_cli-0.6.3.dist-info/RECORD +61 -0
  59. loft_cli-0.6.3.dist-info/WHEEL +5 -0
  60. loft_cli-0.6.3.dist-info/entry_points.txt +5 -0
  61. loft_cli-0.6.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,24 @@
1
+ """TCP port connectivity check."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import socket
6
+
7
+ from loft_cli.checks.ssh import CheckResult
8
+
9
+
10
+ def check_port_open(host: str, port: int, timeout: int = 5) -> CheckResult:
11
+ """Return True if the TCP port is open."""
12
+ try:
13
+ with socket.create_connection((host, port), timeout=timeout):
14
+ return CheckResult(
15
+ passed=True,
16
+ check_type="port_open",
17
+ message=f"Port {host}:{port} is open",
18
+ )
19
+ except (TimeoutError, ConnectionRefusedError, OSError) as e:
20
+ return CheckResult(
21
+ passed=False,
22
+ check_type="port_open",
23
+ message=f"Port {host}:{port} is not reachable: {e}",
24
+ )
@@ -0,0 +1,21 @@
1
+ """PostgreSQL readiness check."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from loft_cli.checks.ssh import CheckResult
6
+
7
+
8
+ def check_postgres_ready(session) -> CheckResult:
9
+ """Check that PostgreSQL is ready via pg_isready."""
10
+ result = session.run("pg_isready", warn=True)
11
+ if result.ok:
12
+ return CheckResult(
13
+ passed=True,
14
+ check_type="postgres_ready",
15
+ message="PostgreSQL is ready",
16
+ )
17
+ return CheckResult(
18
+ passed=False,
19
+ check_type="postgres_ready",
20
+ message=f"PostgreSQL not ready: {result.stderr}",
21
+ )
loft_cli/checks/ssh.py ADDED
@@ -0,0 +1,66 @@
1
+ """SSH connectivity check — used by the GATE step."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import time
6
+
7
+ from pydantic import BaseModel
8
+
9
+
10
+ class CheckResult(BaseModel):
11
+ passed: bool
12
+ check_type: str
13
+ message: str
14
+ details: dict = {}
15
+
16
+
17
+ def check_ssh_reachable(
18
+ host: str,
19
+ port: int,
20
+ user: str,
21
+ key_path: str | None = None,
22
+ password: str | None = None,
23
+ timeout: int = 10,
24
+ retries: int = 5,
25
+ retry_delay: float = 1.0,
26
+ ) -> CheckResult:
27
+ """Test SSH connectivity. This is what GATE step 'verify_admin_login_on_new_port' calls.
28
+
29
+ Retries up to ``retries`` times with ``retry_delay`` seconds between attempts.
30
+ This handles the brief window after ``systemctl reload ssh`` where the daemon
31
+ has acknowledged the reload but has not yet re-bound to its port.
32
+ """
33
+ from loft_cli.runtime.ssh import SSHSession
34
+
35
+ last_message = f"SSH login failed: {user}@{host}:{port}"
36
+ for attempt in range(retries):
37
+ session = SSHSession(
38
+ host=host,
39
+ user=user,
40
+ port=port,
41
+ password=password,
42
+ key_path=key_path,
43
+ connect_timeout=timeout,
44
+ )
45
+ try:
46
+ ok = session.test_connection()
47
+ if ok:
48
+ return CheckResult(
49
+ passed=True,
50
+ check_type="ssh_reachable",
51
+ message=f"SSH login succeeded: {user}@{host}:{port}",
52
+ )
53
+ last_message = f"SSH login failed: {user}@{host}:{port}"
54
+ except Exception as e:
55
+ last_message = f"SSH connection error: {e}"
56
+ finally:
57
+ session.close()
58
+
59
+ if attempt < retries - 1:
60
+ time.sleep(retry_delay)
61
+
62
+ return CheckResult(
63
+ passed=False,
64
+ check_type="ssh_reachable",
65
+ message=last_message,
66
+ )
@@ -0,0 +1,21 @@
1
+ """WireGuard interface check."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from loft_cli.checks.ssh import CheckResult
6
+
7
+
8
+ def check_wireguard_up(session, interface: str) -> CheckResult:
9
+ """Check that the WireGuard interface is up via 'wg show'."""
10
+ result = session.run(f"wg show {interface}", sudo=True, warn=True)
11
+ if result.ok and interface in result.stdout:
12
+ return CheckResult(
13
+ passed=True,
14
+ check_type="wireguard_up",
15
+ message=f"WireGuard interface {interface} is up",
16
+ )
17
+ return CheckResult(
18
+ passed=False,
19
+ check_type="wireguard_up",
20
+ message=f"WireGuard interface {interface} is not up: {result.stderr}",
21
+ )