@@ -14,6 +14,7 @@ import {
14
14
printOccurrences ,
15
15
printServices ,
16
16
printTable ,
17
+ printVulnerabilities ,
17
18
} from "../display.js" ;
18
19
import { createBom } from "../index.js" ;
19
20
import { validateBom } from "../validator.js" ;
@@ -61,9 +62,13 @@ export const importSbom = (sbomOrPath) => {
61
62
if ( sbomOrPath ?. endsWith ( ".json" ) && fs . existsSync ( sbomOrPath ) ) {
62
63
try {
63
64
sbom = JSON . parse ( fs . readFileSync ( sbomOrPath , "utf-8" ) ) ;
64
- console . log ( `✅ SBOM imported successfully from ${ sbomOrPath } ` ) ;
65
+ let bomType = "SBOM" ;
66
+ if ( sbom ?. vulnerabilities && Array . isArray ( sbom . vulnerabilities ) ) {
67
+ bomType = "VDR" ;
68
+ }
69
+ console . log ( `✅ ${ bomType } imported successfully from ${ sbomOrPath } ` ) ;
65
70
} catch ( e ) {
66
- console . log ( `⚠ Unable to import the SBOM from ${ sbomOrPath } due to ${ e } ` ) ;
71
+ console . log ( `⚠ Unable to import the BOM from ${ sbomOrPath } due to ${ e } ` ) ;
67
72
}
68
73
} else {
69
74
console . log ( `⚠ ${ sbomOrPath } is invalid.` ) ;
@@ -72,13 +77,13 @@ export const importSbom = (sbomOrPath) => {
72
77
// Load any sbom passed from the command line
73
78
if ( process . argv . length > 2 ) {
74
79
importSbom ( process . argv [ process . argv . length - 1 ] ) ;
75
- console . log ( "💭 Type .print to view the SBOM as a table" ) ;
80
+ console . log ( "💭 Type .print to view the BOM as a table" ) ;
76
81
} else if ( fs . existsSync ( "bom.json" ) ) {
77
82
// If the current directory has a bom.json load it
78
83
importSbom ( "bom.json" ) ;
79
84
} else {
80
85
console . log ( "💭 Use .create <path> to create an SBOM for the given path." ) ;
81
- console . log ( "💭 Use .import <json> to import an existing SBOM ." ) ;
86
+ console . log ( "💭 Use .import <json> to import an existing BOM ." ) ;
82
87
console . log ( "💭 Type .exit or press ctrl+d to close." ) ;
83
88
}
84
89
@@ -302,7 +307,7 @@ cdxgenRepl.defineCommand("validate", {
302
307
if ( sbom ) {
303
308
const result = validateBom ( sbom ) ;
304
309
if ( result ) {
305
- console . log ( "SBOM is valid!" ) ;
310
+ console . log ( "BOM is valid!" ) ;
306
311
}
307
312
} else {
308
313
console . log (
@@ -426,7 +431,7 @@ cdxgenRepl.defineCommand("services", {
426
431
let services = await expression . evaluate ( sbom ) ;
427
432
if ( ! services ) {
428
433
console . log (
429
- "No services found. Use evinse command to generate an SBOM with evidence." ,
434
+ "No services found. Use evinse command to generate a SaaSBOM with evidence." ,
430
435
) ;
431
436
} else {
432
437
if ( ! Array . isArray ( services ) ) {
@@ -439,12 +444,38 @@ cdxgenRepl.defineCommand("services", {
439
444
}
440
445
} else {
441
446
console . log (
442
- "⚠ No SBOM is loaded. Use .import command to import an evinse SBOM " ,
447
+ "⚠ No SaaSBOM is loaded. Use .import command to import a SaaSBOM " ,
443
448
) ;
444
449
}
445
450
this . displayPrompt ( ) ;
446
451
} ,
447
452
} ) ;
453
+ cdxgenRepl . defineCommand ( "vulnerabilities" , {
454
+ help : "view vulnerabilities" ,
455
+ async action ( ) {
456
+ if ( sbom ) {
457
+ try {
458
+ const expression = jsonata ( "vulnerabilities" ) ;
459
+ let vulnerabilities = await expression . evaluate ( sbom ) ;
460
+ if ( ! vulnerabilities ) {
461
+ console . log (
462
+ "No vulnerabilities found. Use depscan to generate a VDR file with vulnerabilities." ,
463
+ ) ;
464
+ } else {
465
+ if ( ! Array . isArray ( vulnerabilities ) ) {
466
+ vulnerabilities = [ vulnerabilities ] ;
467
+ }
468
+ printVulnerabilities ( vulnerabilities ) ;
469
+ }
470
+ } catch ( e ) {
471
+ console . log ( e ) ;
472
+ }
473
+ } else {
474
+ console . log ( "⚠ No BOM is loaded. Use .import command to import a VDR" ) ;
475
+ }
476
+ this . displayPrompt ( ) ;
477
+ } ,
478
+ } ) ;
448
479
cdxgenRepl . defineCommand ( "osinfocategories" , {
449
480
help : "view the category names for the OS info from the obom" ,
450
481
async action ( ) {
0 commit comments