aws-lockbox
Version:
AWS SSM Parameter Store secrets manager with TypeScript support
53 lines • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Store = void 0;
const client_ssm_1 = require("@aws-sdk/client-ssm");
const Throttler_1 = require("./Throttler");
const REGION = 'us-east-1';
const MAX_RETRIES = 10;
class Store {
constructor(maxRetries = MAX_RETRIES) {
this._store = new client_ssm_1.SSMClient({
region: REGION,
});
this._maxRetries = maxRetries;
}
get store() {
return this._store;
}
async getParameters(parameterNames) {
const limit = 10;
const chunks = Math.ceil(parameterNames.length / limit);
const promises = [];
for (let i = 0; i < chunks; i++) {
const names = parameterNames.slice(i * limit, limit + i * limit);
promises.push(this._getParameters(names));
}
const responses = await Promise.all(promises);
return responses.flat();
}
async _getParameters(names, retries = 0) {
const command = new client_ssm_1.GetParametersCommand(this._arg(names));
try {
const response = await this._store.send(command);
return response.Parameters || [];
}
catch (err) {
// We want to retry a fixed amount of times.
if (Throttler_1.Throttler.isThrottledError(err) && retries < this._maxRetries) {
await new Promise(resolve => setTimeout(resolve, retries * 1000));
console.log(`Lockbox: ThrottlingException: Retried ${retries + 1} times so far...`);
return this._getParameters(names, retries + 1);
}
throw err;
}
}
_arg(names) {
return {
Names: names,
WithDecryption: true
};
}
}
exports.Store = Store;
//# sourceMappingURL=Store.js.map