onedeploy-cli 0.1.0 → 0.1.2
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/LICENSE +7 -0
- package/README.md +7 -0
- package/dist/config.js +27 -0
- package/dist/index.js +21 -82
- package/dist/nebula.js +83 -0
- package/package.json +2 -2
- package/src/index.ts +20 -101
- package/dist/index.d.ts +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Relyon AG
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# OneDeploy CLI
|
|
2
|
+
|
|
3
|
+
This CLI allows you to connect to a OneDeploy cluster via [Nebula](https://github.com/slackhq/nebula). First, you need to create an API key on your dashboard. Then, you can `Setup new connection` with your dashboard URL and API key. Afterwards, you can `Connect` to the cluster you added. Please note that Nebula requires administrator permissions to run, so you'll need to enter your password.
|
|
4
|
+
|
|
5
|
+
## License
|
|
6
|
+
|
|
7
|
+
The OneDeploy CLI licensed under MIT, see [here](./LICENSE). It uses the Nebula overlay network, which is also MIT licensed.
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { y } from "yedra";
|
|
4
|
+
const configDir = `${homedir()}/.config/onedeploy`;
|
|
5
|
+
await mkdir(configDir, { recursive: true });
|
|
6
|
+
const Instance = y.object({
|
|
7
|
+
url: y.string(),
|
|
8
|
+
apiKey: y.string(),
|
|
9
|
+
});
|
|
10
|
+
const Config = y.object({
|
|
11
|
+
instances: Instance.array(),
|
|
12
|
+
});
|
|
13
|
+
export const loadConfig = async () => {
|
|
14
|
+
try {
|
|
15
|
+
const result = await readFile(`${configDir}/config.json`, "utf-8");
|
|
16
|
+
const config = JSON.parse(result);
|
|
17
|
+
return Config.parse(config);
|
|
18
|
+
}
|
|
19
|
+
catch (_error) {
|
|
20
|
+
// no config yet
|
|
21
|
+
return { instances: [] };
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const saveConfig = async (config) => {
|
|
25
|
+
await writeFile(`${configDir}/config.json`, JSON.stringify(config, null, 2));
|
|
26
|
+
await chmod(`${configDir}/config.json`, 0o600);
|
|
27
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,79 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { Readable } from "node:stream";
|
|
6
|
-
import { promisify } from "node:util";
|
|
1
|
+
#!/usr/bin/env node
|
|
7
2
|
import prompts from "prompts";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const tmpDir = `/tmp/onedeploy-${randomUUID()}`;
|
|
12
|
-
await mkdir(configDir, { recursive: true });
|
|
13
|
-
await mkdir(tmpDir, { recursive: true });
|
|
14
|
-
const Instance = y.object({
|
|
15
|
-
url: y.string(),
|
|
16
|
-
apiKey: y.string(),
|
|
17
|
-
});
|
|
18
|
-
const Config = y.object({
|
|
19
|
-
instances: Instance.array(),
|
|
20
|
-
});
|
|
21
|
-
const installNebula = async () => {
|
|
22
|
-
console.log("Downloading Nebula...");
|
|
23
|
-
const file = await fetch(nebulaUrl);
|
|
24
|
-
if (file.body === null) {
|
|
25
|
-
throw new Error("Could not download Nebula executable.");
|
|
26
|
-
}
|
|
27
|
-
await writeFile(`${tmpDir}/nebula.tar.gz`, Readable.from(file.body));
|
|
28
|
-
console.log("Extracting Nebula...");
|
|
29
|
-
await promisify(execFile)("tar", [
|
|
30
|
-
"-xf",
|
|
31
|
-
`${tmpDir}/nebula.tar.gz`,
|
|
32
|
-
"-C",
|
|
33
|
-
tmpDir,
|
|
34
|
-
]);
|
|
35
|
-
};
|
|
36
|
-
const loadConfig = async () => {
|
|
37
|
-
try {
|
|
38
|
-
const result = await readFile(`${configDir}/config.json`, "utf-8");
|
|
39
|
-
const config = JSON.parse(result);
|
|
40
|
-
return Config.parse(config);
|
|
41
|
-
}
|
|
42
|
-
catch (_error) {
|
|
43
|
-
// no config yet
|
|
44
|
-
return { instances: [] };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const saveConfig = async () => {
|
|
48
|
-
await writeFile(`${configDir}/config.json`, JSON.stringify(config, null, 2));
|
|
49
|
-
await chmod(`${configDir}/config.json`, 0o600);
|
|
50
|
-
};
|
|
51
|
-
const getNebulaCert = async (instance) => {
|
|
52
|
-
const response = await fetch(`${instance.url}/api/nebula/cert`, {
|
|
53
|
-
headers: {
|
|
54
|
-
authorization: `Bearer ${instance.apiKey}`,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
throw new Error(`Failed to fetch Nebula certificate: ${response.status}`);
|
|
59
|
-
}
|
|
60
|
-
const { nebulaConfig } = await response.json();
|
|
61
|
-
await writeFile(`${tmpDir}/nebula.yml`, nebulaConfig);
|
|
62
|
-
await chmod(`${tmpDir}/nebula.yml`, 0o600);
|
|
63
|
-
};
|
|
64
|
-
const connectNebula = async (instance) => {
|
|
65
|
-
await getNebulaCert(instance);
|
|
66
|
-
const nebula = spawn("sudo", [`${tmpDir}/nebula`, "-config", `${tmpDir}/nebula.yml`], {
|
|
67
|
-
stdio: "inherit",
|
|
68
|
-
});
|
|
69
|
-
const interval = setInterval(async () => {
|
|
70
|
-
// refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
|
|
71
|
-
await getNebulaCert(instance);
|
|
72
|
-
nebula.kill("SIGHUP");
|
|
73
|
-
}, 10 * 60 * 1000);
|
|
74
|
-
await new Promise((resolve) => nebula.on("exit", resolve));
|
|
75
|
-
clearInterval(interval);
|
|
76
|
-
};
|
|
3
|
+
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
+
import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
|
|
5
|
+
const config = await loadConfig();
|
|
77
6
|
const setupConnection = async () => {
|
|
78
7
|
const result = await prompts([
|
|
79
8
|
{
|
|
@@ -91,7 +20,7 @@ const setupConnection = async () => {
|
|
|
91
20
|
return;
|
|
92
21
|
}
|
|
93
22
|
config.instances.push({ url: result.url, apiKey: result.apiKey });
|
|
94
|
-
await saveConfig();
|
|
23
|
+
await saveConfig(config);
|
|
95
24
|
};
|
|
96
25
|
const removeConnection = async () => {
|
|
97
26
|
const { connection } = await prompts([
|
|
@@ -118,12 +47,10 @@ const removeConnection = async () => {
|
|
|
118
47
|
]);
|
|
119
48
|
if (confirm === true) {
|
|
120
49
|
config.instances.splice(connection, 1);
|
|
121
|
-
await saveConfig();
|
|
50
|
+
await saveConfig(config);
|
|
122
51
|
}
|
|
123
52
|
};
|
|
124
|
-
|
|
125
|
-
const config = await loadConfig();
|
|
126
|
-
while (true) {
|
|
53
|
+
const mainMenu = async () => {
|
|
127
54
|
const { action } = await prompts([
|
|
128
55
|
{
|
|
129
56
|
type: "select",
|
|
@@ -169,7 +96,19 @@ while (true) {
|
|
|
169
96
|
await removeConnection();
|
|
170
97
|
}
|
|
171
98
|
else {
|
|
172
|
-
|
|
99
|
+
return false;
|
|
173
100
|
}
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
await installNebula();
|
|
104
|
+
try {
|
|
105
|
+
while (true) {
|
|
106
|
+
const shouldContinue = await mainMenu();
|
|
107
|
+
if (!shouldContinue) {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
await cleanupNebula();
|
|
174
114
|
}
|
|
175
|
-
await rm(tmpDir, { recursive: true, force: true });
|
package/dist/nebula.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { chmod, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
const getNebulaPackageName = () => {
|
|
9
|
+
switch (process.platform) {
|
|
10
|
+
case "linux":
|
|
11
|
+
if (process.arch !== "x64") {
|
|
12
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
13
|
+
}
|
|
14
|
+
return `nebula-linux-amd64.tar.gz`;
|
|
15
|
+
case "darwin":
|
|
16
|
+
return `nebula-darwin.zip`;
|
|
17
|
+
case "win32":
|
|
18
|
+
if (process.arch !== "x64") {
|
|
19
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
20
|
+
}
|
|
21
|
+
return `nebula-windows-amd64.zip`;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const nebulaVersion = "v1.9.6";
|
|
27
|
+
const packageName = getNebulaPackageName();
|
|
28
|
+
const nebulaUrl = `https://github.com/slackhq/nebula/releases/download/${nebulaVersion}/${packageName}`;
|
|
29
|
+
const tmpDir = path.join(tmpdir(), `onedeploy-${randomUUID()}`);
|
|
30
|
+
await mkdir(tmpDir, { recursive: true });
|
|
31
|
+
export const installNebula = async () => {
|
|
32
|
+
console.log("Downloading Nebula...");
|
|
33
|
+
const file = await fetch(nebulaUrl);
|
|
34
|
+
if (file.body === null) {
|
|
35
|
+
throw new Error("Could not download Nebula executable.");
|
|
36
|
+
}
|
|
37
|
+
await writeFile(`${tmpDir}/${packageName}`, Readable.from(file.body));
|
|
38
|
+
console.log("Extracting Nebula...");
|
|
39
|
+
await promisify(execFile)("tar", [
|
|
40
|
+
"-xf",
|
|
41
|
+
`${tmpDir}/${packageName}`,
|
|
42
|
+
"-C",
|
|
43
|
+
tmpDir,
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
46
|
+
export const cleanupNebula = async () => {
|
|
47
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
48
|
+
};
|
|
49
|
+
export const getNebulaCert = async (instance) => {
|
|
50
|
+
const response = await fetch(`${instance.url}/api/nebula/cert`, {
|
|
51
|
+
headers: {
|
|
52
|
+
authorization: `Bearer ${instance.apiKey}`,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(`Failed to fetch Nebula certificate: ${response.status}`);
|
|
57
|
+
}
|
|
58
|
+
const { nebulaConfig } = (await response.json());
|
|
59
|
+
await writeFile(`${tmpDir}/nebula.yml`, nebulaConfig);
|
|
60
|
+
await chmod(`${tmpDir}/nebula.yml`, 0o600);
|
|
61
|
+
};
|
|
62
|
+
const spawnNebula = () => {
|
|
63
|
+
if (process.platform === "win32") {
|
|
64
|
+
return spawn("powershell.exe", [
|
|
65
|
+
"-Command",
|
|
66
|
+
`Start-Process ${tmpDir}\\nebula.exe -ArgumentList '-config','${tmpDir}\\nebula.yml' -Verb RunAs`,
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
return spawn("sudo", [`${tmpDir}/nebula`, "-config", `${tmpDir}/nebula.yml`], {
|
|
70
|
+
stdio: "inherit",
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
export const connectNebula = async (instance) => {
|
|
74
|
+
await getNebulaCert(instance);
|
|
75
|
+
const nebula = spawnNebula();
|
|
76
|
+
const interval = setInterval(async () => {
|
|
77
|
+
// refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
|
|
78
|
+
await getNebulaCert(instance);
|
|
79
|
+
nebula.kill("SIGHUP");
|
|
80
|
+
}, 10 * 60 * 1000);
|
|
81
|
+
await new Promise((resolve) => nebula.on("exit", resolve));
|
|
82
|
+
clearInterval(interval);
|
|
83
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onedeploy-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "CLI tool for connecting to OneDeploy via Nebula",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"onedeploy",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"main": "src/index.ts",
|
|
26
26
|
"bin": {
|
|
27
|
-
"onedeploy": "./dist/index.js"
|
|
27
|
+
"onedeploy-cli": "./dist/index.js"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsc",
|
package/src/index.ts
CHANGED
|
@@ -1,99 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { Readable } from "node:stream";
|
|
6
|
-
import { promisify } from "node:util";
|
|
1
|
+
#!/usr/bin/env node
|
|
7
2
|
import prompts from "prompts";
|
|
8
|
-
import {
|
|
3
|
+
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
+
import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
|
|
9
5
|
|
|
10
|
-
const
|
|
11
|
-
const configDir = `${homedir()}/.config/onedeploy`;
|
|
12
|
-
const tmpDir = `/tmp/onedeploy-${randomUUID()}`;
|
|
13
|
-
await mkdir(configDir, { recursive: true });
|
|
14
|
-
await mkdir(tmpDir, { recursive: true });
|
|
15
|
-
|
|
16
|
-
const Instance = y.object({
|
|
17
|
-
url: y.string(),
|
|
18
|
-
apiKey: y.string(),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const Config = y.object({
|
|
22
|
-
instances: Instance.array(),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
type Instance = y.Typeof<typeof Instance>;
|
|
26
|
-
type Config = y.Typeof<typeof Config>;
|
|
27
|
-
|
|
28
|
-
const installNebula = async (): Promise<void> => {
|
|
29
|
-
console.log("Downloading Nebula...");
|
|
30
|
-
const file = await fetch(nebulaUrl);
|
|
31
|
-
if (file.body === null) {
|
|
32
|
-
throw new Error("Could not download Nebula executable.");
|
|
33
|
-
}
|
|
34
|
-
await writeFile(`${tmpDir}/nebula.tar.gz`, Readable.from(file.body));
|
|
35
|
-
console.log("Extracting Nebula...");
|
|
36
|
-
await promisify(execFile)("tar", [
|
|
37
|
-
"-xf",
|
|
38
|
-
`${tmpDir}/nebula.tar.gz`,
|
|
39
|
-
"-C",
|
|
40
|
-
tmpDir,
|
|
41
|
-
]);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const loadConfig = async (): Promise<Config> => {
|
|
45
|
-
try {
|
|
46
|
-
const result = await readFile(`${configDir}/config.json`, "utf-8");
|
|
47
|
-
const config = JSON.parse(result);
|
|
48
|
-
return Config.parse(config);
|
|
49
|
-
} catch (_error) {
|
|
50
|
-
// no config yet
|
|
51
|
-
return { instances: [] };
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const saveConfig = async (): Promise<void> => {
|
|
56
|
-
await writeFile(`${configDir}/config.json`, JSON.stringify(config, null, 2));
|
|
57
|
-
await chmod(`${configDir}/config.json`, 0o600);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const getNebulaCert = async (instance: Instance) => {
|
|
61
|
-
const response = await fetch(`${instance.url}/api/nebula/cert`, {
|
|
62
|
-
headers: {
|
|
63
|
-
authorization: `Bearer ${instance.apiKey}`,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new Error(`Failed to fetch Nebula certificate: ${response.status}`);
|
|
68
|
-
}
|
|
69
|
-
const { nebulaConfig } = (await response.json()) as { nebulaConfig: string };
|
|
70
|
-
await writeFile(`${tmpDir}/nebula.yml`, nebulaConfig);
|
|
71
|
-
await chmod(`${tmpDir}/nebula.yml`, 0o600);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const connectNebula = async (instance: {
|
|
75
|
-
url: string;
|
|
76
|
-
apiKey: string;
|
|
77
|
-
}): Promise<void> => {
|
|
78
|
-
await getNebulaCert(instance);
|
|
79
|
-
const nebula = spawn(
|
|
80
|
-
"sudo",
|
|
81
|
-
[`${tmpDir}/nebula`, "-config", `${tmpDir}/nebula.yml`],
|
|
82
|
-
{
|
|
83
|
-
stdio: "inherit",
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
const interval = setInterval(
|
|
87
|
-
async () => {
|
|
88
|
-
// refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
|
|
89
|
-
await getNebulaCert(instance);
|
|
90
|
-
nebula.kill("SIGHUP");
|
|
91
|
-
},
|
|
92
|
-
10 * 60 * 1000,
|
|
93
|
-
);
|
|
94
|
-
await new Promise((resolve) => nebula.on("exit", resolve));
|
|
95
|
-
clearInterval(interval);
|
|
96
|
-
};
|
|
6
|
+
const config = await loadConfig();
|
|
97
7
|
|
|
98
8
|
const setupConnection = async () => {
|
|
99
9
|
const result = await prompts([
|
|
@@ -112,7 +22,7 @@ const setupConnection = async () => {
|
|
|
112
22
|
return;
|
|
113
23
|
}
|
|
114
24
|
config.instances.push({ url: result.url, apiKey: result.apiKey });
|
|
115
|
-
await saveConfig();
|
|
25
|
+
await saveConfig(config);
|
|
116
26
|
};
|
|
117
27
|
|
|
118
28
|
const removeConnection = async () => {
|
|
@@ -140,13 +50,11 @@ const removeConnection = async () => {
|
|
|
140
50
|
]);
|
|
141
51
|
if (confirm === true) {
|
|
142
52
|
config.instances.splice(connection, 1);
|
|
143
|
-
await saveConfig();
|
|
53
|
+
await saveConfig(config);
|
|
144
54
|
}
|
|
145
55
|
};
|
|
146
56
|
|
|
147
|
-
|
|
148
|
-
const config = await loadConfig();
|
|
149
|
-
while (true) {
|
|
57
|
+
const mainMenu = async (): Promise<boolean> => {
|
|
150
58
|
const { action } = await prompts([
|
|
151
59
|
{
|
|
152
60
|
type: "select",
|
|
@@ -189,8 +97,19 @@ while (true) {
|
|
|
189
97
|
} else if (action === "remove") {
|
|
190
98
|
await removeConnection();
|
|
191
99
|
} else {
|
|
192
|
-
|
|
100
|
+
return false;
|
|
193
101
|
}
|
|
102
|
+
return true;
|
|
194
103
|
}
|
|
195
104
|
|
|
196
|
-
await
|
|
105
|
+
await installNebula();
|
|
106
|
+
try {
|
|
107
|
+
while (true) {
|
|
108
|
+
const shouldContinue = await mainMenu();
|
|
109
|
+
if (!shouldContinue) {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
await cleanupNebula();
|
|
115
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|