33 * Export a security debt from DefectDojo.
44 */
55
6- import { join } from "path" ;
6+ import assert from "node:assert/strict" ;
7+ import { join } from "node:path" ;
78import { parseArgs } from "./cli.js" ;
89import { loadConfig } from "./config.js" ;
910import { DefectDojoApiClient } from "./defectdojo.js" ;
@@ -16,7 +17,10 @@ export async function main() {
1617
1718 // Load configuration
1819 const config = await loadConfig ( opts . config )
19- . catch ( ( e ) => { console . error ( `[error] ${ e . message } ` ) ; process . exit ( 1 ) ; } ) ;
20+ . catch ( ( e ) => {
21+ console . error ( `[error] ${ e . message } ` ) ;
22+ process . exit ( 1 ) ;
23+ } ) ;
2024
2125 // Initialise the DefectDojo API client
2226 const defectDojo = new DefectDojoApiClient ( opts . url , opts . token ) ;
@@ -27,38 +31,51 @@ export async function main() {
2731 . reduce ( async ( prevResults , p ) => {
2832 const results = await prevResults ;
2933 const product = await defectDojo . getProduct ( p )
30- . catch ( ( e ) => { console . error ( `[error] ${ e . message } ` ) ; process . exit ( 1 ) ; } ) ;
34+ . catch ( ( e ) => {
35+ console . error ( `[error] ${ e . message } ` ) ;
36+ process . exit ( 1 ) ;
37+ } ) ;
3138 return [ ...results , product ] ;
3239 } , [ ] ) ;
3340
3441 // Fetch engagements
3542 const engagements = await products . reduce ( async ( prevResults , p ) => {
3643 const results = await prevResults ;
3744 const engagements = await defectDojo . getEngagements ( p . id , opts . engagement )
38- . catch ( ( e ) => { console . error ( `[error] ${ e . message } ` ) ; process . exit ( 1 ) ; } ) ;
45+ . catch ( ( e ) => {
46+ console . error ( `[error] ${ e . message } ` ) ;
47+ process . exit ( 1 ) ;
48+ } ) ;
3949 p . engagements = engagements ;
4050 return [ ...results , ...engagements ] ;
4151 } , [ ] ) ;
4252
53+ assert ( engagements . length > 0 , "No engagement found" ) ;
54+
4355 // Fetch vulnerabilities
4456 const findings = await defectDojo
4557 . getFindings ( engagements . map ( e => e . id ) , opts . status )
46- . catch ( ( e ) => { console . error ( `[error] ${ e . message } ` ) ; process . exit ( 1 ) ; } ) ;
58+ . catch ( ( e ) => {
59+ console . error ( `[error] ${ e . message } ` ) ;
60+ process . exit ( 1 ) ;
61+ } ) ;
4762
4863 /*
4964 * Process vulnerabilities
5065 */
5166
5267 console . log ( "[info] Processing findings" ) ;
5368
54- const { impacts, eases, easeTags, criticities,
55- criticityMatrix, originTags, serviceProviderTag } = config ;
69+ const {
70+ impacts, eases, easeTags, criticities,
71+ criticityMatrix, originTags, serviceProviderTag
72+ } = config ;
5673
5774 // Compute additional fields
5875 for ( const finding of findings ) {
5976 // Resultant criticity
6077 finding . severity = finding . severity ?. toLowerCase ( ) ;
61- const i = Math . max ( impacts . findIndex ( i => i == finding . severity ) , 0 ) ;
78+ const i = Math . max ( impacts . findIndex ( i => i === finding . severity ) , 0 ) ;
6279 const e = easeTags . indexOf ( finding . tags ?. find ( t => easeTags . includes ( t ) ) ?? easeTags [ 0 ] ) ;
6380 finding . ease_index = e ;
6481 finding . ease = eases [ e ] ;
@@ -82,13 +99,13 @@ export async function main() {
8299 ( f2 . severity_index - f1 . severity_index ) || f1 . title . localeCompare ( f2 . title ) ) ;
83100
84101 console . log ( "[info] Vulnerabilities:" , criticities . map ( c =>
85- findings . filter ( f => f . criticity == c ) . length + " " + c ) . join ( ", " ) ) ;
102+ findings . filter ( f => f . criticity === c ) . length + " " + c ) . join ( ", " ) ) ;
86103
87104 /*
88105 * Generate reports
89106 */
90107
91- const defaultReportName = "Security-Debt" + ( products . length == 1 ? `_${ products [ 0 ] . name } ` : "" ) ;
108+ const defaultReportName = "Security-Debt" + ( products . length === 1 ? `_${ products [ 0 ] . name } ` : "" ) ;
92109 const path = opts . output ?? join ( process . cwd ( ) , defaultReportName ) ;
93110
94111 for ( const format of opts . format ) {
0 commit comments