@@ -13,14 +13,17 @@ const YELLOW = '\x1b[33m'
1313const WHITE = '\x1b[0m'
1414const BLUE = '\x1b[34m'
1515const RESET = '\x1b[0m'
16- const opName = `SecOps `
16+ const opName = `Security `
1717
1818var argv = require ( 'yargs' )
19- . usage ( 'simplify-secops verify|patch|check|metric|snapshot [options]' )
19+ . usage ( 'simplify-security report| verify|patch|check|metric|snapshot [options]' )
2020 . string ( 'input' )
2121 . alias ( 'i' , 'input' )
22- . describe ( 'input' , 'Input file contains function list ' )
22+ . describe ( 'input' , 'Input lambda functions.csv file or *.JSON security report file ' )
2323 . default ( 'input' , 'functions.csv' )
24+ . string ( 'format' )
25+ . alias ( 'f' , 'format' )
26+ . describe ( 'format' , 'Input file format either CSV or JSON' )
2427 . string ( 'output' )
2528 . alias ( 'o' , 'output' )
2629 . describe ( 'output' , 'Output snapshot folder' )
@@ -54,11 +57,24 @@ var argv = require('yargs')
5457var configInputFile = argv . input || 'functions.csv'
5558var scanOutput = { }
5659var cmdOPS = ( argv . _ [ 0 ] || 'verify' ) . toUpperCase ( )
60+ var fileFormat = ( typeof argv . format === 'undefined' ? ( cmdOPS == 'REPORT' ? 'JSON' : 'CSV' ) : 'CSV' ) . toUpperCase ( )
5761var lineIndex = 0
5862var funcList = [ ]
59-
60- var files = require ( 'fs' ) . readFileSync ( path . resolve ( configInputFile ) , 'utf-8' ) . split ( / \r ? \n / )
61- var headers = files [ lineIndex ++ ]
63+ var files = [ ]
64+ var headers = [ ]
65+ var securityReports = { }
66+ var securityServerity = { critical : 0 , high : 0 , medium : 0 , low : 0 , info : 0 }
67+ try {
68+ var fileContent = require ( 'fs' ) . readFileSync ( path . resolve ( configInputFile ) , 'utf-8' )
69+ if ( fileFormat == 'CSV' ) {
70+ files = fileContent . split ( / \r ? \n / )
71+ headers = files [ lineIndex ++ ]
72+ } else if ( fileFormat == 'JSON' ) {
73+ securityReports = JSON . parse ( fileContent )
74+ }
75+ } catch ( e ) {
76+ console . log ( e )
77+ }
6278
6379function getSnapshotFromFile ( snapshotPath ) {
6480 simplify . consoleWithMessage ( opName , `${ cmdOPS } Snapshot from ${ snapshotPath } ` )
@@ -239,7 +255,7 @@ function printMetricCharts(metrics, functionList, pIndex, mIndex) {
239255 pIndex = pIndex < functionList . length ? pIndex : 0
240256 const functionName = functionList [ pIndex ] . functionInfo . FunctionName
241257 const lastHours = parseInt ( argv . hours || 3 )
242- const periodMins = parseInt ( argv . periods || 300 ) / 60
258+ const periodMins = parseInt ( argv . periods || 300 ) / 60
243259 const totalValues = { }
244260 const series = metrics . MetricDataResults . map ( m => {
245261 const functionId = m . Id . split ( '_' ) [ 1 ]
@@ -286,7 +302,7 @@ function printMetricTable(metrics, functionList) {
286302 const mData = { }
287303 const totalValues = { }
288304 const lastHours = parseInt ( argv . hours || 3 )
289- const periodMins = parseInt ( argv . periods || 300 ) / 60
305+ const periodMins = parseInt ( argv . periods || 300 ) / 60
290306 const table = new utilities . PrintTable ( )
291307 metrics . MetricDataResults . map ( ( m , idx ) => {
292308 const data = { }
@@ -386,10 +402,37 @@ try {
386402 } else if ( cmdOPS === 'SNAPSHOT' ) {
387403 takeSnapshotToFile ( functionList , path . resolve ( argv . output , `${ utilities . getDateToday ( ) } .json` ) )
388404 takeSnapshotToFile ( functionList , path . resolve ( argv . output , `$LATEST.json` ) )
405+ } else {
406+
389407 }
390408 } )
391409 }
392410 } )
393411} catch ( err ) {
394- simplify . finishWithErrors ( `${ opName } -LoadConfig` , err )
412+ simplify . finishWithErrors ( `${ opName } -Function` , err )
413+ }
414+
415+ try {
416+ if ( cmdOPS === 'REPORT' ) {
417+ utilities . printTableWithJSON ( securityReports . vulnerabilities . map ( v => {
418+ securityServerity . critical += v . severity == 'Critical' ? 1 : 0
419+ securityServerity . high += v . severity == 'High' ? 1 : 0
420+ securityServerity . medium += v . severity == 'Medium' ? 1 : 0
421+ securityServerity . low += v . severity == 'Low' ? 1 : 0
422+ securityServerity . info += v . severity == 'Unknown' ? 1 : 0
423+ return {
424+ id : v . id . truncateLeft ( 10 ) ,
425+ name : v . name . truncateLeft ( 30 ) ,
426+ severity : v . severity ,
427+ category : v . category ,
428+ identifier : v . identifiers . map ( i => i . type == 'cwe' ? i . name : undefined ) . filter ( o => o ) ,
429+ location : v . location . file . truncateLeft ( 50 )
430+ }
431+ } ) )
432+ if ( securityServerity . critical || securityServerity . high ) {
433+ throw ( `Analysed security report ${ configInputFile } we had found (${ securityServerity . critical } ) in CRITICAL and (${ securityServerity . high } ) in HIGH severity that STOPPED you continuing your work.` )
434+ }
435+ }
436+ } catch ( err ) {
437+ simplify . finishWithErrors ( `${ opName } -Report` , err )
395438}
0 commit comments