@alicloud/autowonder-managed 0.0.0-stage → 0.4.1
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/connect.cjs +46 -0
- package/package.json +1 -6
- package/README.md +0 -3
package/connect.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { spawnSync } = require("node:child_process");
|
|
5
|
+
const { parseArgs } = require("node:util");
|
|
6
|
+
|
|
7
|
+
async function connect(argv, platform = process.platform, fetchScript = fetch, launch = spawnSync) {
|
|
8
|
+
if (argv[0] !== "connect") throw Error("Usage: connect --server-url <platform-url> --token <registration-token>");
|
|
9
|
+
const { values } = parseArgs({ args: argv.slice(1), options: {
|
|
10
|
+
"server-url": { type: "string" }, token: { type: "string" }
|
|
11
|
+
} });
|
|
12
|
+
const base = new URL(values["server-url"]);
|
|
13
|
+
const local = ["localhost", "127.0.0.1", "[::1]"].includes(base.hostname);
|
|
14
|
+
if ((base.protocol !== "https:" && !(local && base.protocol === "http:")) ||
|
|
15
|
+
base.username || base.password || base.search || base.hash) throw Error("Invalid platform URL");
|
|
16
|
+
const token = values.token;
|
|
17
|
+
if (!token || token.length > 8192 || /\s|\0/.test(token)) throw Error("Invalid registration token");
|
|
18
|
+
const os = { win32: "windows", darwin: "macos", linux: "linux" }[platform];
|
|
19
|
+
if (!os) throw Error("Unsupported operating system");
|
|
20
|
+
base.pathname = base.pathname.replace(/\/+$/, "") + "/api/daemon/runtime-bootstrap/" + os;
|
|
21
|
+
// Enrollment happens in the platform installer. Its initial GET carries no credential.
|
|
22
|
+
const response = await fetchScript(base, { redirect: "error", signal: AbortSignal.timeout(30000) });
|
|
23
|
+
if (!response.ok || !response.body) throw Error("Platform installer unavailable (HTTP " + response.status + ")");
|
|
24
|
+
const chunks = [];
|
|
25
|
+
let size = 0;
|
|
26
|
+
for await (const chunk of response.body) {
|
|
27
|
+
size += chunk.length;
|
|
28
|
+
if (size > 96 * 1024) throw Error("Platform installer exceeds size limit");
|
|
29
|
+
chunks.push(chunk);
|
|
30
|
+
}
|
|
31
|
+
if (!size) throw Error("Empty platform installer");
|
|
32
|
+
const script = Buffer.concat(chunks).toString("utf8");
|
|
33
|
+
let executable = "/bin/bash", args = ["-c", script];
|
|
34
|
+
if (platform === "win32") {
|
|
35
|
+
executable = "powershell.exe";
|
|
36
|
+
const program = "$ErrorActionPreference='Stop'; $ticket=[Console]::In.ReadLine(); & {\n" + script + "\n} $ticket";
|
|
37
|
+
args = ["-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(program, "utf16le").toString("base64")];
|
|
38
|
+
}
|
|
39
|
+
const child = launch(executable, args, { input: token + "\n", stdio: ["pipe", "inherit", "inherit"] });
|
|
40
|
+
if (child.error || child.status !== 0) throw Error("Managed runtime installation failed");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (require.main === module) {
|
|
44
|
+
connect(process.argv.slice(2)).catch(() => { console.error("Managed runtime connection failed. Check the platform URL, registration token and installer output."); process.exitCode = 1; });
|
|
45
|
+
}
|
|
46
|
+
module.exports = { connect };
|
package/package.json
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@alicloud/autowonder-managed",
|
|
3
|
-
"version": "0.0.0-stage",
|
|
4
|
-
"stub": true,
|
|
5
|
-
"description": "Temporary package placeholder for staged publishing"
|
|
6
|
-
}
|
|
1
|
+
{"name":"@alicloud/autowonder-managed","version":"0.4.1","license":"Apache-2.0","bin":{"autowonder-managed":"connect.cjs"},"engines":{"node":">=18"},"files":["connect.cjs"]}
|
package/README.md
DELETED