@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
67 lines • 1.76 kB
JavaScript
/**
* @module runtime/providers/env-provider
* @description Environment variable secret provider
*/
/**
* Environment variable secret provider
*/
export class EnvProvider {
name = 'env';
config;
constructor(config = {}) {
this.config = {
prefix: config.prefix ?? '',
uppercase: config.uppercase ?? true,
allowMissing: config.allowMissing ?? false,
};
}
/**
* Get a single secret from environment variables
*/
async getSecret(key) {
const envKey = this.transformKey(key);
const value = process.env[envKey];
if (value === undefined) {
if (this.config.allowMissing) {
return '';
}
throw new Error(`Secret not found: ${key} (env: ${envKey})`);
}
return value;
}
/**
* Get multiple secrets from environment variables
*/
async getSecrets(keys) {
const results = new Map();
for (const key of keys) {
try {
const value = await this.getSecret(key);
results.set(key, value);
}
catch (error) {
if (!this.config.allowMissing) {
throw error;
}
}
}
return results;
}
/**
* Check if provider is available (always true for env vars)
*/
async isAvailable() {
return true;
}
/**
* Transform key to environment variable name
*/
transformKey(key) {
let envKey = this.config.prefix + key;
if (this.config.uppercase) {
envKey = envKey.toUpperCase();
}
return envKey;
}
}
//# sourceMappingURL=env-provider.js.map