hexaqueue-cli 0.10.0__tar.gz → 0.12.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.
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/PKG-INFO +4 -1
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/pyproject.toml +4 -1
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/pyproject.toml.orig +4 -1
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/adapters/auth_rotation.py +253 -0
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/adapters/dashboard_tunnel.py +158 -0
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/adapters/local.py +700 -0
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/adapters/oci_pool.py +99 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/adapters/presenter.py +269 -2
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/commands/auth.py +75 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/cluster.py +191 -1
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/commands/collateral.py +468 -0
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/commands/dashboard.py +150 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/node.py +70 -7
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/run.py +106 -33
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/suite.py +8 -5
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/domain/session.py +74 -1
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/infra/options.py +22 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/main.py +192 -40
- hexaqueue_cli-0.12.0/src/hexaqueue_cli/ports/client.py +415 -0
- hexaqueue_cli-0.10.0/src/hexaqueue_cli/adapters/local.py +0 -339
- hexaqueue_cli-0.10.0/src/hexaqueue_cli/commands/collateral.py +0 -127
- hexaqueue_cli-0.10.0/src/hexaqueue_cli/ports/client.py +0 -168
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/README.md +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/__init__.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/adapters/__init__.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/__init__.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/admin.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/mcp.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/scanner.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/server.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/commands/workflow.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/domain/__init__.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/domain/models.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/domain/options.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/domain/parser.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/infra/__init__.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/infra/bootstrap.py +0 -0
- {hexaqueue_cli-0.10.0 → hexaqueue_cli-0.12.0}/src/hexaqueue_cli/ports/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexaqueue-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Hexaqueue CLI - Modern developer and operator terminal interface
|
|
5
5
|
Author: Richard West
|
|
6
6
|
Author-email: Richard West <dopplereffect.us@gmail.com>
|
|
@@ -9,10 +9,13 @@ Requires-Dist: hexaqueue-core
|
|
|
9
9
|
Requires-Dist: hexaqueue-server
|
|
10
10
|
Requires-Dist: hexaqueue-worker
|
|
11
11
|
Requires-Dist: hexaqueue-workflow
|
|
12
|
+
Requires-Dist: hexastack-auth>=0.11.0
|
|
12
13
|
Requires-Dist: hexastack-cli>=0.11.0
|
|
13
14
|
Requires-Dist: hexastack-core>=0.11.0
|
|
14
15
|
Requires-Dist: hexastack-cqrs>=0.11.0
|
|
15
16
|
Requires-Dist: hexastack-grpc>=0.11.0
|
|
17
|
+
Requires-Dist: httpx>=0.27.0
|
|
18
|
+
Requires-Dist: pydantic>=2.0.0
|
|
16
19
|
Requires-Dist: pyyaml>=6.0.2
|
|
17
20
|
Requires-Dist: rich>=13.8.0
|
|
18
21
|
Requires-Dist: typer>=0.15.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hexaqueue-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.0"
|
|
4
4
|
description = "Hexaqueue CLI - Modern developer and operator terminal interface"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -10,10 +10,13 @@ dependencies = [
|
|
|
10
10
|
"hexaqueue-server",
|
|
11
11
|
"hexaqueue-worker",
|
|
12
12
|
"hexaqueue-workflow",
|
|
13
|
+
"hexastack-auth>=0.11.0",
|
|
13
14
|
"hexastack-cli>=0.11.0",
|
|
14
15
|
"hexastack-core>=0.11.0",
|
|
15
16
|
"hexastack-cqrs>=0.11.0",
|
|
16
17
|
"hexastack-grpc>=0.11.0",
|
|
18
|
+
"httpx>=0.27.0",
|
|
19
|
+
"pydantic>=2.0.0",
|
|
17
20
|
"pyyaml>=6.0.2",
|
|
18
21
|
"rich>=13.8.0",
|
|
19
22
|
"typer>=0.15.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hexaqueue-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.0"
|
|
4
4
|
description = "Hexaqueue CLI - Modern developer and operator terminal interface"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -13,10 +13,13 @@ dependencies = [
|
|
|
13
13
|
"hexaqueue-server",
|
|
14
14
|
"hexaqueue-worker",
|
|
15
15
|
"hexaqueue-workflow",
|
|
16
|
+
"hexastack-auth>=0.11.0",
|
|
16
17
|
"hexastack-cli>=0.11.0",
|
|
17
18
|
"hexastack-core>=0.11.0",
|
|
18
19
|
"hexastack-cqrs>=0.11.0",
|
|
19
20
|
"hexastack-grpc>=0.11.0",
|
|
21
|
+
"httpx>=0.27.0",
|
|
22
|
+
"pydantic>=2.0.0",
|
|
20
23
|
"pyyaml>=6.0.2",
|
|
21
24
|
"rich>=13.8.0",
|
|
22
25
|
"typer>=0.15.0",
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""Password rotation adapter for Hexaqueue CLI (HTTP with offline ADB/SQLite fallback).
|
|
2
|
+
|
|
3
|
+
Notes/Architectural Intent:
|
|
4
|
+
Keeps hexaqueue-cli decoupled from hexaqueue-dashboard (sibling layer in
|
|
5
|
+
.importlinter) by calling POST /dashboard/auth/rotate-password over HTTP
|
|
6
|
+
and falling back to direct Oracle ADB or SQLite updates when offline.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import sqlite3
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
import httpx
|
|
16
|
+
from hexastack_auth.adapters.password import Pbkdf2PasswordHasher
|
|
17
|
+
from pydantic import SecretStr
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
import oracledb
|
|
21
|
+
except ImportError:
|
|
22
|
+
oracledb = None # type: ignore[assignment]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _extract_error_detail(response: httpx.Response) -> str:
|
|
26
|
+
"""Extract an error message from a failed HTTP response without raising."""
|
|
27
|
+
try:
|
|
28
|
+
payload = response.json()
|
|
29
|
+
if isinstance(payload, dict) and "detail" in payload:
|
|
30
|
+
return str(payload["detail"])
|
|
31
|
+
except ValueError:
|
|
32
|
+
# Non-JSON error bodies fall back to response.text below.
|
|
33
|
+
return response.text
|
|
34
|
+
return response.text
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def rotate_password_online(
|
|
38
|
+
dashboard_url: str,
|
|
39
|
+
username: str,
|
|
40
|
+
current_secret: SecretStr,
|
|
41
|
+
new_secret: SecretStr,
|
|
42
|
+
*,
|
|
43
|
+
timeout: float = 10.0,
|
|
44
|
+
transport: httpx.BaseTransport | None = None,
|
|
45
|
+
) -> str:
|
|
46
|
+
"""Rotate a dashboard principal password via the running dashboard HTTP API.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
dashboard_url: Base URL of the Hexaqueue dashboard.
|
|
50
|
+
username: Principal username to update.
|
|
51
|
+
current_secret: Existing credential wrapped in SecretStr.
|
|
52
|
+
new_secret: Replacement credential wrapped in SecretStr.
|
|
53
|
+
timeout: HTTP timeout in seconds.
|
|
54
|
+
transport: Optional custom httpx transport for hermetic testing.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
Confirmation message describing the online rotation target.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
ConnectionError: If the dashboard server is unreachable.
|
|
61
|
+
ValueError: If the dashboard rejects the credentials or request.
|
|
62
|
+
"""
|
|
63
|
+
base_url = dashboard_url.rstrip("/")
|
|
64
|
+
try:
|
|
65
|
+
with httpx.Client(
|
|
66
|
+
base_url=base_url,
|
|
67
|
+
timeout=timeout,
|
|
68
|
+
transport=transport,
|
|
69
|
+
) as client:
|
|
70
|
+
response = client.post(
|
|
71
|
+
"/dashboard/auth/rotate-password",
|
|
72
|
+
json={
|
|
73
|
+
"username": username,
|
|
74
|
+
"current_secret": current_secret.get_secret_value(),
|
|
75
|
+
"new_secret": new_secret.get_secret_value(),
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
except httpx.HTTPError as exc:
|
|
79
|
+
raise ConnectionError(f"Dashboard unreachable at {base_url}: {exc}") from exc
|
|
80
|
+
|
|
81
|
+
if response.is_error:
|
|
82
|
+
detail = _extract_error_detail(response)
|
|
83
|
+
raise ValueError(
|
|
84
|
+
f"Dashboard rejected password rotation (HTTP {response.status_code}): {detail}"
|
|
85
|
+
)
|
|
86
|
+
return f"Rotated password for '{username}' via {base_url}"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _connect_oracle_adb() -> Any:
|
|
90
|
+
"""Open an Oracle ADB connection using HEXAQUEUE_ORACLE_ADB_* env vars."""
|
|
91
|
+
if oracledb is None:
|
|
92
|
+
raise RuntimeError(
|
|
93
|
+
"oracledb is not installed; install hexaqueue-server[oracle] for ADB access"
|
|
94
|
+
)
|
|
95
|
+
kwargs: dict[str, Any] = {
|
|
96
|
+
"user": os.environ.get("HEXAQUEUE_ORACLE_ADB_USER", "ADMIN"),
|
|
97
|
+
"password": os.environ.get("HEXAQUEUE_ORACLE_ADB_PASSWORD", ""),
|
|
98
|
+
"dsn": os.environ.get("HEXAQUEUE_ORACLE_ADB_DSN", ""),
|
|
99
|
+
}
|
|
100
|
+
wallet_dir = os.environ.get("HEXAQUEUE_ORACLE_ADB_WALLET_DIR")
|
|
101
|
+
wallet_password = os.environ.get("HEXAQUEUE_ORACLE_ADB_WALLET_PASSWORD")
|
|
102
|
+
if wallet_dir:
|
|
103
|
+
kwargs["config_dir"] = wallet_dir
|
|
104
|
+
kwargs["wallet_location"] = wallet_dir
|
|
105
|
+
if wallet_password:
|
|
106
|
+
kwargs["wallet_password"] = wallet_password
|
|
107
|
+
return oracledb.connect(**kwargs)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _rotate_in_sqlite(
|
|
111
|
+
db_path: str,
|
|
112
|
+
username: str,
|
|
113
|
+
current_secret: SecretStr,
|
|
114
|
+
new_secret: SecretStr,
|
|
115
|
+
hasher: Pbkdf2PasswordHasher,
|
|
116
|
+
) -> str:
|
|
117
|
+
"""Verify current password and update PBKDF2 hash in local SQLite RBAC store."""
|
|
118
|
+
with sqlite3.connect(db_path) as conn:
|
|
119
|
+
row = conn.execute(
|
|
120
|
+
"SELECT hashed_secret, is_active FROM hxq_rbac_principals WHERE principal_id = ?",
|
|
121
|
+
(username,),
|
|
122
|
+
).fetchone()
|
|
123
|
+
if row is None or not bool(row[1]):
|
|
124
|
+
raise ValueError(f"Principal '{username}' not found or inactive.")
|
|
125
|
+
if not hasher.verify_password(current_secret.get_secret_value(), str(row[0])):
|
|
126
|
+
raise ValueError("Current password verification failed.")
|
|
127
|
+
new_hash = hasher.hash_password(new_secret.get_secret_value())
|
|
128
|
+
conn.execute(
|
|
129
|
+
"UPDATE hxq_rbac_principals SET hashed_secret = ? WHERE principal_id = ?",
|
|
130
|
+
(new_hash, username),
|
|
131
|
+
)
|
|
132
|
+
conn.commit()
|
|
133
|
+
return f"Rotated password for '{username}' offline in SQLite ({db_path})"
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _rotate_in_oracle(
|
|
137
|
+
username: str,
|
|
138
|
+
current_secret: SecretStr,
|
|
139
|
+
new_secret: SecretStr,
|
|
140
|
+
hasher: Pbkdf2PasswordHasher,
|
|
141
|
+
) -> str:
|
|
142
|
+
"""Verify current password and update PBKDF2 hash in Oracle ADB RBAC store."""
|
|
143
|
+
conn = _connect_oracle_adb()
|
|
144
|
+
try:
|
|
145
|
+
cur = conn.cursor()
|
|
146
|
+
try:
|
|
147
|
+
cur.execute(
|
|
148
|
+
"SELECT hashed_secret, is_active FROM hxq_rbac_principals WHERE principal_id = :1",
|
|
149
|
+
(username,),
|
|
150
|
+
)
|
|
151
|
+
row = cur.fetchone()
|
|
152
|
+
if row is None or not bool(row[1]):
|
|
153
|
+
raise ValueError(f"Principal '{username}' not found or inactive.")
|
|
154
|
+
if not hasher.verify_password(
|
|
155
|
+
current_secret.get_secret_value(), str(row[0])
|
|
156
|
+
):
|
|
157
|
+
raise ValueError("Current password verification failed.")
|
|
158
|
+
new_hash = hasher.hash_password(new_secret.get_secret_value())
|
|
159
|
+
cur.execute(
|
|
160
|
+
"UPDATE hxq_rbac_principals SET hashed_secret = :1 WHERE principal_id = :2",
|
|
161
|
+
(new_hash, username),
|
|
162
|
+
)
|
|
163
|
+
conn.commit()
|
|
164
|
+
finally:
|
|
165
|
+
cur.close()
|
|
166
|
+
finally:
|
|
167
|
+
conn.close()
|
|
168
|
+
return f"Rotated password for '{username}' offline in Oracle ADB"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def rotate_password_offline(
|
|
172
|
+
username: str,
|
|
173
|
+
current_secret: SecretStr,
|
|
174
|
+
new_secret: SecretStr,
|
|
175
|
+
*,
|
|
176
|
+
sqlite_path: str | None = None,
|
|
177
|
+
) -> str:
|
|
178
|
+
"""Rotate a principal password directly in Oracle ADB or SQLite without HTTP.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
username: Principal username to update.
|
|
182
|
+
current_secret: Existing credential wrapped in SecretStr.
|
|
183
|
+
new_secret: Replacement credential wrapped in SecretStr.
|
|
184
|
+
sqlite_path: Optional explicit SQLite DB path override.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Confirmation message describing the offline store updated.
|
|
188
|
+
|
|
189
|
+
Raises:
|
|
190
|
+
RuntimeError: If neither Oracle ADB nor SQLite RBAC storage is configured.
|
|
191
|
+
ValueError: If principal is missing/inactive or current password is invalid.
|
|
192
|
+
"""
|
|
193
|
+
hasher = Pbkdf2PasswordHasher()
|
|
194
|
+
if os.environ.get("HEXAQUEUE_ORACLE_ADB_DSN"):
|
|
195
|
+
return _rotate_in_oracle(username, current_secret, new_secret, hasher)
|
|
196
|
+
resolved_sqlite = sqlite_path or os.environ.get("HEXAQUEUE_RBAC_DB_PATH")
|
|
197
|
+
if resolved_sqlite:
|
|
198
|
+
return _rotate_in_sqlite(
|
|
199
|
+
resolved_sqlite, username, current_secret, new_secret, hasher
|
|
200
|
+
)
|
|
201
|
+
raise RuntimeError(
|
|
202
|
+
"No offline RBAC store configured "
|
|
203
|
+
"(set HEXAQUEUE_ORACLE_ADB_DSN or HEXAQUEUE_RBAC_DB_PATH)."
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def rotate_dashboard_password(
|
|
208
|
+
username: str,
|
|
209
|
+
current_secret: SecretStr,
|
|
210
|
+
new_secret: SecretStr,
|
|
211
|
+
*,
|
|
212
|
+
dashboard_url: str | None = None,
|
|
213
|
+
offline: bool = False,
|
|
214
|
+
transport: httpx.BaseTransport | None = None,
|
|
215
|
+
) -> str:
|
|
216
|
+
"""Rotate a dashboard principal password via HTTP with offline fallback.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
username: Principal username to update.
|
|
220
|
+
current_secret: Existing credential wrapped in SecretStr.
|
|
221
|
+
new_secret: Replacement credential wrapped in SecretStr.
|
|
222
|
+
dashboard_url: Optional dashboard URL (defaults to HEXAQUEUE_DASHBOARD_URL
|
|
223
|
+
or http://127.0.0.1:8080).
|
|
224
|
+
offline: If True, bypass HTTP and update Oracle ADB / SQLite directly.
|
|
225
|
+
transport: Optional custom httpx transport for hermetic testing.
|
|
226
|
+
|
|
227
|
+
Returns:
|
|
228
|
+
Human-readable confirmation message without any secret values.
|
|
229
|
+
"""
|
|
230
|
+
if offline:
|
|
231
|
+
return rotate_password_offline(username, current_secret, new_secret)
|
|
232
|
+
|
|
233
|
+
resolved_url = dashboard_url or os.environ.get(
|
|
234
|
+
"HEXAQUEUE_DASHBOARD_URL",
|
|
235
|
+
"http://127.0.0.1:8080",
|
|
236
|
+
)
|
|
237
|
+
try:
|
|
238
|
+
return rotate_password_online(
|
|
239
|
+
resolved_url,
|
|
240
|
+
username,
|
|
241
|
+
current_secret,
|
|
242
|
+
new_secret,
|
|
243
|
+
transport=transport,
|
|
244
|
+
)
|
|
245
|
+
except ConnectionError:
|
|
246
|
+
return rotate_password_offline(username, current_secret, new_secret)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
__all__ = [
|
|
250
|
+
"rotate_dashboard_password",
|
|
251
|
+
"rotate_password_offline",
|
|
252
|
+
"rotate_password_online",
|
|
253
|
+
]
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""SSH ControlMaster tunnel adapter for Hexaqueue standalone dashboard access.
|
|
2
|
+
|
|
3
|
+
Notes/Architectural Intent:
|
|
4
|
+
Manages a persistent, idempotent SSH local port-forward using a Unix
|
|
5
|
+
ControlMaster socket so CLI subcommands can start, inspect, open, and
|
|
6
|
+
cleanly tear down the dashboard tunnel without tracking raw PIDs.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import subprocess
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
DEFAULT_SOCKET_PATH = Path.home() / ".hexaqueue" / "dashboard-tunnel.sock"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _validate_port(port: int, label: str) -> int:
|
|
19
|
+
if not 1 <= port <= 65535:
|
|
20
|
+
raise ValueError(f"{label} port must be between 1 and 65535, got {port}")
|
|
21
|
+
return port
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _resolve_target(host: str | None, user: str | None) -> str:
|
|
25
|
+
resolved_host = (
|
|
26
|
+
host or os.environ.get("HEXAQUEUE_CLUSTER_HOST") or "129.146.115.79"
|
|
27
|
+
).strip()
|
|
28
|
+
resolved_user = (user or os.environ.get("HEXAQUEUE_SSH_USER") or "ubuntu").strip()
|
|
29
|
+
if not resolved_host or not resolved_user:
|
|
30
|
+
raise ValueError("Both SSH host and user must be non-empty.")
|
|
31
|
+
return f"{resolved_user}@{resolved_host}"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def is_tunnel_active(
|
|
35
|
+
*,
|
|
36
|
+
host: str | None = None,
|
|
37
|
+
user: str | None = None,
|
|
38
|
+
socket_path: Path = DEFAULT_SOCKET_PATH,
|
|
39
|
+
) -> bool:
|
|
40
|
+
"""Check whether the SSH ControlMaster dashboard tunnel is currently active.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
host: Remote controller host (defaults to HEXAQUEUE_CLUSTER_HOST).
|
|
44
|
+
user: Remote SSH user (defaults to HEXAQUEUE_SSH_USER or 'ubuntu').
|
|
45
|
+
socket_path: ControlMaster Unix socket path.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
True if the ControlMaster socket responds cleanly, otherwise False.
|
|
49
|
+
"""
|
|
50
|
+
if not socket_path.exists():
|
|
51
|
+
return False
|
|
52
|
+
target = _resolve_target(host, user)
|
|
53
|
+
res = subprocess.run(
|
|
54
|
+
["ssh", "-S", str(socket_path), "-O", "check", target],
|
|
55
|
+
capture_output=True,
|
|
56
|
+
text=True,
|
|
57
|
+
check=False,
|
|
58
|
+
)
|
|
59
|
+
return res.returncode == 0
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def start_tunnel(
|
|
63
|
+
*,
|
|
64
|
+
host: str | None = None,
|
|
65
|
+
user: str | None = None,
|
|
66
|
+
local_port: int = 8080,
|
|
67
|
+
remote_port: int = 8080,
|
|
68
|
+
socket_path: Path = DEFAULT_SOCKET_PATH,
|
|
69
|
+
) -> bool:
|
|
70
|
+
"""Start an SSH local port-forward tunnel if not already active.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
host: Remote controller host.
|
|
74
|
+
user: Remote SSH user.
|
|
75
|
+
local_port: Local loopback port to bind.
|
|
76
|
+
remote_port: Remote loopback dashboard port on the OCI host.
|
|
77
|
+
socket_path: ControlMaster Unix socket path.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
True if a new tunnel was started, False if one was already active.
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
RuntimeError: If SSH fails to establish the tunnel.
|
|
84
|
+
ValueError: If ports or target host/user are invalid.
|
|
85
|
+
"""
|
|
86
|
+
lport = _validate_port(local_port, "local")
|
|
87
|
+
rport = _validate_port(remote_port, "remote")
|
|
88
|
+
if is_tunnel_active(host=host, user=user, socket_path=socket_path):
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
if socket_path.exists():
|
|
92
|
+
socket_path.unlink(missing_ok=True)
|
|
93
|
+
socket_path.parent.mkdir(parents=True, exist_ok=True)
|
|
94
|
+
socket_path.parent.chmod(0o700)
|
|
95
|
+
|
|
96
|
+
target = _resolve_target(host, user)
|
|
97
|
+
res = subprocess.run(
|
|
98
|
+
[
|
|
99
|
+
"ssh",
|
|
100
|
+
"-M",
|
|
101
|
+
"-S",
|
|
102
|
+
str(socket_path),
|
|
103
|
+
"-fN",
|
|
104
|
+
"-L",
|
|
105
|
+
f"127.0.0.1:{lport}:127.0.0.1:{rport}",
|
|
106
|
+
"-o",
|
|
107
|
+
"ExitOnForwardFailure=yes",
|
|
108
|
+
target,
|
|
109
|
+
],
|
|
110
|
+
capture_output=True,
|
|
111
|
+
text=True,
|
|
112
|
+
check=False,
|
|
113
|
+
)
|
|
114
|
+
if res.returncode != 0:
|
|
115
|
+
detail = res.stderr.strip() or res.stdout.strip() or f"exit {res.returncode}"
|
|
116
|
+
raise RuntimeError(
|
|
117
|
+
f"Failed to start dashboard SSH tunnel to {target}: {detail}"
|
|
118
|
+
)
|
|
119
|
+
return True
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def stop_tunnel(
|
|
123
|
+
*,
|
|
124
|
+
host: str | None = None,
|
|
125
|
+
user: str | None = None,
|
|
126
|
+
socket_path: Path = DEFAULT_SOCKET_PATH,
|
|
127
|
+
) -> bool:
|
|
128
|
+
"""Tear down the active SSH ControlMaster dashboard tunnel if running.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
host: Remote controller host.
|
|
132
|
+
user: Remote SSH user.
|
|
133
|
+
socket_path: ControlMaster Unix socket path.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
True if an active tunnel was stopped, False if none was running.
|
|
137
|
+
"""
|
|
138
|
+
if not is_tunnel_active(host=host, user=user, socket_path=socket_path):
|
|
139
|
+
socket_path.unlink(missing_ok=True)
|
|
140
|
+
return False
|
|
141
|
+
|
|
142
|
+
target = _resolve_target(host, user)
|
|
143
|
+
subprocess.run(
|
|
144
|
+
["ssh", "-S", str(socket_path), "-O", "exit", target],
|
|
145
|
+
capture_output=True,
|
|
146
|
+
text=True,
|
|
147
|
+
check=False,
|
|
148
|
+
)
|
|
149
|
+
socket_path.unlink(missing_ok=True)
|
|
150
|
+
return True
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
__all__ = [
|
|
154
|
+
"DEFAULT_SOCKET_PATH",
|
|
155
|
+
"is_tunnel_active",
|
|
156
|
+
"start_tunnel",
|
|
157
|
+
"stop_tunnel",
|
|
158
|
+
]
|