Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getSSMInstance = awsSdkOptions => {
// lazy load aws-sdk and SSM constructor to avoid performance
// penalties if you don't use this middleware
// AWS Lambda has aws-sdk included version 2.176.0
// see https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html
const { SSM } = require('aws-sdk')
return new SSM(awsSdkOptions)
}
async deleteParameterStore(ingestEndpoints) {
try {
const ssm = new SSM({ apiVersion: '2014-11-06' });
const promises = ingestEndpoints.map((x, idx) =>
ssm.deleteParameter({
Name: `${this.ssmKey}-${idx}`,
}).promise());
await Promise.all(promises);
return true;
} catch (e) {
console.error(e);
return false;
}
}
var getSystemParameter = /*async*/function(paramName, cachedValue, callback) {
if(cachedValue && (cachedValue != null)) {
if(callback) callback(null, cachedValue);
return cachedValue;
}
if(process.env[paramName]) {
cachedValue = process.env[paramName];
if(callback) callback(null, cachedValue);
} else {
var ssm = new AWS.SSM();
/*await*/ssm.getParameter({Name : paramName}).promise()
.then(data => {
cachedValue = data.Parameter["Value"];
console.log("Successfully retrieved " + paramName + ": " + cachedValue);
if(callback) callback(null, cachedValue);
})
.catch(err => {
console.log("Error Retrieving " + paramName + ": " + err);
cachedValue = null;
if(callback) callback(err, null);
});
}
return cachedValue;
}
module.exports = function lookupTables(callback) {
let ssm = new aws.SSM
let Path = `/${process.env.ARC_CLOUDFORMATION}`
ssm.getParametersByPath({Path, Recursive:true}, function done(err, result) {
if (err) callback(err)
else {
let table = param=> param.Name.split('/')[2] === 'tables'
let tables = result.Parameters.filter(table).reduce((a, b)=> {
a[b.Name.split('/')[3]] = b.Value
return a
}, {})
callback(null, tables)
}
})
}
function requestSSMParameters(variables, stage, region, profile) {
AWS.config.credentials = new AWS.SharedIniFileCredentials({profile});
const ssm = new AWS.SSM({region: region});
const ps = {
Names: variables,
WithDecryption: true
};
return ssm.getParameters(ps).promise();
}
async function createSSMParameter(channelKey, hookURLKey, cb) {
const ssm = new AWS.SSM();
try {
const data = await ssm
.getParameters({Names: [channelKey, hookURLKey], WithDecryption: true})
.promise();
LOGGER.log(
'DEBUG',
`${JSON.stringify(
{
SSMParameter: {
create: 'true',
parameters: data.InvalidParameters,
},
},
null,
2
)}`
function loadAwsConfig(properties) {
let region = properties('region');
if (!region) {
return Promise.resolve({});
}
let ssm = new AWS.SSM({region: region});
const path = '/compiler-explorer/';
return ssm.getParametersByPath({
Path: path
})
.promise()
.then((response) => {
const map = {};
response.Parameters.forEach((response) => {
map[response.Name.substr(path.length)] = response.Value;
});
logger.info("AWS info:", map);
return map;
})
.catch((error) => {
logger.error(`Failed to get AWS info: ${error}`);
return {};
const getParameters = ({ region, stage, name }, callback) => {
try {
const ssm = new SSM({ region })
const Names = parameterNames.map(
k => ['/app', name, stage, k].join('/')
)
const params = { Names }
ssm.getParameters(params, callback)
} catch (error) {
callback(error)
}
}
async function getParameter(name, region) {
const config = typeof region === 'string' ? { region } : undefined;
const parameterStore = new AWS.SSM(config);
return new Promise((resolve, reject) => parameterStore.getParameter(
{ Name: name, WithDecryption: true },
(error, data) => error ? reject(error) : resolve(data.Parameter.Value),
));
}