@opentrust/cli 7.3.23 → 7.3.25
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.
- package/dist/commands/init.js +3 -3
- package/dist/commands/status.js +66 -1
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -13,9 +13,9 @@ const SCAFFOLD_PKG = {
|
|
|
13
13
|
status: "opentrust status",
|
|
14
14
|
},
|
|
15
15
|
dependencies: {
|
|
16
|
-
"@opentrust/core": "^7.3.
|
|
17
|
-
"@opentrust/gateway": "^7.3.
|
|
18
|
-
"@opentrust/dashboard": "^7.3.
|
|
16
|
+
"@opentrust/core": "^7.3.25",
|
|
17
|
+
"@opentrust/gateway": "^7.3.25",
|
|
18
|
+
"@opentrust/dashboard": "^7.3.25",
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
21
|
const ENV_TEMPLATE = `# OpenTrust Configuration
|
package/dist/commands/status.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
import { getStatus, checkHealth, getAllServiceKeys, SERVICES } from "../lib/process-manager.js";
|
|
2
2
|
import { requireProject } from "../lib/paths.js";
|
|
3
3
|
import { dockerStatus } from "../lib/docker-manager.js";
|
|
4
|
+
import { loadConfig } from "../lib/dashboard-client.js";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
const GREEN = "\x1b[32m●\x1b[0m";
|
|
9
|
+
const YELLOW = "\x1b[33m●\x1b[0m";
|
|
10
|
+
const RED = "\x1b[31m●\x1b[0m";
|
|
11
|
+
const PID_FILE = path.join(os.homedir(), ".opentrust", "connect.pid");
|
|
12
|
+
function getConnectDaemonStatus() {
|
|
13
|
+
if (!fs.existsSync(PID_FILE))
|
|
14
|
+
return { running: false, pid: null };
|
|
15
|
+
const pid = parseInt(fs.readFileSync(PID_FILE, "utf-8").trim(), 10);
|
|
16
|
+
if (isNaN(pid))
|
|
17
|
+
return { running: false, pid: null };
|
|
18
|
+
try {
|
|
19
|
+
process.kill(pid, 0);
|
|
20
|
+
return { running: true, pid };
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return { running: false, pid: null };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function checkDashboardReachable(url) {
|
|
27
|
+
try {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
const timer = setTimeout(() => controller.abort(), 5000);
|
|
30
|
+
const res = await fetch(`${url}/health`, { signal: controller.signal });
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
const data = (await res.json());
|
|
33
|
+
return data.status === "ok";
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
4
39
|
export function registerStatusCommand(program) {
|
|
5
40
|
program
|
|
6
41
|
.command("status")
|
|
@@ -14,12 +49,13 @@ export function registerStatusCommand(program) {
|
|
|
14
49
|
}
|
|
15
50
|
requireProject();
|
|
16
51
|
console.log("OpenTrust Service Status\n");
|
|
52
|
+
// Services
|
|
17
53
|
const keys = getAllServiceKeys();
|
|
18
54
|
for (const key of keys) {
|
|
19
55
|
const svc = SERVICES[key];
|
|
20
56
|
const { running, pid } = getStatus(key);
|
|
21
57
|
const healthy = running ? await checkHealth(key) : false;
|
|
22
|
-
const statusIcon = running ? (healthy ?
|
|
58
|
+
const statusIcon = running ? (healthy ? GREEN : YELLOW) : RED;
|
|
23
59
|
const statusText = running
|
|
24
60
|
? healthy
|
|
25
61
|
? `running (PID ${pid})`
|
|
@@ -27,6 +63,35 @@ export function registerStatusCommand(program) {
|
|
|
27
63
|
: "stopped";
|
|
28
64
|
console.log(` ${statusIcon} ${svc.name.padEnd(12)} ${statusText.padEnd(35)} port ${svc.port}`);
|
|
29
65
|
}
|
|
66
|
+
// Connect daemon
|
|
67
|
+
console.log("");
|
|
68
|
+
const daemon = getConnectDaemonStatus();
|
|
69
|
+
const config = loadConfig();
|
|
70
|
+
if (daemon.running) {
|
|
71
|
+
const reachable = config?.dashboardUrl
|
|
72
|
+
? await checkDashboardReachable(config.dashboardUrl)
|
|
73
|
+
: false;
|
|
74
|
+
const connIcon = reachable ? GREEN : YELLOW;
|
|
75
|
+
const connText = reachable
|
|
76
|
+
? `connected (PID ${daemon.pid})`
|
|
77
|
+
: `running but dashboard unreachable (PID ${daemon.pid})`;
|
|
78
|
+
console.log(` ${connIcon} ${"CLI Client".padEnd(12)} ${connText}`);
|
|
79
|
+
if (config?.dashboardUrl) {
|
|
80
|
+
console.log(` ${"".padEnd(15)} → ${config.dashboardUrl}`);
|
|
81
|
+
}
|
|
82
|
+
if (config?.hostId) {
|
|
83
|
+
console.log(` ${"".padEnd(15)} Host ID: ${config.hostId}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (config?.dashboardUrl) {
|
|
87
|
+
console.log(` ${RED} ${"CLI Client".padEnd(12)} not running (configured but daemon stopped)`);
|
|
88
|
+
console.log(` ${"".padEnd(15)} → ${config.dashboardUrl}`);
|
|
89
|
+
console.log(` ${"".padEnd(15)} Run: opentrust connect --daemon`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log(` ${RED} ${"CLI Client".padEnd(12)} not configured`);
|
|
93
|
+
console.log(` ${"".padEnd(15)} Run: opentrust connect --dashboard-url <url> --api-key <key> --daemon`);
|
|
94
|
+
}
|
|
30
95
|
console.log("");
|
|
31
96
|
});
|
|
32
97
|
}
|