MCPcopy
hub / github.com/AutoMaker-Org/automaker / ensureApiKey

Function ensureApiKey

apps/ui/src/electron/security/api-key-manager.ts:25–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23 * Uses centralized electronUserData methods for path validation.
24 */
25export function ensureApiKey(): string {
26 try {
27 if (electronUserDataExists(API_KEY_FILENAME)) {
28 const key = electronUserDataReadFileSync(API_KEY_FILENAME).trim();
29 if (key) {
30 state.apiKey = key;
31 logger.info('Loaded existing API key');
32 return state.apiKey;
33 }
34 }
35 } catch (error) {
36 logger.warn('Error reading API key:', error);
37 }
38
39 // Generate new key
40 state.apiKey = crypto.randomUUID();
41 try {
42 electronUserDataWriteFileSync(API_KEY_FILENAME, state.apiKey, {
43 encoding: 'utf-8',
44 mode: 0o600,
45 });
46 logger.info('Generated new API key');
47 } catch (error) {
48 logger.error('Failed to save API key:', error);
49 }
50 return state.apiKey;
51}
52
53/**
54 * Get the current API key

Callers 1

handleAppReadyFunction · 0.90

Calls 3

electronUserDataExistsFunction · 0.90

Tested by

no test coverage detected