UNPKG

aws-lockbox

Version:

AWS SSM Parameter Store secrets manager with TypeScript support

64 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Lockbox = void 0; const Store_1 = require("./Store"); const ConfigLoader_1 = require("./ConfigLoader"); class Lockbox { constructor(maxTries = 100) { this._isSet = false; this._store = new Store_1.Store(maxTries); } static overrides(params) { if (!(params && Array.isArray(params))) return; for (const param of params) { process.env[param.Name] = param.Value; } } static setEnvVariables(params) { for (const param of params) { if (param.Name && param.Value) { process.env[param.Name] = param.Value; } } } async exec() { try { const config = ConfigLoader_1.ConfigLoader.loadConfig(); const names = [...config.parameters]; const parameters = await this._getParameters(names); Lockbox.setEnvVariables(parameters); Lockbox.overrides(config.overrides); this.isSet = true; console.log('Lockbox: Environment variables set'); } catch (err) { console.error('Lockbox: Failed to set environment variables', err); throw err; } } async wait(maxTries = 100, waitMS = 100) { let tries = 0; while (this.isSet === false && tries <= maxTries) { await this._sleep(waitMS); tries++; } if (tries >= maxTries && this.isSet === false) { throw new Error('Lockbox: Failed to set environment variables after ' + maxTries + ' tries'); } } get isSet() { return this._isSet; } set isSet(newIsSet) { this._isSet = newIsSet; } async _getParameters(names) { return this._store.getParameters(names); } async _sleep(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)); } } exports.Lockbox = Lockbox; //# sourceMappingURL=Lockbox.js.map