Skip to content

Instantly share code, notes, and snippets.

@gpsarkar
Created January 6, 2019 15:35
Show Gist options
  • Select an option

  • Save gpsarkar/220b73e69b49ed623ab9d596f4c7ce59 to your computer and use it in GitHub Desktop.

Select an option

Save gpsarkar/220b73e69b49ed623ab9d596f4c7ce59 to your computer and use it in GitHub Desktop.
csp report uri lambda
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
const uuidv4 = require('uuid/v4');
exports.handler = (event, context, callback) => {
// Callback to finish response
const done = (err, res) => callback(null, {
statusCode: err ? '400' : '204',
body: err ? err.message : '',
headers: {
'Content-Type': 'application/json',
}
});
switch (event.httpMethod) {
case 'POST':
var reqJson = JSON.parse(event.body, (key, value) => {
if (value === null || value === '') {
return "NA";
}
return value;
});
if(!reqJson.hasOwnProperty('csp-report')) {
done();
break;
}
var item = reqJson["csp-report"];
item.id = uuidv4();
item.timestamp = new Date().getTime().toString();
dynamo.putItem({
TableName: process.env.table,
Item: item
}, done);
break;
default:
done(new Error('Unsupported method'));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment