ssm-params
Version:
Obtain from AWS SSM Parameter Store
30 lines (29 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ssmToObj = void 0;
const queryParameterNamesWithPrefix_1 = require("./queryParameterNamesWithPrefix");
const getAllParameters_1 = require("./getAllParameters");
async function ssmToObj(options) {
if (typeof options === 'string') {
options = {
prefix: options,
};
}
const { prefix, target = {}, withDecryption } = options;
const Names = await queryParameterNamesWithPrefix_1.queryParameterNamesWithPrefix(prefix);
if (Names.length === 0) {
return target;
}
const { Parameters, InvalidParameters } = await getAllParameters_1.getAllParameters({ Names, WithDecryption: withDecryption });
if (InvalidParameters && InvalidParameters.length > 0) {
throw new Error(`Invalid parameter names : ${InvalidParameters.join(', ')}`);
}
if (!Parameters || Parameters.length === 0) {
return target;
}
Parameters.forEach(({ Name, Value }) => {
target[Name.substr(prefix.length)] = Value;
});
return target;
}
exports.ssmToObj = ssmToObj;