onedeploy-cli 0.1.4 → 0.1.5
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/index.js +7 -3
- package/dist/nebula.js +14 -0
- package/package.json +1 -1
- package/src/index.ts +0 -122
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import prompts from "prompts";
|
|
3
3
|
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
-
import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
|
|
4
|
+
import { cleanupNebula, connectNebula, installNebula, isNebulaRunning, } from "./nebula.js";
|
|
5
5
|
if (process.argv.includes("--version")) {
|
|
6
6
|
console.log("onedeploy-cli version 0.1.4");
|
|
7
7
|
process.exit();
|
|
@@ -104,8 +104,12 @@ const mainMenu = async () => {
|
|
|
104
104
|
}
|
|
105
105
|
return true;
|
|
106
106
|
};
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
process.on("SIGINT", () => {
|
|
108
|
+
if (!isNebulaRunning) {
|
|
109
|
+
process.exit();
|
|
110
|
+
}
|
|
111
|
+
// ignore SIGINTs to continue after Nebula is disconnected
|
|
112
|
+
});
|
|
109
113
|
await installNebula();
|
|
110
114
|
try {
|
|
111
115
|
while (true) {
|
package/dist/nebula.js
CHANGED
|
@@ -67,10 +67,23 @@ export const getNebulaCert = async (instance) => {
|
|
|
67
67
|
"-path",
|
|
68
68
|
`${tmpDir}/nebula-debug.crt`,
|
|
69
69
|
]);
|
|
70
|
+
// in case our local time isn't correct, wait for the certificate to become valid
|
|
71
|
+
const validFrom = stdout.match(/Not before: ([\d-]+ [\d:]+ \+\d+)/);
|
|
72
|
+
if (validFrom === null) {
|
|
73
|
+
throw new Error("Invalid Nebula certificate: Missing 'Not before' field.");
|
|
74
|
+
}
|
|
75
|
+
const validFromDate = new Date(validFrom[1]);
|
|
76
|
+
if (validFromDate > new Date()) {
|
|
77
|
+
const waitTime = validFromDate.getTime() - Date.now();
|
|
78
|
+
console.log(`Your system clock is running slow! Waiting ${Math.ceil(waitTime / 1000)} seconds for Nebula certificate to become valid...`);
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
80
|
+
}
|
|
70
81
|
process.stdout.write(stdout);
|
|
71
82
|
};
|
|
83
|
+
export let isNebulaRunning = false;
|
|
72
84
|
export const connectNebula = async (instance) => {
|
|
73
85
|
await getNebulaCert(instance);
|
|
86
|
+
isNebulaRunning = true;
|
|
74
87
|
const nebula = spawn(`${tmpDir}/nebula`, ["-config", `${tmpDir}/nebula.yml`], { stdio: "inherit" });
|
|
75
88
|
const interval = setInterval(async () => {
|
|
76
89
|
// refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
|
|
@@ -78,5 +91,6 @@ export const connectNebula = async (instance) => {
|
|
|
78
91
|
nebula.kill("SIGHUP");
|
|
79
92
|
}, 10 * 60 * 1000);
|
|
80
93
|
await new Promise((resolve) => nebula.on("exit", resolve));
|
|
94
|
+
isNebulaRunning = false;
|
|
81
95
|
clearInterval(interval);
|
|
82
96
|
};
|
package/package.json
CHANGED
package/src/index.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import prompts from "prompts";
|
|
3
|
-
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
-
import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
|
|
5
|
-
|
|
6
|
-
if (process.argv.includes("--version")) {
|
|
7
|
-
console.log("onedeploy-cli version 0.1.4");
|
|
8
|
-
process.exit();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const config = await loadConfig();
|
|
12
|
-
|
|
13
|
-
const setupConnection = async () => {
|
|
14
|
-
const result = await prompts([
|
|
15
|
-
{
|
|
16
|
-
type: "text",
|
|
17
|
-
name: "url",
|
|
18
|
-
message: "Enter OneDeploy URL",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: "password",
|
|
22
|
-
name: "apiKey",
|
|
23
|
-
message: "Enter OneDeploy API key",
|
|
24
|
-
},
|
|
25
|
-
]);
|
|
26
|
-
if (result.apiKey === undefined || result.url === undefined) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
config.instances.push({ url: result.url, apiKey: result.apiKey });
|
|
30
|
-
await saveConfig(config);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const removeConnection = async () => {
|
|
34
|
-
const { connection } = await prompts([
|
|
35
|
-
{
|
|
36
|
-
type: "select",
|
|
37
|
-
name: "connection",
|
|
38
|
-
message: "Select connection to remove",
|
|
39
|
-
choices: config.instances.map((instance, index) => ({
|
|
40
|
-
title: instance.url,
|
|
41
|
-
value: index,
|
|
42
|
-
})),
|
|
43
|
-
},
|
|
44
|
-
]);
|
|
45
|
-
if (connection === undefined) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const { confirm } = await prompts([
|
|
49
|
-
{
|
|
50
|
-
type: "confirm",
|
|
51
|
-
name: "confirm",
|
|
52
|
-
message: `Are you sure you want to remove connection to ${config.instances[connection].url}?`,
|
|
53
|
-
initial: false,
|
|
54
|
-
},
|
|
55
|
-
]);
|
|
56
|
-
if (confirm === true) {
|
|
57
|
-
config.instances.splice(connection, 1);
|
|
58
|
-
await saveConfig(config);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const mainMenu = async (): Promise<boolean> => {
|
|
63
|
-
const { action } = await prompts([
|
|
64
|
-
{
|
|
65
|
-
type: "select",
|
|
66
|
-
name: "action",
|
|
67
|
-
message: "What do you want to do?",
|
|
68
|
-
choices: [
|
|
69
|
-
{
|
|
70
|
-
title: "Connect",
|
|
71
|
-
value: "connect",
|
|
72
|
-
disabled: config.instances.length === 0,
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
title: "Setup new connection",
|
|
76
|
-
value: "setup",
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
title: "Remove connection",
|
|
80
|
-
value: "remove",
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
]);
|
|
85
|
-
if (action === "connect") {
|
|
86
|
-
const result = await prompts([
|
|
87
|
-
{
|
|
88
|
-
type: "select",
|
|
89
|
-
name: "connection",
|
|
90
|
-
message: "Select OneDeploy instance",
|
|
91
|
-
choices: config.instances.map((instance) => ({
|
|
92
|
-
title: instance.url,
|
|
93
|
-
value: instance,
|
|
94
|
-
})),
|
|
95
|
-
},
|
|
96
|
-
]);
|
|
97
|
-
if (result.connection !== undefined) {
|
|
98
|
-
await connectNebula(result.connection);
|
|
99
|
-
}
|
|
100
|
-
} else if (action === "setup") {
|
|
101
|
-
await setupConnection();
|
|
102
|
-
} else if (action === "remove") {
|
|
103
|
-
await removeConnection();
|
|
104
|
-
} else {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// ignore SIGINTs to continue after Nebula is disconnected
|
|
111
|
-
process.on("SIGINT", () => {});
|
|
112
|
-
await installNebula();
|
|
113
|
-
try {
|
|
114
|
-
while (true) {
|
|
115
|
-
const shouldContinue = await mainMenu();
|
|
116
|
-
if (!shouldContinue) {
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} finally {
|
|
121
|
-
await cleanupNebula();
|
|
122
|
-
}
|