onedeploy-cli 0.1.6 → 0.1.8
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 +51 -6
- package/package.json +6 -6
- package/src/index.ts +2 -7
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";
|
|
@@ -29,7 +30,7 @@ const getNebulaPackageName = () => {
|
|
|
29
30
|
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
|
-
const nebulaVersion = "v1.
|
|
33
|
+
const nebulaVersion = "v1.10.0";
|
|
33
34
|
const packageName = getNebulaPackageName();
|
|
34
35
|
const nebulaUrl = `https://github.com/slackhq/nebula/releases/download/${nebulaVersion}/${packageName}`;
|
|
35
36
|
const tmpDir = path.join(tmpdir(), `onedeploy-${randomUUID()}`);
|
|
@@ -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.8",
|
|
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": "^
|
|
35
|
+
"@biomejs/biome": "^2.3.8",
|
|
36
|
+
"@types/node": "^25.0.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
|
-
"yaml": "^2.8.
|
|
43
|
-
"yedra": "^0.
|
|
42
|
+
"yaml": "^2.8.2",
|
|
43
|
+
"yedra": "^0.19.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -22,16 +22,11 @@ const setupConnection = async () => {
|
|
|
22
22
|
name: "url",
|
|
23
23
|
message: "Enter OneDeploy URL",
|
|
24
24
|
},
|
|
25
|
-
{
|
|
26
|
-
type: "password",
|
|
27
|
-
name: "apiKey",
|
|
28
|
-
message: "Enter OneDeploy API key",
|
|
29
|
-
},
|
|
30
25
|
]);
|
|
31
|
-
if (result.
|
|
26
|
+
if (result.url === undefined) {
|
|
32
27
|
return;
|
|
33
28
|
}
|
|
34
|
-
config.instances.push({ url: result.url
|
|
29
|
+
config.instances.push({ url: result.url });
|
|
35
30
|
await saveConfig(config);
|
|
36
31
|
};
|
|
37
32
|
|