feat: rebuild xiteng.site homelab platform
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import {readFileSync} from "node:fs";
|
||||
import {cloudflareRuleFromSpec, syncCloudflareRule} from "./controller.mjs";
|
||||
|
||||
const command = process.argv[2] || "plan";
|
||||
const specPath = process.env.CLOUDFLARE_SPEC_PATH || "/state/cloudflare-cache-rules.json";
|
||||
const tokenPath = process.env.CLOUDFLARE_API_TOKEN_FILE || "/run/secrets/cloudflare_cache_api_token";
|
||||
const zoneId = process.env.CLOUDFLARE_ZONE_ID || "";
|
||||
const spec = JSON.parse(readFileSync(specPath, "utf8"));
|
||||
|
||||
if (command === "plan") {
|
||||
console.log(JSON.stringify(cloudflareRuleFromSpec(spec), null, 2));
|
||||
} else if (["check", "apply"].includes(command)) {
|
||||
const token = readFileSync(tokenPath, "utf8").trim();
|
||||
const result = await syncCloudflareRule(spec, {zoneId, token, dryRun: command === "check"});
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} else {
|
||||
console.error("Usage: node cloudflare.mjs [plan|check|apply]");
|
||||
process.exit(2);
|
||||
}
|
||||
Reference in New Issue
Block a user