@infosupport/huddle-cli 0.0.0-experiment-66.29.1 → 0.0.0-experiment-66.30.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 +38 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/dist/firewall.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.runFirewallList = runFirewallList;
|
|
7
7
|
exports.runFirewallAdd = runFirewallAdd;
|
|
8
|
+
exports.runFirewallDelete = runFirewallDelete;
|
|
8
9
|
exports.runFirewallExport = runFirewallExport;
|
|
9
10
|
exports.runFirewallImport = runFirewallImport;
|
|
10
11
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -84,6 +85,43 @@ async function runFirewallAdd(opts) {
|
|
|
84
85
|
const verb = status === 'deny' ? (0, utils_1.red)('Denied') : (0, utils_1.green)('Allowed');
|
|
85
86
|
console.log(`${verb} ${(0, utils_1.bold)((0, utils_1.cyan)(target))} ${(0, utils_1.dim)(`(${scope})`)}`);
|
|
86
87
|
}
|
|
88
|
+
// Deletes a firewall rule. Accepts the numeric id shown by `firewall list`
|
|
89
|
+
// (deleted directly) or a domain, which is resolved to a single rule id via a
|
|
90
|
+
// lookup. `--container` narrows a domain match to one scope; an ambiguous
|
|
91
|
+
// domain (multiple matching rules) is refused with the candidate ids so the
|
|
92
|
+
// caller can re-run with an exact id.
|
|
93
|
+
async function runFirewallDelete(opts) {
|
|
94
|
+
const target = (opts.target ?? '').trim();
|
|
95
|
+
if (!target) {
|
|
96
|
+
throw new Error('Usage: huddle firewall delete <id-or-domain> [--container <id>]');
|
|
97
|
+
}
|
|
98
|
+
let id;
|
|
99
|
+
if (/^\d+$/.test(target)) {
|
|
100
|
+
id = Number(target);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Domain form: list all rules (optionally scoped) and resolve to one id.
|
|
104
|
+
const qs = new URLSearchParams();
|
|
105
|
+
if (opts.container)
|
|
106
|
+
qs.set('container', opts.container);
|
|
107
|
+
const query = qs.toString();
|
|
108
|
+
const rules = await (0, api_1.get)(`/api/rules${query ? `?${query}` : ''}`);
|
|
109
|
+
const matches = rules.filter((r) => r.domain === target);
|
|
110
|
+
if (matches.length === 0) {
|
|
111
|
+
const scope = opts.container ? ` for container ${opts.container}` : '';
|
|
112
|
+
throw new Error(`No firewall rule found for "${target}"${scope}.`);
|
|
113
|
+
}
|
|
114
|
+
if (matches.length > 1) {
|
|
115
|
+
const ids = matches
|
|
116
|
+
.map((r) => ` ${r.id} ${r.status.padEnd(9)} ${formatTarget(r)} ${r.container_id ?? '(global)'}`)
|
|
117
|
+
.join('\n');
|
|
118
|
+
throw new Error(`"${target}" matches ${matches.length} rules — delete by id (or narrow with --container):\n${ids}`);
|
|
119
|
+
}
|
|
120
|
+
id = matches[0].id;
|
|
121
|
+
}
|
|
122
|
+
await (0, api_1.del)(`/api/rules/${id}`);
|
|
123
|
+
console.log(`${(0, utils_1.green)('Deleted')} rule ${(0, utils_1.bold)((0, utils_1.cyan)(String(id)))}`);
|
|
124
|
+
}
|
|
87
125
|
function printRulesTable(rules) {
|
|
88
126
|
const headers = ['ID', 'Status', 'Domain/path', 'Container', 'Requests', 'Seen'];
|
|
89
127
|
const rows = rules.map((r) => [
|
package/dist/index.js
CHANGED
|
@@ -100,6 +100,8 @@ Usage:
|
|
|
100
100
|
huddle fw list [options] Alias for firewall list
|
|
101
101
|
huddle firewall add <domain> Add a custom firewall rule (wildcards
|
|
102
102
|
supported: *.example.com and /path/*)
|
|
103
|
+
huddle firewall delete <id> Delete a firewall rule by id (or domain;
|
|
104
|
+
narrow with --container)
|
|
103
105
|
huddle firewall export [options] Export firewall rules as JSON
|
|
104
106
|
huddle firewall import <file> Import firewall rules from a JSON file
|
|
105
107
|
huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
|
|
@@ -244,6 +246,12 @@ async function main() {
|
|
|
244
246
|
container: flagString(flags, 'container'),
|
|
245
247
|
});
|
|
246
248
|
}
|
|
249
|
+
else if (subCmd === 'delete' || subCmd === 'remove' || subCmd === 'rm') {
|
|
250
|
+
await (0, firewall_1.runFirewallDelete)({
|
|
251
|
+
target: positional[2],
|
|
252
|
+
container: flagString(flags, 'container'),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
247
255
|
else if (subCmd === 'export') {
|
|
248
256
|
await (0, firewall_1.runFirewallExport)({
|
|
249
257
|
container: flagString(flags, 'container'),
|
package/package.json
CHANGED