mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
Running any CLI command — even `omniroute --version` or `--help` — generated a 32-byte STORAGE_ENCRYPTION_KEY and created `~/.omniroute/.env` (or DATA_DIR/.env). A read-only command should never mutate the data dir. Gate the provisioning behind shouldProvisionStorageKey(): skip for --version/--help/help/completion and bare invocations; still provision for real commands (serve, keys, …) so the encryption key persists before storage is accessed (#1622).
29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
/**
|
|
* Decide whether a CLI invocation should provision (generate + persist) the
|
|
* STORAGE_ENCRYPTION_KEY into DATA_DIR/.env.
|
|
*
|
|
* Purely informational invocations must NOT create `~/.omniroute/.env` or write
|
|
* a key — they never touch encrypted storage. Generating a 32-byte key and a
|
|
* `.env` file just to print `omniroute --version` (or `--help`) is a surprising
|
|
* side effect: running a read-only command should not mutate the data dir.
|
|
*
|
|
* Returns false for: no command at all (bare `omniroute` → Commander prints
|
|
* help), `--version`/`-V` or `--help`/`-h` anywhere in the args, and the
|
|
* `help`/`completion` subcommands. Returns true for every real command
|
|
* (`serve`, `keys`, `providers`, …) so the encryption key is still provisioned
|
|
* before encrypted storage is accessed (preserves the #1622 persistence fix).
|
|
*
|
|
* @param {string[]} argv - process.argv (node + script + args).
|
|
* @returns {boolean}
|
|
*/
|
|
const INFO_FLAGS = new Set(["-h", "--help", "-V", "--version"]);
|
|
const INFO_COMMANDS = new Set(["help", "completion"]);
|
|
|
|
export function shouldProvisionStorageKey(argv) {
|
|
const args = Array.isArray(argv) ? argv.slice(2) : [];
|
|
if (args.length === 0) return false;
|
|
if (args.some((a) => INFO_FLAGS.has(a))) return false;
|
|
if (INFO_COMMANDS.has(args[0])) return false;
|
|
return true;
|
|
}
|