onedeploy-cli 0.1.6 → 0.1.7
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/config.js +0 -1
- package/dist/index.js +2 -7
- package/dist/nebula.js +50 -5
- package/package.json +5 -5
- package/src/index.ts +0 -131
package/dist/config.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,16 +14,11 @@ const setupConnection = async () => {
|
|
|
14
14
|
name: "url",
|
|
15
15
|
message: "Enter OneDeploy URL",
|
|
16
16
|
},
|
|
17
|
-
{
|
|
18
|
-
type: "password",
|
|
19
|
-
name: "apiKey",
|
|
20
|
-
message: "Enter OneDeploy API key",
|
|
21
|
-
},
|
|
22
17
|
]);
|
|
23
|
-
if (result.
|
|
18
|
+
if (result.url === undefined) {
|
|
24
19
|
return;
|
|
25
20
|
}
|
|
26
|
-
config.instances.push({ url: result.url
|
|
21
|
+
config.instances.push({ url: result.url });
|
|
27
22
|
await saveConfig(config);
|
|
28
23
|
};
|
|
29
24
|
const removeConnection = async () => {
|
package/dist/nebula.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile, spawn } from "node:child_process";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
3
3
|
import { chmod, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { createServer } from "node:http";
|
|
4
5
|
import { tmpdir } from "node:os";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { Readable } from "node:stream";
|
|
@@ -52,10 +53,10 @@ export const installNebula = async () => {
|
|
|
52
53
|
export const cleanupNebula = async () => {
|
|
53
54
|
await rm(tmpDir, { recursive: true, force: true });
|
|
54
55
|
};
|
|
55
|
-
export const getNebulaCert = async (instance) => {
|
|
56
|
+
export const getNebulaCert = async (instance, session) => {
|
|
56
57
|
const response = await fetch(`${instance.url}/api/nebula/cert`, {
|
|
57
58
|
headers: {
|
|
58
|
-
authorization: `Bearer ${
|
|
59
|
+
authorization: `Bearer ${session}`,
|
|
59
60
|
},
|
|
60
61
|
});
|
|
61
62
|
if (!response.ok) {
|
|
@@ -86,13 +87,57 @@ export const getNebulaCert = async (instance) => {
|
|
|
86
87
|
process.stdout.write(stdout);
|
|
87
88
|
};
|
|
88
89
|
export let isNebulaRunning = false;
|
|
90
|
+
const getSession = (instance) => {
|
|
91
|
+
const verificationCode = randomBytes(8).toString("base64url");
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
const getServerAddr = () => {
|
|
94
|
+
const addr = server.address();
|
|
95
|
+
if (addr === null || typeof addr === "string") {
|
|
96
|
+
// just a placeholder, should not happen
|
|
97
|
+
return "http://localhost:70000";
|
|
98
|
+
}
|
|
99
|
+
return `http://localhost:${addr.port}`;
|
|
100
|
+
};
|
|
101
|
+
const server = createServer((req, res) => {
|
|
102
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
103
|
+
if (url.pathname === "/authenticated") {
|
|
104
|
+
const token = url.searchParams.get("token");
|
|
105
|
+
if (token === null) {
|
|
106
|
+
throw new Error("Missing token in callback URL");
|
|
107
|
+
}
|
|
108
|
+
// authentication complete
|
|
109
|
+
res.writeHead(200);
|
|
110
|
+
res.write("Authentication successful! You can close this window.");
|
|
111
|
+
res.end();
|
|
112
|
+
server.close();
|
|
113
|
+
resolve(token);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const target = `${getServerAddr()}/authenticated`;
|
|
117
|
+
res.writeHead(302, {
|
|
118
|
+
location: `${instance.url}/auth/nebula?redirect=${encodeURIComponent(target)}&code=${encodeURIComponent(verificationCode)}`,
|
|
119
|
+
});
|
|
120
|
+
res.end();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
server.on("listening", () => {
|
|
124
|
+
const addr = server.address();
|
|
125
|
+
if (addr === null || typeof addr === "string") {
|
|
126
|
+
throw new Error("Unexpected address type");
|
|
127
|
+
}
|
|
128
|
+
console.log(`Visit ${getServerAddr()} to authenticate. Client verification code: ${verificationCode}`);
|
|
129
|
+
});
|
|
130
|
+
server.listen();
|
|
131
|
+
});
|
|
132
|
+
};
|
|
89
133
|
export const connectNebula = async (instance) => {
|
|
90
|
-
await
|
|
134
|
+
const session = await getSession(instance);
|
|
135
|
+
await getNebulaCert(instance, session);
|
|
91
136
|
isNebulaRunning = true;
|
|
92
137
|
const nebula = spawn(`${tmpDir}/nebula`, ["-config", `${tmpDir}/nebula.yml`], { stdio: "inherit" });
|
|
93
138
|
const interval = setInterval(async () => {
|
|
94
139
|
// refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
|
|
95
|
-
await getNebulaCert(instance);
|
|
140
|
+
await getNebulaCert(instance, session);
|
|
96
141
|
nebula.kill("SIGHUP");
|
|
97
142
|
}, 10 * 60 * 1000);
|
|
98
143
|
await new Promise((resolve) => nebula.on("exit", resolve));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onedeploy-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "CLI tool for connecting to OneDeploy via Nebula",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"onedeploy",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"fix": "biome check src/* --fix"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@biomejs/biome": "^2.
|
|
36
|
-
"@types/node": "^24.
|
|
35
|
+
"@biomejs/biome": "^2.3.1",
|
|
36
|
+
"@types/node": "^24.9.1",
|
|
37
37
|
"@types/prompts": "^2.4.9",
|
|
38
|
-
"typescript": "^5.9.
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"prompts": "^2.4.2",
|
|
42
42
|
"yaml": "^2.8.1",
|
|
43
|
-
"yedra": "^0.
|
|
43
|
+
"yedra": "^0.18.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/index.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import prompts from "prompts";
|
|
3
|
-
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
-
import {
|
|
5
|
-
cleanupNebula,
|
|
6
|
-
connectNebula,
|
|
7
|
-
installNebula,
|
|
8
|
-
isNebulaRunning,
|
|
9
|
-
} from "./nebula.js";
|
|
10
|
-
|
|
11
|
-
if (process.argv.includes("--version")) {
|
|
12
|
-
console.log("onedeploy-cli version 0.1.4");
|
|
13
|
-
process.exit();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const config = await loadConfig();
|
|
17
|
-
|
|
18
|
-
const setupConnection = async () => {
|
|
19
|
-
const result = await prompts([
|
|
20
|
-
{
|
|
21
|
-
type: "text",
|
|
22
|
-
name: "url",
|
|
23
|
-
message: "Enter OneDeploy URL",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
type: "password",
|
|
27
|
-
name: "apiKey",
|
|
28
|
-
message: "Enter OneDeploy API key",
|
|
29
|
-
},
|
|
30
|
-
]);
|
|
31
|
-
if (result.apiKey === undefined || result.url === undefined) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
config.instances.push({ url: result.url, apiKey: result.apiKey });
|
|
35
|
-
await saveConfig(config);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const removeConnection = async () => {
|
|
39
|
-
const { connection } = await prompts([
|
|
40
|
-
{
|
|
41
|
-
type: "select",
|
|
42
|
-
name: "connection",
|
|
43
|
-
message: "Select connection to remove",
|
|
44
|
-
choices: config.instances.map((instance, index) => ({
|
|
45
|
-
title: instance.url,
|
|
46
|
-
value: index,
|
|
47
|
-
})),
|
|
48
|
-
},
|
|
49
|
-
]);
|
|
50
|
-
if (connection === undefined) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const { confirm } = await prompts([
|
|
54
|
-
{
|
|
55
|
-
type: "confirm",
|
|
56
|
-
name: "confirm",
|
|
57
|
-
message: `Are you sure you want to remove connection to ${config.instances[connection].url}?`,
|
|
58
|
-
initial: false,
|
|
59
|
-
},
|
|
60
|
-
]);
|
|
61
|
-
if (confirm === true) {
|
|
62
|
-
config.instances.splice(connection, 1);
|
|
63
|
-
await saveConfig(config);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const mainMenu = async (): Promise<boolean> => {
|
|
68
|
-
const { action } = await prompts([
|
|
69
|
-
{
|
|
70
|
-
type: "select",
|
|
71
|
-
name: "action",
|
|
72
|
-
message: "What do you want to do?",
|
|
73
|
-
choices: [
|
|
74
|
-
{
|
|
75
|
-
title: "Connect",
|
|
76
|
-
value: "connect",
|
|
77
|
-
disabled: config.instances.length === 0,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
title: "Setup new connection",
|
|
81
|
-
value: "setup",
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
title: "Remove connection",
|
|
85
|
-
value: "remove",
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
]);
|
|
90
|
-
if (action === "connect") {
|
|
91
|
-
const result = await prompts([
|
|
92
|
-
{
|
|
93
|
-
type: "select",
|
|
94
|
-
name: "connection",
|
|
95
|
-
message: "Select OneDeploy instance",
|
|
96
|
-
choices: config.instances.map((instance) => ({
|
|
97
|
-
title: instance.url,
|
|
98
|
-
value: instance,
|
|
99
|
-
})),
|
|
100
|
-
},
|
|
101
|
-
]);
|
|
102
|
-
if (result.connection !== undefined) {
|
|
103
|
-
await connectNebula(result.connection);
|
|
104
|
-
}
|
|
105
|
-
} else if (action === "setup") {
|
|
106
|
-
await setupConnection();
|
|
107
|
-
} else if (action === "remove") {
|
|
108
|
-
await removeConnection();
|
|
109
|
-
} else {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
return true;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
process.on("SIGINT", () => {
|
|
116
|
-
if (!isNebulaRunning) {
|
|
117
|
-
process.exit();
|
|
118
|
-
}
|
|
119
|
-
// ignore SIGINTs to continue after Nebula is disconnected
|
|
120
|
-
});
|
|
121
|
-
await installNebula();
|
|
122
|
-
try {
|
|
123
|
-
while (true) {
|
|
124
|
-
const shouldContinue = await mainMenu();
|
|
125
|
-
if (!shouldContinue) {
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
} finally {
|
|
130
|
-
await cleanupNebula();
|
|
131
|
-
}
|