Skip to content

Commit aad7fb0

Browse files
committed
Add convert-rules CLI and move rules module to lib/
Add setup/convert-rules.mjs so Makefile can accept wildcard syntax instead of requiring hand-written regex. Move rules.mjs and its tests into setup/lib/ for better organization.
1 parent 34af343 commit aad7fb0

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ run_restrict_mode: ## Start in restrict mode
2929
@echo "Starting buildcage in RESTRICT mode..."
3030
@COMPOSE_FILE=$(COMPOSE_FILE) \
3131
PROXY_MODE=restrict \
32-
ALLOWED_HTTP_RULES="$${ALLOWED_HTTP_RULES:-}" \
33-
ALLOWED_HTTPS_RULES="$${ALLOWED_HTTPS_RULES:-^github\.com:443$$,^registry\.npmjs\.org:443$$,^api\.github\.com:443$$,^objects\.githubusercontent\.com:443$$,^httpbin\.org:443$$,^deb\.debian\.org:80$$,^.*\.githubusercontent\.com:443$$}" \
32+
ALLOWED_HTTP_RULES="$$(node setup/convert-rules.mjs "$${ALLOWED_HTTP_RULES:-}")" \
33+
ALLOWED_HTTPS_RULES="$$(node setup/convert-rules.mjs "$${ALLOWED_HTTPS_RULES:-github.com:443 registry.npmjs.org:443 api.github.com:443 objects.githubusercontent.com:443 httpbin.org:443 deb.debian.org:80 *.githubusercontent.com:443}")" \
3434
docker compose up -d --wait --build
3535
@docker buildx rm buildcage 2>/dev/null || true
3636
@echo "Creating buildx builder..."
@@ -68,4 +68,4 @@ test_audit_mode: ## Run audit mode tests
6868

6969
.PHONY: test_unit
7070
test_unit: ## Run unit tests
71-
@node --test setup/rules.test.mjs
71+
@node --test setup/lib/rules.test.mjs

docs/development.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ Fields: `[timestamp] buildcage [status] "domain:port" reason`
9494
│ ├── compose.yml # Compose config for GitHub Actions (with image tag)
9595
│ ├── main.mjs # Setup entrypoint (rule generation, compose up)
9696
│ ├── post.mjs # Post-action cleanup
97-
│ ├── rules.mjs # Rule parser (wildcards, regex, ports)
98-
│ └── rules.test.mjs # Unit tests for rules.mjs
97+
│ ├── convert-rules.mjs # CLI: wildcard rules → regex (used by Makefile)
98+
│ └── lib/
99+
│ ├── rules.mjs # Rule parser (wildcards, regex, ports)
100+
│ └── rules.test.mjs # Unit tests for rules.mjs
99101
├── report/
100102
│ ├── action.yml # GitHub Action: dash14/buildcage/report@v1
101103
│ └── main.mjs # Log analysis and Job Summary output

setup/convert-rules.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
/**
3+
* CLI wrapper for buildRules.
4+
* Converts wildcard/regex rules to regex strings (space-separated).
5+
*
6+
* Usage: node setup/convert-rules.mjs "*.example.com:443 other.com:80"
7+
*/
8+
import { buildRules } from "./lib/rules.mjs";
9+
10+
const input = process.argv[2] || "";
11+
console.log(buildRules(input).join(" "));
File renamed without changes.

setup/main.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execFileSync } from "node:child_process";
22
import { appendFileSync } from "node:fs";
33
import { join, dirname } from "node:path";
44
import { fileURLToPath } from "node:url";
5-
import { buildRules, buildLegacyRules } from "./rules.mjs";
5+
import { buildRules, buildLegacyRules } from "./lib/rules.mjs";
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
88
const composeFile = join(__dirname, "compose.yml");

0 commit comments

Comments
 (0)