feat(config): support reading Brave API key from a file (#313)

* feat: support reading Brave API key from a file
* chore: add secret file template and gitignore local keys
* docs: document optional Docker Compose secrets workflow
* fix: trim whitespace API keys and exclude secrets from Docker build
* docs: clarify container paths for BRAVE_API_KEY_FILE
* test: cover API key file config and expand Docker build context ignores
* test: isolate getOptions tests from local env vars
* docs: clarify optional use of BRAVE_API_KEY_FILE
* docs: document BRAVE_API_KEY_FILE in AWS Marketplace catalog template
This commit is contained in:
Sampson authored and GitHub committed 2026-06-24 13:53:51 -05:00
1 parent e3f77ced06
commit fd28e3e7b3
11 files changed
+225 -9

No files matched your search

+19
View File
@@ -1,3 +1,4 @@
import { readFileSync } from 'node:fs';
import { RATE_LIMIT } from './constants.js';
let requestCount = {
@@ -23,6 +24,24 @@ export function stringify(data: any, pretty = false) {
return pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
}
export type ReadBraveApiKeyFromFileResult =
| { ok: true; key: string }
| { ok: false; error: string };
export function readBraveApiKeyFromFile(filePath: string): ReadBraveApiKeyFromFileResult {
try {
const key = readFileSync(filePath, 'utf8').trim();
if (key.length === 0) {
return { ok: false, error: `API key file is empty: ${filePath}` };
}
return { ok: true, key };
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
return { ok: false, error: `Unable to read API key file '${filePath}': ${reason}` };
}
}
export function parsePort(value: unknown): number | null {
if (value === undefined || value === null || value === '') {
return null;