mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 04:24:31 +00:00
Secrets migrate: split plan/apply/backup modules
This commit is contained in:
committed by
Peter Steinberger
parent
4807e40cbd
commit
363334253b
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user