@infosupport/huddle-cli 0.0.0-experiment-97.41.1 → 0.0.0-experiment-98.43.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/config.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CONFIG_DIR = void 0;
6
7
  exports.configPath = configPath;
7
8
  exports.readConfig = readConfig;
8
9
  exports.writeConfig = writeConfig;
@@ -12,8 +13,8 @@ exports.imageTag = imageTag;
12
13
  const fs_1 = __importDefault(require("fs"));
13
14
  const os_1 = __importDefault(require("os"));
14
15
  const path_1 = __importDefault(require("path"));
15
- const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.huddle');
16
- const CONFIG_PATH = path_1.default.join(CONFIG_DIR, 'config.json');
16
+ exports.CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.huddle');
17
+ const CONFIG_PATH = path_1.default.join(exports.CONFIG_DIR, 'config.json');
17
18
  function configPath() {
18
19
  return CONFIG_PATH;
19
20
  }
@@ -26,7 +27,7 @@ function readConfig() {
26
27
  }
27
28
  }
28
29
  function writeConfig(config) {
29
- fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
30
+ fs_1.default.mkdirSync(exports.CONFIG_DIR, { recursive: true });
30
31
  fs_1.default.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
31
32
  }
32
33
  /** Operator-token voor API-auth: env wint, anders uit de config. */
package/dist/firewall.js CHANGED
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.runFirewallList = runFirewallList;
4
7
  exports.runFirewallAdd = runFirewallAdd;
5
8
  exports.runFirewallDelete = runFirewallDelete;
9
+ exports.runFirewallExport = runFirewallExport;
10
+ exports.runFirewallImport = runFirewallImport;
11
+ exports.runFirewallGroup = runFirewallGroup;
12
+ exports.runFirewallFolder = runFirewallFolder;
13
+ const fs_1 = __importDefault(require("fs"));
6
14
  const api_1 = require("./api");
15
+ const config_1 = require("./config");
7
16
  const utils_1 = require("./utils");
8
17
  async function runFirewallList(opts) {
9
18
  const qs = new URLSearchParams({ status: opts.status ?? 'requested' });
@@ -56,9 +65,9 @@ async function resolveRule(rule, status, scope) {
56
65
  }
57
66
  // Creates a custom firewall rule. Supports wildcards: `*.` in the domain
58
67
  // (e.g. `*.pkgs.dev.azure.com`) and `*` in the path pattern (e.g.
59
- // `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a rotating
60
- // GUID). Defaults to 'allow'; with --deny a block rule. Without --container the
61
- // rule is global.
68
+ // `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a changing
69
+ // GUID). Defaults to 'allow'; --deny creates a block rule. Without --container
70
+ // the rule is global.
62
71
  async function runFirewallAdd(opts) {
63
72
  const domain = (opts.domain ?? '').trim();
64
73
  if (!domain) {
@@ -135,3 +144,146 @@ function printRulesTable(rules) {
135
144
  function formatTarget(rule) {
136
145
  return rule.path_pattern ? `${rule.domain}${rule.path_pattern}` : rule.domain;
137
146
  }
147
+ async function runFirewallExport(opts) {
148
+ const qs = new URLSearchParams();
149
+ if (opts.container)
150
+ qs.set('container', opts.container);
151
+ const suffix = qs.toString() ? `?${qs}` : '';
152
+ const doc = await (0, api_1.get)(`/api/rules/export${suffix}`);
153
+ const json = JSON.stringify(doc, null, 2);
154
+ if (opts.out) {
155
+ fs_1.default.writeFileSync(opts.out, `${json}\n`);
156
+ // Progress to stderr so a pure `--out` run leaks nothing to stdout.
157
+ console.error((0, utils_1.green)(`[OK] Exported ${doc.rules.length} rule(s) to ${opts.out}`));
158
+ }
159
+ else {
160
+ console.log(json);
161
+ }
162
+ }
163
+ async function runFirewallImport(opts) {
164
+ let raw;
165
+ try {
166
+ raw = fs_1.default.readFileSync(opts.file, 'utf8');
167
+ }
168
+ catch {
169
+ throw new Error(`Cannot read ${opts.file}`);
170
+ }
171
+ let doc;
172
+ try {
173
+ doc = JSON.parse(raw);
174
+ }
175
+ catch {
176
+ throw new Error(`${opts.file} is not valid JSON`);
177
+ }
178
+ const mode = opts.replace ? 'replace' : 'merge';
179
+ const qs = new URLSearchParams();
180
+ if (opts.container)
181
+ qs.set('container', opts.container);
182
+ const suffix = qs.toString() ? `?${qs}` : '';
183
+ const res = await (0, api_1.post)(`/api/rules/import${suffix}`, { mode, rules: doc.rules });
184
+ console.error((0, utils_1.green)(`[OK] Imported (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
185
+ }
186
+ async function resolveGroupByName(name) {
187
+ const groups = await (0, api_1.get)('/api/groups');
188
+ const match = groups.filter((g) => g.name.toLowerCase() === name.toLowerCase());
189
+ if (match.length === 0)
190
+ throw new Error(`No group named "${name}". Run \`huddle firewall group list\`.`);
191
+ return match[0];
192
+ }
193
+ async function runFirewallGroup(opts) {
194
+ const action = opts.action ?? 'list';
195
+ if (action === 'list') {
196
+ const groups = await (0, api_1.get)('/api/groups');
197
+ if (groups.length === 0) {
198
+ console.log((0, utils_1.dim)('No firewall groups yet.'));
199
+ return;
200
+ }
201
+ const headers = ['ID', 'Name', 'Rules', 'Shared', 'Source'];
202
+ const rows = groups.map((g) => [String(g.id), g.name, String(g.rule_count), g.shared ? 'yes' : 'no', g.source]);
203
+ (0, utils_1.printTable)(headers, rows);
204
+ return;
205
+ }
206
+ if (action === 'export') {
207
+ const name = (opts.arg ?? '').trim();
208
+ if (!name)
209
+ throw new Error('Usage: huddle firewall group export <name> [--out <file>]');
210
+ const g = await resolveGroupByName(name);
211
+ const env = await (0, api_1.get)(`/api/groups/${g.id}/export`);
212
+ const json = JSON.stringify(env, null, 2);
213
+ if (opts.out) {
214
+ fs_1.default.writeFileSync(opts.out, `${json}\n`);
215
+ console.error((0, utils_1.green)(`[OK] Exported group "${g.name}" to ${opts.out}`));
216
+ }
217
+ else {
218
+ console.log(json);
219
+ }
220
+ return;
221
+ }
222
+ if (action === 'import') {
223
+ const file = (opts.arg ?? '').trim();
224
+ if (!file)
225
+ throw new Error('Usage: huddle firewall group import <file> [--replace]');
226
+ let raw;
227
+ try {
228
+ raw = fs_1.default.readFileSync(file, 'utf8');
229
+ }
230
+ catch {
231
+ throw new Error(`Cannot read ${file}`);
232
+ }
233
+ let envelope;
234
+ try {
235
+ envelope = JSON.parse(raw);
236
+ }
237
+ catch {
238
+ throw new Error(`${file} is not valid JSON`);
239
+ }
240
+ const mode = opts.replace ? 'replace' : 'merge';
241
+ const res = await (0, api_1.post)('/api/groups/import', { mode, envelope });
242
+ console.error((0, utils_1.green)(`[OK] Imported group "${res.group.name}" (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
243
+ return;
244
+ }
245
+ if (action === 'apply') {
246
+ const name = (opts.arg ?? '').trim();
247
+ if (!name)
248
+ throw new Error('Usage: huddle firewall group apply <name> [--container <id>]');
249
+ const g = await resolveGroupByName(name);
250
+ const container = opts.container ?? null;
251
+ const res = await (0, api_1.post)(`/api/groups/${g.id}/apply`, { container });
252
+ const scope = container ? `container ${container}` : 'global';
253
+ console.log((0, utils_1.green)(`[OK] Applied "${g.name}" to ${scope}: ${res.applied} added, ${res.updated} updated`));
254
+ return;
255
+ }
256
+ throw new Error(`Unknown group action: ${action}. Use list | export | import | apply.`);
257
+ }
258
+ async function runFirewallFolder(opts) {
259
+ const action = opts.action ?? 'show';
260
+ if (action === 'show') {
261
+ // The CLI config is the source of truth for the path.
262
+ const folder = (0, config_1.readConfig)().firewallRulesFolder;
263
+ console.log(folder ? folder : (0, utils_1.dim)('(no firewall rules folder configured)'));
264
+ return;
265
+ }
266
+ if (action === 'set') {
267
+ const path = (opts.path ?? '').trim();
268
+ if (!path)
269
+ throw new Error('Usage: huddle firewall folder set <path>');
270
+ // Config-only: the gateway reads the folder at the fixed mount point the CLI
271
+ // binds it to; there is no DB setting. Persist here and mount on restart.
272
+ (0, config_1.writeConfig)({ ...(0, config_1.readConfig)(), firewallRulesFolder: path });
273
+ console.log((0, utils_1.green)(`[OK] Firewall rules folder set to ${(0, utils_1.cyan)(path)}`));
274
+ console.log((0, utils_1.dim)(' Run `huddle restart` to mount it into the gateway; it is then read on start & reload.'));
275
+ return;
276
+ }
277
+ if (action === 'reload') {
278
+ const res = await (0, api_1.post)('/api/firewall-rules-folder/reload', {});
279
+ if (!res.mounted) {
280
+ console.log((0, utils_1.dim)('No firewall rules folder mounted. Set one with `huddle firewall folder set <path>` and run `huddle restart`.'));
281
+ return;
282
+ }
283
+ console.log((0, utils_1.green)(`[OK] Reloaded: ${res.groups} group(s), ${res.imported} rule(s), ${res.errors.length} error(s)`));
284
+ for (const e of res.errors)
285
+ console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
286
+ return;
287
+ }
288
+ throw new Error(`Unknown folder action: ${action}. Use show | set | reload.`);
289
+ }
package/dist/index.js CHANGED
@@ -15,9 +15,9 @@ const images_1 = require("./images");
15
15
  const self_update_1 = require("./self-update");
16
16
  const utils_1 = require("./utils");
17
17
  const experiment_1 = require("./experiment");
18
- const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output']);
19
- const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force']);
20
- const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'experiment', 'migrate', 'help', 'version']);
18
+ const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output', 'out']);
19
+ const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', 'replace']);
20
+ const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'restart', 'experiment', 'migrate', 'help', 'version']);
21
21
  function parseArgs(argv) {
22
22
  const positional = [];
23
23
  const flags = {};
@@ -94,6 +94,8 @@ Usage:
94
94
  huddle start [options] [folder] Explicitly start a devcontainer
95
95
  huddle init [options] Pull the Huddle + devcontainer base images and
96
96
  start them via Docker or Podman
97
+ huddle restart Recreate the gateway (e.g. to mount a changed
98
+ team firewall-rules folder)
97
99
  huddle migrate [folder] Wire an existing docker-compose devcontainer
98
100
  behind Huddle by generating an override file
99
101
  huddle firewall list [options] Show firewall requests
@@ -102,6 +104,14 @@ Usage:
102
104
  supported: *.example.com and /path/*)
103
105
  huddle firewall delete <id> Delete a firewall rule by id (or domain;
104
106
  narrow with --container)
107
+ huddle firewall export [options] Export firewall rules as JSON
108
+ huddle firewall import <file> Import firewall rules from a JSON file
109
+ huddle firewall group list List firewall groups (#69)
110
+ huddle firewall group export <name> Export a group as JSON (--out <file>)
111
+ huddle firewall group import <file> Import a group (--replace to mirror)
112
+ huddle firewall group apply <name> Apply a group (--container <id> or global)
113
+ huddle firewall folder set <path> Set the team-managed rules folder
114
+ huddle firewall folder reload Re-read the team-managed rules folder
105
115
  huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
106
116
  and run init
107
117
  huddle experiment reset Back to the stable release
@@ -132,6 +142,8 @@ Migrate options:
132
142
  Firewall options:
133
143
  -i, --interactive Interactively approve/deny (list)
134
144
  --container <name> Filter by (list) / scope to (add) a container
145
+ (or __global__). On import: remap all rules
146
+ to this scope
135
147
  --status <requested|allow|deny> Filter by status (default: requested)
136
148
 
137
149
  Firewall add options:
@@ -140,6 +152,11 @@ Firewall add options:
140
152
  (e.g. /_packaging/*/nuget/v3/*)
141
153
  --deny Create a block rule (default: allow)
142
154
 
155
+ Firewall export/import options:
156
+ --out <file> Write export to a file (default: stdout)
157
+ --replace Import in replace mode: wipe the target
158
+ scope first (default: merge/upsert)
159
+
143
160
  Global options:
144
161
  --url <url> Huddle URL (default: http://localhost:3000)
145
162
  Or via the HUDDLE_URL env var
@@ -202,6 +219,15 @@ async function main() {
202
219
  await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
203
220
  return;
204
221
  }
222
+ if (cmd === 'restart') {
223
+ // Stop + recreate the gateway (runInit does `rm -f` first) so changed team
224
+ // folders get mounted. The portal writes the paths straight into the mounted
225
+ // ~/.huddle/config.json, so runInit already reads the latest values here.
226
+ const initOpts = { runtime: flagString(flags, 'runtime') };
227
+ (0, experiment_1.ensureCliForChannel)(process.argv.slice(2));
228
+ await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
229
+ return;
230
+ }
205
231
  if (cmd === 'experiment') {
206
232
  const subCmd = sub ?? 'status';
207
233
  if (subCmd === 'use') {
@@ -243,6 +269,36 @@ async function main() {
243
269
  container: flagString(flags, 'container'),
244
270
  });
245
271
  }
272
+ else if (subCmd === 'export') {
273
+ await (0, firewall_1.runFirewallExport)({
274
+ container: flagString(flags, 'container'),
275
+ out: flagString(flags, 'out'),
276
+ });
277
+ }
278
+ else if (subCmd === 'import') {
279
+ const file = positional[2];
280
+ if (!file) {
281
+ console.error('Usage: huddle firewall import <file> [--replace] [--container <id>]');
282
+ process.exit(1);
283
+ }
284
+ await (0, firewall_1.runFirewallImport)({
285
+ file,
286
+ replace: flagBool(flags, 'replace'),
287
+ container: flagString(flags, 'container'),
288
+ });
289
+ }
290
+ else if (subCmd === 'group' || subCmd === 'groups') {
291
+ await (0, firewall_1.runFirewallGroup)({
292
+ action: positional[2],
293
+ arg: positional[3],
294
+ out: flagString(flags, 'out'),
295
+ replace: flagBool(flags, 'replace'),
296
+ container: flagString(flags, 'container'),
297
+ });
298
+ }
299
+ else if (subCmd === 'folder') {
300
+ await (0, firewall_1.runFirewallFolder)({ action: positional[2], path: positional[3] });
301
+ }
246
302
  else {
247
303
  console.error(`Unknown firewall subcommand: ${subCmd}`);
248
304
  process.exit(1);
package/dist/init.js CHANGED
@@ -145,6 +145,19 @@ async function runInit(opts, images) {
145
145
  // network (moby/moby#36174). Which source IP the gateway sees for forwarded
146
146
  // traffic no longer matters — the control plane authenticates with the
147
147
  // operator token instead of source-IP filtering.
148
+ // Team-managed folders (#69). Bind the CLI config dir (~/.huddle) read-write so
149
+ // the gateway/portal read and write the folder paths there (config.json is the
150
+ // single source of truth), then bind each configured team folder to a FIXED
151
+ // path so the gateway reads it without knowing the host path. Read-only.
152
+ const fwFolder = cfg.firewallRulesFolder?.trim();
153
+ const extFolder = cfg.extensionsFolder?.trim();
154
+ const homeMountFlag = ` -v "${config_1.CONFIG_DIR}:/huddle-home:rw" -e HUDDLE_HOME_DIR=/huddle-home`;
155
+ const fwMountFlag = fwFolder ? ` -v "${fwFolder}:/firewall-rules:ro"` : '';
156
+ const extMountFlag = extFolder ? ` -v "${extFolder}:/extensions:ro"` : '';
157
+ if (fwFolder)
158
+ console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
159
+ if (extFolder)
160
+ console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
148
161
  run(`${rt} run -d` +
149
162
  ` --name ${CONTAINER}` +
150
163
  ` --network ${runtime.defaultNetwork}` +
@@ -155,6 +168,9 @@ async function runInit(opts, images) {
155
168
  ` -v ${VOLUME}:/data` +
156
169
  ` -v "${runtime.socketPath}:/var/run/docker.sock"` +
157
170
  ` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
171
+ homeMountFlag +
172
+ fwMountFlag +
173
+ extMountFlag +
158
174
  (0, images_1.gatewayEnvFlags)(images) +
159
175
  ` ${IMAGE}`);
160
176
  // Attaching devcontainer-net after the container has started pollutes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-97.41.1",
3
+ "version": "0.0.0-experiment-98.43.1",
4
4
  "description": "Huddle CLI — start devcontainers and manage firewall rules",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Info Support B.V.",