onedeploy-cli 0.1.5 → 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 CHANGED
@@ -5,7 +5,6 @@ const configDir = `${homedir()}/.config/onedeploy`;
5
5
  await mkdir(configDir, { recursive: true });
6
6
  const Instance = y.object({
7
7
  url: y.string(),
8
- apiKey: y.string(),
9
8
  });
10
9
  const Config = y.object({
11
10
  instances: Instance.array(),
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.apiKey === undefined || result.url === undefined) {
18
+ if (result.url === undefined) {
24
19
  return;
25
20
  }
26
- config.instances.push({ url: result.url, apiKey: result.apiKey });
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";
@@ -9,10 +10,15 @@ import { parse } from "yaml";
9
10
  const getNebulaPackageName = () => {
10
11
  switch (process.platform) {
11
12
  case "linux":
12
- if (process.arch !== "x64") {
13
+ if (process.arch === "x64") {
14
+ return `nebula-linux-amd64.tar.gz`;
15
+ }
16
+ else if (process.arch === "arm64") {
17
+ return `nebula-linux-arm64.tar.gz`;
18
+ }
19
+ else {
13
20
  throw new Error(`Unsupported architecture: ${process.arch}`);
14
21
  }
15
- return `nebula-linux-amd64.tar.gz`;
16
22
  case "darwin":
17
23
  return `nebula-darwin.zip`;
18
24
  case "win32":
@@ -47,10 +53,10 @@ export const installNebula = async () => {
47
53
  export const cleanupNebula = async () => {
48
54
  await rm(tmpDir, { recursive: true, force: true });
49
55
  };
50
- export const getNebulaCert = async (instance) => {
56
+ export const getNebulaCert = async (instance, session) => {
51
57
  const response = await fetch(`${instance.url}/api/nebula/cert`, {
52
58
  headers: {
53
- authorization: `Bearer ${instance.apiKey}`,
59
+ authorization: `Bearer ${session}`,
54
60
  },
55
61
  });
56
62
  if (!response.ok) {
@@ -81,13 +87,57 @@ export const getNebulaCert = async (instance) => {
81
87
  process.stdout.write(stdout);
82
88
  };
83
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
+ };
84
133
  export const connectNebula = async (instance) => {
85
- await getNebulaCert(instance);
134
+ const session = await getSession(instance);
135
+ await getNebulaCert(instance, session);
86
136
  isNebulaRunning = true;
87
137
  const nebula = spawn(`${tmpDir}/nebula`, ["-config", `${tmpDir}/nebula.yml`], { stdio: "inherit" });
88
138
  const interval = setInterval(async () => {
89
139
  // refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
90
- await getNebulaCert(instance);
140
+ await getNebulaCert(instance, session);
91
141
  nebula.kill("SIGHUP");
92
142
  }, 10 * 60 * 1000);
93
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.5",
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.2.3",
36
- "@types/node": "^24.3.1",
35
+ "@biomejs/biome": "^2.3.1",
36
+ "@types/node": "^24.9.1",
37
37
  "@types/prompts": "^2.4.9",
38
- "typescript": "^5.9.2"
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.17.9"
43
+ "yedra": "^0.18.0"
44
44
  }
45
45
  }