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:
1 parent
e3f77ced06
commit
fd28e3e7b3
11 files changed
+225
-9
No files matched your search
+41
-1
@@ -1,6 +1,9 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { describe, it } from 'node:test';
|
||||
import { parsePort } from './utils.js';
|
||||
import { parsePort, readBraveApiKeyFromFile } from './utils.js';
|
||||
|
||||
describe('parsePort', () => {
|
||||
it('accepts valid integer ports', () => {
|
||||
@@ -22,3 +25,40 @@ describe('parsePort', () => {
|
||||
assert.equal(parsePort(undefined), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('readBraveApiKeyFromFile', () => {
|
||||
it('reads and trims API keys from a file', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'brave-api-key-'));
|
||||
const filePath = join(dir, 'key.txt');
|
||||
writeFileSync(filePath, 'test-api-key\n');
|
||||
|
||||
const result = readBraveApiKeyFromFile(filePath);
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
if (result.ok) {
|
||||
assert.equal(result.key, 'test-api-key');
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects empty files', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'brave-api-key-'));
|
||||
const filePath = join(dir, 'empty.txt');
|
||||
writeFileSync(filePath, '\n');
|
||||
|
||||
const result = readBraveApiKeyFromFile(filePath);
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
if (!result.ok) {
|
||||
assert.match(result.error, /empty/i);
|
||||
}
|
||||
});
|
||||
|
||||
it('reports missing files with the path and reason', () => {
|
||||
const result = readBraveApiKeyFromFile('definitely-not-a-real-api-key-file');
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
if (!result.ok) {
|
||||
assert.match(result.error, /definitely-not-a-real-api-key-file/);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user