@infosupport/huddle-cli 0.0.0-experiment-47.7.1 → 0.0.0-experiment-47.9.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/dist/api.js +14 -1
- package/dist/config.js +9 -0
- package/dist/init.js +29 -7
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -3,6 +3,7 @@ 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");
|
|
6
7
|
let baseUrl = normalizeBaseUrl(process.env.HUDDLE_URL ?? 'http://localhost:3000');
|
|
7
8
|
class ApiError extends Error {
|
|
8
9
|
status;
|
|
@@ -17,11 +18,19 @@ function setBaseUrl(url) {
|
|
|
17
18
|
baseUrl = normalizeBaseUrl(url);
|
|
18
19
|
}
|
|
19
20
|
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}`;
|
|
20
29
|
let res;
|
|
21
30
|
try {
|
|
22
31
|
res = await fetch(`${baseUrl}${path}`, {
|
|
23
32
|
method,
|
|
24
|
-
headers
|
|
33
|
+
headers,
|
|
25
34
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
26
35
|
});
|
|
27
36
|
}
|
|
@@ -32,6 +41,10 @@ async function apiCall(method, path, body) {
|
|
|
32
41
|
const raw = await res.text();
|
|
33
42
|
const payload = parsePayload(raw);
|
|
34
43
|
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
|
+
}
|
|
35
48
|
const msg = errorMessage(payload) ?? res.statusText;
|
|
36
49
|
throw new ApiError(`${method} ${path} -> ${res.status}: ${msg}`, res.status);
|
|
37
50
|
}
|
package/dist/config.js
CHANGED
|
@@ -6,6 +6,7 @@ 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;
|
|
9
10
|
exports.activeExperiment = activeExperiment;
|
|
10
11
|
exports.imageTag = imageTag;
|
|
11
12
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -28,6 +29,14 @@ function writeConfig(config) {
|
|
|
28
29
|
fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
29
30
|
fs_1.default.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
|
|
30
31
|
}
|
|
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
|
+
}
|
|
31
40
|
/** Active experiment number, or undefined when running on stable. */
|
|
32
41
|
function activeExperiment() {
|
|
33
42
|
const cfg = readConfig();
|
package/dist/init.js
CHANGED
|
@@ -5,9 +5,11 @@ 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"));
|
|
8
9
|
const utils_1 = require("./utils");
|
|
9
10
|
const runtime_1 = require("./runtime");
|
|
10
11
|
const images_1 = require("./images");
|
|
12
|
+
const config_1 = require("./config");
|
|
11
13
|
const fs_1 = __importDefault(require("fs"));
|
|
12
14
|
const CONTAINER = 'huddle';
|
|
13
15
|
const VOLUME = 'huddle-data';
|
|
@@ -112,19 +114,29 @@ async function runInit(opts, images) {
|
|
|
112
114
|
// `--security-opt label=disable` on every devcontainer so it can reach the
|
|
113
115
|
// SELinux-labeled proxy socket.
|
|
114
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
|
+
}
|
|
115
128
|
// The container is created on the engine's default network first (with -p),
|
|
116
|
-
// then joins devcontainer-net (--internal) afterwards
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
// devcontainer-net were primary the operator's browser would appear to come
|
|
122
|
-
// from the devcontainer subnet and get blocked by the source-IP gate (api.ts).
|
|
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.
|
|
123
134
|
run(`${rt} run -d` +
|
|
124
135
|
` --name ${CONTAINER}` +
|
|
125
136
|
` --network ${runtime.defaultNetwork}` +
|
|
126
137
|
securityOptFlags +
|
|
127
138
|
` -e HUDDLE_RUNTIME=${runtime.name}` +
|
|
139
|
+
` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
|
|
128
140
|
` -p ${HOST_PORT}:3000` +
|
|
129
141
|
` -v ${VOLUME}:/data` +
|
|
130
142
|
` -v ${runtime.socketPath}:/var/run/docker.sock` +
|
|
@@ -138,4 +150,14 @@ async function runInit(opts, images) {
|
|
|
138
150
|
runSilent(`${rt} network connect ${INTERNAL_NET} ${CONTAINER}`);
|
|
139
151
|
console.log();
|
|
140
152
|
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.'));
|
|
141
163
|
}
|
package/package.json
CHANGED