@infosupport/huddle-cli 0.0.0-experiment-66.30.1 → 0.0.0-experiment-66.31.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/firewall.js +102 -0
- package/dist/index.js +18 -0
- package/package.json +1 -1
package/dist/firewall.js
CHANGED
|
@@ -8,6 +8,8 @@ exports.runFirewallAdd = runFirewallAdd;
|
|
|
8
8
|
exports.runFirewallDelete = runFirewallDelete;
|
|
9
9
|
exports.runFirewallExport = runFirewallExport;
|
|
10
10
|
exports.runFirewallImport = runFirewallImport;
|
|
11
|
+
exports.runFirewallGroup = runFirewallGroup;
|
|
12
|
+
exports.runFirewallFolder = runFirewallFolder;
|
|
11
13
|
const fs_1 = __importDefault(require("fs"));
|
|
12
14
|
const api_1 = require("./api");
|
|
13
15
|
const utils_1 = require("./utils");
|
|
@@ -176,3 +178,103 @@ async function runFirewallImport(opts) {
|
|
|
176
178
|
const res = await (0, api_1.post)(`/api/rules/import${suffix}`, { mode, rules: doc.rules });
|
|
177
179
|
console.error((0, utils_1.green)(`[OK] Imported (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
|
|
178
180
|
}
|
|
181
|
+
async function resolveGroupByName(name) {
|
|
182
|
+
const groups = await (0, api_1.get)('/api/groups');
|
|
183
|
+
const match = groups.filter((g) => g.name.toLowerCase() === name.toLowerCase());
|
|
184
|
+
if (match.length === 0)
|
|
185
|
+
throw new Error(`No group named "${name}". Run \`huddle firewall group list\`.`);
|
|
186
|
+
return match[0];
|
|
187
|
+
}
|
|
188
|
+
async function runFirewallGroup(opts) {
|
|
189
|
+
const action = opts.action ?? 'list';
|
|
190
|
+
if (action === 'list') {
|
|
191
|
+
const groups = await (0, api_1.get)('/api/groups');
|
|
192
|
+
if (groups.length === 0) {
|
|
193
|
+
console.log((0, utils_1.dim)('No firewall groups yet.'));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const headers = ['ID', 'Name', 'Rules', 'Shared', 'Source'];
|
|
197
|
+
const rows = groups.map((g) => [String(g.id), g.name, String(g.rule_count), g.shared ? 'yes' : 'no', g.source]);
|
|
198
|
+
(0, utils_1.printTable)(headers, rows);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (action === 'export') {
|
|
202
|
+
const name = (opts.arg ?? '').trim();
|
|
203
|
+
if (!name)
|
|
204
|
+
throw new Error('Usage: huddle firewall group export <name> [--out <file>]');
|
|
205
|
+
const g = await resolveGroupByName(name);
|
|
206
|
+
const env = await (0, api_1.get)(`/api/groups/${g.id}/export`);
|
|
207
|
+
const json = JSON.stringify(env, null, 2);
|
|
208
|
+
if (opts.out) {
|
|
209
|
+
fs_1.default.writeFileSync(opts.out, `${json}\n`);
|
|
210
|
+
console.error((0, utils_1.green)(`[OK] Exported group "${g.name}" to ${opts.out}`));
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
console.log(json);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (action === 'import') {
|
|
218
|
+
const file = (opts.arg ?? '').trim();
|
|
219
|
+
if (!file)
|
|
220
|
+
throw new Error('Usage: huddle firewall group import <file> [--replace]');
|
|
221
|
+
let raw;
|
|
222
|
+
try {
|
|
223
|
+
raw = fs_1.default.readFileSync(file, 'utf8');
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
throw new Error(`Cannot read ${file}`);
|
|
227
|
+
}
|
|
228
|
+
let envelope;
|
|
229
|
+
try {
|
|
230
|
+
envelope = JSON.parse(raw);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
throw new Error(`${file} is not valid JSON`);
|
|
234
|
+
}
|
|
235
|
+
const mode = opts.replace ? 'replace' : 'merge';
|
|
236
|
+
const res = await (0, api_1.post)('/api/groups/import', { mode, envelope });
|
|
237
|
+
console.error((0, utils_1.green)(`[OK] Imported group "${res.group.name}" (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (action === 'apply') {
|
|
241
|
+
const name = (opts.arg ?? '').trim();
|
|
242
|
+
if (!name)
|
|
243
|
+
throw new Error('Usage: huddle firewall group apply <name> [--container <id>]');
|
|
244
|
+
const g = await resolveGroupByName(name);
|
|
245
|
+
const container = opts.container ?? null;
|
|
246
|
+
const res = await (0, api_1.post)(`/api/groups/${g.id}/apply`, { container });
|
|
247
|
+
const scope = container ? `container ${container}` : 'global';
|
|
248
|
+
console.log((0, utils_1.green)(`[OK] Applied "${g.name}" to ${scope}: ${res.applied} added, ${res.updated} updated`));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
throw new Error(`Unknown group action: ${action}. Use list | export | import | apply.`);
|
|
252
|
+
}
|
|
253
|
+
async function runFirewallFolder(opts) {
|
|
254
|
+
const action = opts.action ?? 'show';
|
|
255
|
+
if (action === 'show') {
|
|
256
|
+
const s = await (0, api_1.get)('/api/settings');
|
|
257
|
+
console.log(s.firewallRulesFolder ? s.firewallRulesFolder : (0, utils_1.dim)('(no firewall rules folder configured)'));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (action === 'set') {
|
|
261
|
+
const path = (opts.path ?? '').trim();
|
|
262
|
+
if (!path)
|
|
263
|
+
throw new Error('Usage: huddle firewall folder set <path>');
|
|
264
|
+
await (0, api_1.post)('/api/settings', { firewallRulesFolder: path });
|
|
265
|
+
console.log((0, utils_1.green)(`[OK] Firewall rules folder set to ${(0, utils_1.cyan)(path)} (re-read now and on startup)`));
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (action === 'reload') {
|
|
269
|
+
const res = await (0, api_1.post)('/api/firewall-rules-folder/reload', {});
|
|
270
|
+
if (!res.folder) {
|
|
271
|
+
console.log((0, utils_1.dim)('No firewall rules folder configured. Use `huddle firewall folder set <path>`.'));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
console.log((0, utils_1.green)(`[OK] Reloaded ${res.folder}: ${res.groups} group(s), ${res.imported} rule(s), ${res.errors.length} error(s)`));
|
|
275
|
+
for (const e of res.errors)
|
|
276
|
+
console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
throw new Error(`Unknown folder action: ${action}. Use show | set | reload.`);
|
|
280
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -104,6 +104,12 @@ Usage:
|
|
|
104
104
|
narrow with --container)
|
|
105
105
|
huddle firewall export [options] Export firewall rules as JSON
|
|
106
106
|
huddle firewall import <file> Import firewall rules from a JSON file
|
|
107
|
+
huddle firewall group list List firewall groups (#69)
|
|
108
|
+
huddle firewall group export <name> Export a group as JSON (--out <file>)
|
|
109
|
+
huddle firewall group import <file> Import a group (--replace to mirror)
|
|
110
|
+
huddle firewall group apply <name> Apply a group (--container <id> or global)
|
|
111
|
+
huddle firewall folder set <path> Set the team-managed rules folder
|
|
112
|
+
huddle firewall folder reload Re-read the team-managed rules folder
|
|
107
113
|
huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
|
|
108
114
|
and run init
|
|
109
115
|
huddle experiment reset Back to the stable release
|
|
@@ -270,6 +276,18 @@ async function main() {
|
|
|
270
276
|
container: flagString(flags, 'container'),
|
|
271
277
|
});
|
|
272
278
|
}
|
|
279
|
+
else if (subCmd === 'group' || subCmd === 'groups') {
|
|
280
|
+
await (0, firewall_1.runFirewallGroup)({
|
|
281
|
+
action: positional[2],
|
|
282
|
+
arg: positional[3],
|
|
283
|
+
out: flagString(flags, 'out'),
|
|
284
|
+
replace: flagBool(flags, 'replace'),
|
|
285
|
+
container: flagString(flags, 'container'),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
else if (subCmd === 'folder') {
|
|
289
|
+
await (0, firewall_1.runFirewallFolder)({ action: positional[2], path: positional[3] });
|
|
290
|
+
}
|
|
273
291
|
else {
|
|
274
292
|
console.error(`Unknown firewall subcommand: ${subCmd}`);
|
|
275
293
|
process.exit(1);
|
package/package.json
CHANGED