Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stackvalidator

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stackvalidator - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

195

bin/index.js
'use strict';
let validateTemplate = (() => {
var _ref = _asyncToGenerator(function* (templatePath, delay) {
try {
yield validate(templatePath, delay);
} catch (ex) {
console.log(ex);
}
});
var validateTemplate = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(templatePath, delay) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return validate(templatePath, delay);
case 3:
_context.next = 8;
break;
case 5:
_context.prev = 5;
_context.t0 = _context['catch'](0);
console.log(_context.t0);
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[0, 5]]);
}));
return function validateTemplate(_x, _x2) {
return _ref.apply(this, arguments);
};
})();
}();
let validateTemplates = (() => {
var _ref2 = _asyncToGenerator(function* (rootPath, delay) {
try {
const { templates } = yield getTemplates(rootPath);
const templatePaths = templates.map(function (template) {
return template.path;
});
console.log(chalk.yellow(`Found ${templatePaths.length} template${templatePaths.length !== 1 ? 's' : ''}\r\n${rootPath}`));
console.log(chalk.yellow(templatePaths.join(',\n').replace(new RegExp(rootPath, 'g'), ' └ ')));
console.log(chalk.yellow('---------------------------'));
templatePaths.forEach(function (template) {
return queue.add(function () {
return validateTemplate(template, delay);
});
});
} catch (exception) {
console.log(chalk.red(`[ERROR] ${exception.message}`));
process.exit(1);
}
});
var validateTemplates = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(rootPath, delay) {
var _ref3, templates, templatePaths;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return getTemplates(rootPath);
case 3:
_ref3 = _context2.sent;
templates = _ref3.templates;
templatePaths = templates.map(function (template) {
return template.path;
});
console.log(chalk.yellow('Found ' + templatePaths.length + ' template' + (templatePaths.length !== 1 ? 's' : '') + '\r\n' + rootPath));
console.log(chalk.yellow(templatePaths.join(',\n').replace(new RegExp(rootPath, 'g'), ' └ ')));
console.log(chalk.yellow('---------------------------'));
templatePaths.forEach(function (template) {
return queue.add(function () {
return validateTemplate(template, delay);
});
});
_context2.next = 16;
break;
case 12:
_context2.prev = 12;
_context2.t0 = _context2['catch'](0);
console.log(chalk.red('[ERROR] ' + _context2.t0.message));
process.exit(1);
case 16:
case 'end':
return _context2.stop();
}
}
}, _callee2, this, [[0, 12]]);
}));
return function validateTemplates(_x3, _x4) {
return _ref2.apply(this, arguments);
};
})();
}();
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const klaw = require('klaw');
const path = require('path');
const fs = require('fs-extra');
const AWS = require('aws-sdk');
const Queue = require('promise-queue');
const chalk = require('chalk');
var klaw = require('klaw');
var path = require('path');
var fs = require('fs-extra');
var AWS = require('aws-sdk');
var Queue = require('promise-queue');
var chalk = require('chalk');
const maxConcurrent = 1;
const maxQueue = Infinity;
const queue = new Queue(maxConcurrent, maxQueue);
var maxConcurrent = 1;
var maxQueue = Infinity;
var queue = new Queue(maxConcurrent, maxQueue);
const config = {
var config = {
region: AWS.config.region || 'eu-west-1'
};
const cloudFormation = new AWS.CloudFormation(config);
var cloudFormation = new AWS.CloudFormation(config);
const getTemplates = rootPath => new Promise((resolve, reject) => {
const templates = [];
let counter = 0;
klaw(rootPath).on('data', item => {
const ext = path.extname(item.path);
if (['.yml', '.json'].includes(ext)) {
const contents = fs.readFileSync(item.path).toString();
counter = counter + 1;
if (counter > 1000) {
return reject(new Error(`Lots of json and yml files found, is '${rootPath}/*' really the path you want to validate?`));
} else if (/AWSTemplateFormatVersion/g.test(contents)) {
templates.push(item);
var getTemplates = function getTemplates(rootPath) {
return new Promise(function (resolve, reject) {
var templates = [];
var counter = 0;
klaw(rootPath).on('data', function (item) {
var ext = path.extname(item.path);
if (['.yml', '.json'].includes(ext)) {
var contents = fs.readFileSync(item.path).toString();
counter = counter + 1;
if (counter > 1000) {
return reject(new Error('Lots of json and yml files found, is \'' + rootPath + '/*\' really the path you want to validate?'));
} else if (/AWSTemplateFormatVersion/g.test(contents)) {
templates.push(item);
}
}
}
}).on('error', (error, item) => reject(error)).on('end', () => resolve({ templates }));
});
}).on('error', function (error, item) {
return reject(error);
}).on('end', function () {
return resolve({ templates: templates });
});
});
};
const validate = (templatePath, delay) => new Promise(resolve => {
console.log('Validate:', templatePath);
return setTimeout(() => cloudFormation.validateTemplate({
TemplateBody: fs.readFileSync(templatePath).toString()
}).promise().then(result => {
console.log(chalk.green(` ✓ [${templatePath}]`));
return resolve(result);
}).catch(error => {
console.log(chalk.red(` ✗ [${templatePath}]`));
console.log(chalk.red(JSON.stringify(error, null, 2)));
return resolve({ error });
}), delay);
});
var validate = function validate(templatePath, delay) {
return new Promise(function (resolve) {
console.log('Validate:', templatePath);
return setTimeout(function () {
return cloudFormation.validateTemplate({
TemplateBody: fs.readFileSync(templatePath).toString()
}).promise().then(function (result) {
console.log(chalk.green(' \u2713 [' + templatePath + ']'));
return resolve(result);
}).catch(function (error) {
console.log(chalk.red(' \u2717 [' + templatePath + ']'));
console.log(chalk.red(JSON.stringify(error, null, 2)));
return resolve({ error: error });
});
}, delay);
});
};
module.exports = {
validateTemplates,
validateTemplate
validateTemplates: validateTemplates,
validateTemplate: validateTemplate
};

@@ -6,18 +6,18 @@ #!/usr/bin/env node

const {
validateTemplate,
validateTemplates
} = require('./index');
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const args = require('yargs').argv;
var _require = require('./index'),
validateTemplate = _require.validateTemplate,
validateTemplates = _require.validateTemplates;
var fs = require('fs-extra');
var path = require('path');
var chalk = require('chalk');
var args = require('yargs').argv;
console.log(chalk.yellow('***** AWS CloudFormation Stack Validator *****'));
console.log(chalk.yellow('usage: stackvalidator path-to-stacks offset-in-ms'));
const normalizedPath = path.normalize(args.path || '.');
const delay = args.delay || 100;
var normalizedPath = path.normalize(args.path || '.');
var delay = args.delay || 100;
fs.lstat(normalizedPath, (error, stats) => {
fs.lstat(normalizedPath, function (error, stats) {
if (error) {

@@ -24,0 +24,0 @@ return console.log(error);

@@ -6,3 +6,3 @@ {

},
"version": "0.1.4",
"version": "0.1.5",
"author": "Eetu Tuomala",

@@ -22,3 +22,4 @@ "license": "MIT",

"scripts": {
"prepare": "babel src --out-dir bin",
"build": "babel src --out-dir bin",
"prepare": "npm run build",
"stackvalidator": "bin/stackvalidator.js"

@@ -38,5 +39,5 @@ },

"babel-preset-env": "^1.6.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc