Secrets migrate: split plan/apply/backup modules

This commit is contained in:
joshavant
2026-02-24 13:42:41 -06:00
committed by Peter Steinberger
parent 4807e40cbd
commit 363334253b
7 changed files with 921 additions and 870 deletions

View File

@@ -1,3 +1,6 @@
import fs from "node:fs";
import path from "node:path";
export function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
@@ -12,3 +15,13 @@ export function normalizePositiveInt(value: unknown, fallback: number): number {
}
return Math.max(1, Math.floor(fallback));
}
export function ensureDirForFile(filePath: string): void {
fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
}
export function writeJsonFileSecure(pathname: string, value: unknown): void {
ensureDirForFile(pathname);
fs.writeFileSync(pathname, `${JSON.stringify(value, null, 2)}\n`, "utf8");
fs.chmodSync(pathname, 0o600);
}