import { Risk } from "./rules/Risk" ; import { Remediation } from "./rules/Remediation" ; const fs = require ( 'fs' ) ; const program = require ( 'commander' ) ; program . option ( '-s, --save' , 'Validate and save the update file' ) . option ( '-r, --risk' , 'Validate Risks only' ) . option ( '-e, --remediation' , 'Validate Remediations only' ) . option ( '-d, --debug' , 'Enable debug output' ) ; program . parse ( process . argv ) ; var scanDir = function ( base , callback ) { fs . readdir ( base , ( err , entries ) => { entries . forEach ( ( entry ) => { if ( entry . endsWith ( "yaml" ) ) callback ( `${ base }/${ entry }` ) ; else if ( fs . lstatSync ( `${ base }/${ entry }` ) . isDirectory ( ) ) { scanDir ( `${ base }/${ entry }` , callback ) ; } } ) ; } ) ; } ; if ( program . risk || ! program . remediation ) { scanDir ( '../rules/risks' , ( file ) => { if ( program . debug ) console . log ( file ) ; var risk = new Risk ( file ) ; var valid = risk . validate ( ) ; try { risk . save ( undefined , ! program . save ) ; } catch ( e ) { console . error ( "Failed to save " + file ) ; console . error ( e ) ; valid = false ; } var error = valid ? '' : ' INVALID' ; console . log ( "Risk: " + risk . score + " - " + risk . risk + " - " + risk . title + error ) ; } ) ; } if ( program . remediation || ! program . risk ) { scanDir ( '../rules/remediations' , ( file ) => { var remediation = new Remediation ( file ) ; var valid = remediation . validate ; try { remediation . save ( undefined , ! program . save ) ; } catch ( e ) { console . error ( "Failed to save " + file ) ; console . error ( e ) ; } var error = valid ? '' : ' INVALID' ; console . log ( "Remediation: " + remediation . title + " " + remediation . vector + error ) ; } ) ; }