onedeploy-cli 0.1.1 → 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 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,80 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { execFile, spawn } from "node:child_process";
3
- import { randomUUID } from "node:crypto";
4
- import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
- import { homedir } from "node:os";
6
- import { Readable } from "node:stream";
7
- import { promisify } from "node:util";
8
2
  import prompts from "prompts";
9
- import { y } from "yedra";
10
- const nebulaUrl = `https://github.com/slackhq/nebula/releases/download/v1.9.6/nebula-linux-amd64.tar.gz`;
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
- const Instance = y.object({
16
- url: y.string(),
17
- apiKey: y.string(),
18
- });
19
- const Config = y.object({
20
- instances: Instance.array(),
21
- });
22
- const installNebula = async () => {
23
- console.log("Downloading Nebula...");
24
- const file = await fetch(nebulaUrl);
25
- if (file.body === null) {
26
- throw new Error("Could not download Nebula executable.");
27
- }
28
- await writeFile(`${tmpDir}/nebula.tar.gz`, Readable.from(file.body));
29
- console.log("Extracting Nebula...");
30
- await promisify(execFile)("tar", [
31
- "-xf",
32
- `${tmpDir}/nebula.tar.gz`,
33
- "-C",
34
- tmpDir,
35
- ]);
36
- };
37
- const loadConfig = async () => {
38
- try {
39
- const result = await readFile(`${configDir}/config.json`, "utf-8");
40
- const config = JSON.parse(result);
41
- return Config.parse(config);
42
- }
43
- catch (_error) {
44
- // no config yet
45
- return { instances: [] };
46
- }
47
- };
48
- const saveConfig = async () => {
49
- await writeFile(`${configDir}/config.json`, JSON.stringify(config, null, 2));
50
- await chmod(`${configDir}/config.json`, 0o600);
51
- };
52
- const getNebulaCert = async (instance) => {
53
- const response = await fetch(`${instance.url}/api/nebula/cert`, {
54
- headers: {
55
- authorization: `Bearer ${instance.apiKey}`,
56
- },
57
- });
58
- if (!response.ok) {
59
- throw new Error(`Failed to fetch Nebula certificate: ${response.status}`);
60
- }
61
- const { nebulaConfig } = (await response.json());
62
- await writeFile(`${tmpDir}/nebula.yml`, nebulaConfig);
63
- await chmod(`${tmpDir}/nebula.yml`, 0o600);
64
- };
65
- const connectNebula = async (instance) => {
66
- await getNebulaCert(instance);
67
- const nebula = spawn("sudo", [`${tmpDir}/nebula`, "-config", `${tmpDir}/nebula.yml`], {
68
- stdio: "inherit",
69
- });
70
- const interval = setInterval(async () => {
71
- // refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
72
- await getNebulaCert(instance);
73
- nebula.kill("SIGHUP");
74
- }, 10 * 60 * 1000);
75
- await new Promise((resolve) => nebula.on("exit", resolve));
76
- clearInterval(interval);
77
- };
3
+ import { loadConfig, saveConfig } from "./config.js";
4
+ import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
5
+ const config = await loadConfig();
78
6
  const setupConnection = async () => {
79
7
  const result = await prompts([
80
8
  {
@@ -92,7 +20,7 @@ const setupConnection = async () => {
92
20
  return;
93
21
  }
94
22
  config.instances.push({ url: result.url, apiKey: result.apiKey });
95
- await saveConfig();
23
+ await saveConfig(config);
96
24
  };
97
25
  const removeConnection = async () => {
98
26
  const { connection } = await prompts([
@@ -119,12 +47,10 @@ const removeConnection = async () => {
119
47
  ]);
120
48
  if (confirm === true) {
121
49
  config.instances.splice(connection, 1);
122
- await saveConfig();
50
+ await saveConfig(config);
123
51
  }
124
52
  };
125
- await installNebula();
126
- const config = await loadConfig();
127
- while (true) {
53
+ const mainMenu = async () => {
128
54
  const { action } = await prompts([
129
55
  {
130
56
  type: "select",
@@ -170,7 +96,19 @@ while (true) {
170
96
  await removeConnection();
171
97
  }
172
98
  else {
173
- break;
99
+ return false;
174
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();
175
114
  }
176
- 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.1",
3
+ "version": "0.1.2",
4
4
  "description": "CLI tool for connecting to OneDeploy via Nebula",
5
5
  "keywords": [
6
6
  "onedeploy",
package/src/index.ts CHANGED
@@ -1,100 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { execFile, spawn } from "node:child_process";
3
- import { randomUUID } from "node:crypto";
4
- import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
- import { homedir } from "node:os";
6
- import { Readable } from "node:stream";
7
- import { promisify } from "node:util";
8
2
  import prompts from "prompts";
9
- import { y } from "yedra";
3
+ import { loadConfig, saveConfig } from "./config.js";
4
+ import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
10
5
 
11
- const nebulaUrl = `https://github.com/slackhq/nebula/releases/download/v1.9.6/nebula-linux-amd64.tar.gz`;
12
- const configDir = `${homedir()}/.config/onedeploy`;
13
- const tmpDir = `/tmp/onedeploy-${randomUUID()}`;
14
- await mkdir(configDir, { recursive: true });
15
- await mkdir(tmpDir, { recursive: true });
16
-
17
- const Instance = y.object({
18
- url: y.string(),
19
- apiKey: y.string(),
20
- });
21
-
22
- const Config = y.object({
23
- instances: Instance.array(),
24
- });
25
-
26
- type Instance = y.Typeof<typeof Instance>;
27
- type Config = y.Typeof<typeof Config>;
28
-
29
- const installNebula = async (): Promise<void> => {
30
- console.log("Downloading Nebula...");
31
- const file = await fetch(nebulaUrl);
32
- if (file.body === null) {
33
- throw new Error("Could not download Nebula executable.");
34
- }
35
- await writeFile(`${tmpDir}/nebula.tar.gz`, Readable.from(file.body));
36
- console.log("Extracting Nebula...");
37
- await promisify(execFile)("tar", [
38
- "-xf",
39
- `${tmpDir}/nebula.tar.gz`,
40
- "-C",
41
- tmpDir,
42
- ]);
43
- };
44
-
45
- const loadConfig = async (): Promise<Config> => {
46
- try {
47
- const result = await readFile(`${configDir}/config.json`, "utf-8");
48
- const config = JSON.parse(result);
49
- return Config.parse(config);
50
- } catch (_error) {
51
- // no config yet
52
- return { instances: [] };
53
- }
54
- };
55
-
56
- const saveConfig = async (): Promise<void> => {
57
- await writeFile(`${configDir}/config.json`, JSON.stringify(config, null, 2));
58
- await chmod(`${configDir}/config.json`, 0o600);
59
- };
60
-
61
- const getNebulaCert = async (instance: Instance) => {
62
- const response = await fetch(`${instance.url}/api/nebula/cert`, {
63
- headers: {
64
- authorization: `Bearer ${instance.apiKey}`,
65
- },
66
- });
67
- if (!response.ok) {
68
- throw new Error(`Failed to fetch Nebula certificate: ${response.status}`);
69
- }
70
- const { nebulaConfig } = (await response.json()) as { nebulaConfig: string };
71
- await writeFile(`${tmpDir}/nebula.yml`, nebulaConfig);
72
- await chmod(`${tmpDir}/nebula.yml`, 0o600);
73
- };
74
-
75
- const connectNebula = async (instance: {
76
- url: string;
77
- apiKey: string;
78
- }): Promise<void> => {
79
- await getNebulaCert(instance);
80
- const nebula = spawn(
81
- "sudo",
82
- [`${tmpDir}/nebula`, "-config", `${tmpDir}/nebula.yml`],
83
- {
84
- stdio: "inherit",
85
- },
86
- );
87
- const interval = setInterval(
88
- async () => {
89
- // refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
90
- await getNebulaCert(instance);
91
- nebula.kill("SIGHUP");
92
- },
93
- 10 * 60 * 1000,
94
- );
95
- await new Promise((resolve) => nebula.on("exit", resolve));
96
- clearInterval(interval);
97
- };
6
+ const config = await loadConfig();
98
7
 
99
8
  const setupConnection = async () => {
100
9
  const result = await prompts([
@@ -113,7 +22,7 @@ const setupConnection = async () => {
113
22
  return;
114
23
  }
115
24
  config.instances.push({ url: result.url, apiKey: result.apiKey });
116
- await saveConfig();
25
+ await saveConfig(config);
117
26
  };
118
27
 
119
28
  const removeConnection = async () => {
@@ -141,13 +50,11 @@ const removeConnection = async () => {
141
50
  ]);
142
51
  if (confirm === true) {
143
52
  config.instances.splice(connection, 1);
144
- await saveConfig();
53
+ await saveConfig(config);
145
54
  }
146
55
  };
147
56
 
148
- await installNebula();
149
- const config = await loadConfig();
150
- while (true) {
57
+ const mainMenu = async (): Promise<boolean> => {
151
58
  const { action } = await prompts([
152
59
  {
153
60
  type: "select",
@@ -190,8 +97,19 @@ while (true) {
190
97
  } else if (action === "remove") {
191
98
  await removeConnection();
192
99
  } else {
193
- break;
100
+ return false;
194
101
  }
102
+ return true;
195
103
  }
196
104
 
197
- await rm(tmpDir, { recursive: true, force: true });
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,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};