@infosupport/huddle-cli 0.0.0-experiment-48.15.1 → 1.2.3
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/api.js +1 -14
- package/dist/config.js +0 -9
- package/dist/init.js +4 -55
- package/dist/runtime.js +6 -43
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.del = exports.put = exports.post = exports.get = exports.ApiError = void 0;
|
|
4
4
|
exports.setBaseUrl = setBaseUrl;
|
|
5
5
|
exports.apiCall = apiCall;
|
|
6
|
-
const config_1 = require("./config");
|
|
7
6
|
let baseUrl = normalizeBaseUrl(process.env.HUDDLE_URL ?? 'http://localhost:3000');
|
|
8
7
|
class ApiError extends Error {
|
|
9
8
|
status;
|
|
@@ -18,19 +17,11 @@ function setBaseUrl(url) {
|
|
|
18
17
|
baseUrl = normalizeBaseUrl(url);
|
|
19
18
|
}
|
|
20
19
|
async function apiCall(method, path, body) {
|
|
21
|
-
const headers = {};
|
|
22
|
-
if (body !== undefined)
|
|
23
|
-
headers['content-type'] = 'application/json';
|
|
24
|
-
// Operator-auth: stuur het token als Bearer mee zodat de CLI de control-plane
|
|
25
|
-
// -auth passeert. Zonder token krijgen we een 401 met een duidelijke hint.
|
|
26
|
-
const token = (0, config_1.operatorToken)();
|
|
27
|
-
if (token)
|
|
28
|
-
headers['authorization'] = `Bearer ${token}`;
|
|
29
20
|
let res;
|
|
30
21
|
try {
|
|
31
22
|
res = await fetch(`${baseUrl}${path}`, {
|
|
32
23
|
method,
|
|
33
|
-
headers,
|
|
24
|
+
headers: body !== undefined ? { 'content-type': 'application/json' } : {},
|
|
34
25
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
35
26
|
});
|
|
36
27
|
}
|
|
@@ -41,10 +32,6 @@ async function apiCall(method, path, body) {
|
|
|
41
32
|
const raw = await res.text();
|
|
42
33
|
const payload = parsePayload(raw);
|
|
43
34
|
if (!res.ok) {
|
|
44
|
-
if (res.status === 401) {
|
|
45
|
-
throw new ApiError(`${method} ${path} -> 401: operator authentication required. ` +
|
|
46
|
-
`Set HUDDLE_OPERATOR_TOKEN (find it in the huddle container logs, or re-run \`huddle init\`).`, 401);
|
|
47
|
-
}
|
|
48
35
|
const msg = errorMessage(payload) ?? res.statusText;
|
|
49
36
|
throw new ApiError(`${method} ${path} -> ${res.status}: ${msg}`, res.status);
|
|
50
37
|
}
|
package/dist/config.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.configPath = configPath;
|
|
7
7
|
exports.readConfig = readConfig;
|
|
8
8
|
exports.writeConfig = writeConfig;
|
|
9
|
-
exports.operatorToken = operatorToken;
|
|
10
9
|
exports.activeExperiment = activeExperiment;
|
|
11
10
|
exports.imageTag = imageTag;
|
|
12
11
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -29,14 +28,6 @@ function writeConfig(config) {
|
|
|
29
28
|
fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
30
29
|
fs_1.default.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
|
|
31
30
|
}
|
|
32
|
-
/** Operator-token voor API-auth: env wint, anders uit de config. */
|
|
33
|
-
function operatorToken() {
|
|
34
|
-
const env = process.env.HUDDLE_OPERATOR_TOKEN?.trim();
|
|
35
|
-
if (env)
|
|
36
|
-
return env;
|
|
37
|
-
const t = readConfig().operatorToken;
|
|
38
|
-
return t && t.trim() ? t.trim() : undefined;
|
|
39
|
-
}
|
|
40
31
|
/** Active experiment number, or undefined when running on stable. */
|
|
41
32
|
function activeExperiment() {
|
|
42
33
|
const cfg = readConfig();
|
package/dist/init.js
CHANGED
|
@@ -5,11 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.runInit = runInit;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
9
8
|
const utils_1 = require("./utils");
|
|
10
9
|
const runtime_1 = require("./runtime");
|
|
11
10
|
const images_1 = require("./images");
|
|
12
|
-
const config_1 = require("./config");
|
|
13
11
|
const fs_1 = __importDefault(require("fs"));
|
|
14
12
|
const CONTAINER = 'huddle';
|
|
15
13
|
const VOLUME = 'huddle-data';
|
|
@@ -85,20 +83,10 @@ async function runInit(opts, images) {
|
|
|
85
83
|
// gateway and devcontainers across two filesystems, and Unix sockets are
|
|
86
84
|
// unreliable on such a drvfs/9p mount anyway.
|
|
87
85
|
const hostTmpSockets = '/tmp/dc-sockets';
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// the directory explicitly in the machine VM; the socket lives there too.
|
|
93
|
-
console.log((0, utils_1.dim)(` (Podman: creating ${hostTmpSockets} in the machine VM)`));
|
|
94
|
-
if (!runSilent(`podman machine ssh "mkdir -p ${hostTmpSockets}"`)) {
|
|
95
|
-
console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets} in the Podman VM.`));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// Docker Desktop creates a missing bind source itself in the VM on `run`.
|
|
100
|
-
console.log((0, utils_1.dim)(` (${runtime.name}: the engine creates ${hostTmpSockets} in the VM)`));
|
|
101
|
-
}
|
|
86
|
+
if (process.platform === 'win32') {
|
|
87
|
+
// Cannot be created locally from Windows; the engine creates a missing
|
|
88
|
+
// bind source itself in the VM on `run`.
|
|
89
|
+
console.log((0, utils_1.dim)(` (Windows: the engine creates ${hostTmpSockets} in the VM)`));
|
|
102
90
|
}
|
|
103
91
|
else {
|
|
104
92
|
try {
|
|
@@ -109,55 +97,16 @@ async function runInit(opts, images) {
|
|
|
109
97
|
}
|
|
110
98
|
}
|
|
111
99
|
console.log((0, utils_1.dim)(`Starting container`));
|
|
112
|
-
// The gateway is engine-agnostic (talks the Docker-compatible API on the
|
|
113
|
-
// mounted socket), but does need to know it's Podman: it then sets
|
|
114
|
-
// `--security-opt label=disable` on every devcontainer so it can reach the
|
|
115
|
-
// SELinux-labeled proxy socket.
|
|
116
|
-
const securityOptFlags = runtime.securityOpts.map((opt) => ` --security-opt ${opt}`).join('');
|
|
117
|
-
// Operator-token voor de control-plane-auth. Hergebruik het token uit de
|
|
118
|
-
// config (zodat een bestaande browser-sessie/CLI blijft werken over re-inits),
|
|
119
|
-
// anders genereer er één. We geven het aan de gateway mee via env én bewaren
|
|
120
|
-
// het lokaal zodat volgende `huddle`-commando's zich kunnen authenticeren.
|
|
121
|
-
const cfg = (0, config_1.readConfig)();
|
|
122
|
-
const operatorToken = process.env.HUDDLE_OPERATOR_TOKEN?.trim() ||
|
|
123
|
-
(cfg.operatorToken && cfg.operatorToken.trim()) ||
|
|
124
|
-
crypto_1.default.randomBytes(32).toString('base64url');
|
|
125
|
-
if (cfg.operatorToken !== operatorToken) {
|
|
126
|
-
(0, config_1.writeConfig)({ ...cfg, operatorToken });
|
|
127
|
-
}
|
|
128
|
-
// The container is created on the engine's default network first (with -p),
|
|
129
|
-
// then joins devcontainer-net (--internal) afterwards: Docker skips the host
|
|
130
|
-
// port-forward entirely when a container is created directly on an --internal
|
|
131
|
-
// network (moby/moby#36174). Which source IP the gateway sees for forwarded
|
|
132
|
-
// traffic no longer matters — the control plane authenticates with the
|
|
133
|
-
// operator token instead of source-IP filtering.
|
|
134
100
|
run(`${rt} run -d` +
|
|
135
101
|
` --name ${CONTAINER}` +
|
|
136
102
|
` --network ${runtime.defaultNetwork}` +
|
|
137
|
-
securityOptFlags +
|
|
138
|
-
` -e HUDDLE_RUNTIME=${runtime.name}` +
|
|
139
|
-
` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
|
|
140
103
|
` -p ${HOST_PORT}:3000` +
|
|
141
104
|
` -v ${VOLUME}:/data` +
|
|
142
105
|
` -v ${runtime.socketPath}:/var/run/docker.sock` +
|
|
143
106
|
` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
|
|
144
107
|
(0, images_1.gatewayEnvFlags)(images) +
|
|
145
108
|
` ${IMAGE}`);
|
|
146
|
-
// Attaching devcontainer-net after the container has started pollutes
|
|
147
|
-
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
148
|
-
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
149
|
-
// index.ts).
|
|
150
109
|
runSilent(`${rt} network connect ${INTERNAL_NET} ${CONTAINER}`);
|
|
151
110
|
console.log();
|
|
152
111
|
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
153
|
-
console.log();
|
|
154
|
-
// Volledige auto-login-link: open deze en de portal logt je automatisch in met
|
|
155
|
-
// het operator-token (de frontend leest ?token=..., logt in en verwijdert het
|
|
156
|
-
// daarna uit de adresbalk). Zo hoef je niets te plakken.
|
|
157
|
-
const loginUrl = `http://localhost:${HOST_PORT}/?token=${encodeURIComponent(operatorToken)}`;
|
|
158
|
-
console.log((0, utils_1.bold)('Open the portal (auto-login link):'));
|
|
159
|
-
console.log((0, utils_1.green)(` ${loginUrl}`));
|
|
160
|
-
console.log((0, utils_1.dim)(' Opens the portal and logs you in automatically.'));
|
|
161
|
-
console.log((0, utils_1.dim)(` Manual token (if you prefer to paste it): ${operatorToken}`));
|
|
162
|
-
console.log((0, utils_1.dim)(' The token is also saved to ~/.huddle/config.json for the CLI.'));
|
|
163
112
|
}
|
package/dist/runtime.js
CHANGED
|
@@ -15,22 +15,6 @@ function isAvailable(runtime) {
|
|
|
15
15
|
// 'info' only succeeds if the daemon/machine is actually reachable.
|
|
16
16
|
return commandOutput(`${runtime} info`) !== undefined;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Bepaalt de ECHTE engine achter een commando, of undefined als de engine niet
|
|
20
|
-
* bereikbaar is. Vertrouw niet op de commandonaam: `docker` is vaak een
|
|
21
|
-
* symlink/shim naar Podman (podman-docker) en Podman emuleert dan zelfs
|
|
22
|
-
* `docker --version`. Podman's `info` kent daarentegen het veld
|
|
23
|
-
* Host.ServiceIsRemote; Docker's info-schema niet. Dat is een betrouwbaar
|
|
24
|
-
* onderscheid dat ook via de shim werkt.
|
|
25
|
-
*/
|
|
26
|
-
function detectEngine(command) {
|
|
27
|
-
if (commandOutput(`${command} info --format "{{.Host.ServiceIsRemote}}"`) !== undefined) {
|
|
28
|
-
return 'podman';
|
|
29
|
-
}
|
|
30
|
-
if (isAvailable(command))
|
|
31
|
-
return 'docker';
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
18
|
function podmanSocketPath() {
|
|
35
19
|
// Podman knows where its own (rootless or rootful) socket lives.
|
|
36
20
|
const reported = commandOutput(`podman info --format "{{.Host.RemoteSocket.Path}}"`);
|
|
@@ -42,30 +26,11 @@ function podmanSocketPath() {
|
|
|
42
26
|
function dockerSocketPath() {
|
|
43
27
|
return process.platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock';
|
|
44
28
|
}
|
|
45
|
-
function podmanIsRemote() {
|
|
46
|
-
// Op macOS/Windows draait Podman altijd in een `podman machine`-VM; ook op
|
|
47
|
-
// Linux kan de client op een remote socket wijzen. `ServiceIsRemote` is de
|
|
48
|
-
// gezaghebbende bron.
|
|
49
|
-
return commandOutput(`podman info --format "{{.Host.ServiceIsRemote}}"`) === 'true';
|
|
50
|
-
}
|
|
51
29
|
function buildRuntime(name) {
|
|
52
30
|
if (name === 'podman') {
|
|
53
|
-
return {
|
|
54
|
-
name,
|
|
55
|
-
socketPath: podmanSocketPath(),
|
|
56
|
-
defaultNetwork: 'podman',
|
|
57
|
-
isRemote: podmanIsRemote(),
|
|
58
|
-
securityOpts: ['label=disable'],
|
|
59
|
-
};
|
|
31
|
+
return { name, socketPath: podmanSocketPath(), defaultNetwork: 'podman' };
|
|
60
32
|
}
|
|
61
|
-
return {
|
|
62
|
-
name,
|
|
63
|
-
socketPath: dockerSocketPath(),
|
|
64
|
-
defaultNetwork: 'bridge',
|
|
65
|
-
// Docker Desktop (macOS/Windows) draait in een VM; native Docker op Linux niet.
|
|
66
|
-
isRemote: process.platform !== 'linux',
|
|
67
|
-
securityOpts: [],
|
|
68
|
-
};
|
|
33
|
+
return { name, socketPath: dockerSocketPath(), defaultNetwork: 'bridge' };
|
|
69
34
|
}
|
|
70
35
|
function parseRuntimeName(value) {
|
|
71
36
|
const normalized = value.toLowerCase().trim();
|
|
@@ -87,12 +52,10 @@ function resolveRuntime(explicit) {
|
|
|
87
52
|
}
|
|
88
53
|
return buildRuntime(name);
|
|
89
54
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (detected)
|
|
95
|
-
return buildRuntime(detected);
|
|
55
|
+
if (isAvailable('docker'))
|
|
56
|
+
return buildRuntime('docker');
|
|
57
|
+
if (isAvailable('podman'))
|
|
58
|
+
return buildRuntime('podman');
|
|
96
59
|
throw new Error('No working container runtime found. Install and start Docker or Podman,\n' +
|
|
97
60
|
'or pick one explicitly with --runtime <docker|podman> or the HUDDLE_RUNTIME env var.');
|
|
98
61
|
}
|
package/package.json
CHANGED