@@ -6,140 +6,139 @@ import {
66 ScannerEvents ,
77 ScannerInput ,
88 ScannerResults ,
9- WinnowingMode
9+ WinnowingMode ,
1010} from '../../sdk/scanner/ScannerTypes' ;
1111import { ScannerCfg } from '../../sdk/scanner/ScannerCfg' ;
1212import { Tree } from '../../sdk/tree/Tree' ;
1313import cliProgress from 'cli-progress' ;
14- import {
15- DispatcherResponse
16- } from '../../sdk/scanner/Dispatcher/DispatcherResponse' ;
14+ import { DispatcherResponse } from '../../sdk/scanner/Dispatcher/DispatcherResponse' ;
1715import { getProjectNameFromPath , isFolder } from './helpers' ;
1816
19-
20- import {
21- DependencyScannerCfg
22- } from '../../sdk/Dependencies/DependencyScannerCfg' ;
17+ import { DependencyScannerCfg } from '../../sdk/Dependencies/DependencyScannerCfg' ;
2318import { DependencyScanner } from '../../sdk/Dependencies/DependencyScanner' ;
2419import { IDependencyResponse } from '../../sdk/Dependencies/DependencyTypes' ;
2520import { ScanFilter } from '../../sdk/tree/Filters/ScanFilter' ;
2621import { DependencyFilter } from '../../sdk/tree/Filters/DependencyFilter' ;
2722import { Report } from '../../sdk/Report/Report' ;
28- import { DataProviderManager } from '../../sdk/DataLayer/DataProviderManager' ;
29- import {
30- ComponentDataProvider
31- } from '../../sdk/DataLayer/DataProviders/ComponentDataProvider' ;
32- import {
33- DependencyDataProvider
34- } from '../../sdk/DataLayer/DataProviders/DependencyDataProvider' ;
35- import {
36- LicenseDataProvider
37- } from '../../sdk/DataLayer/DataProviders/LicenseDataProvider' ;
38- import {
39- SummaryDataProvider
40- } from '../../sdk/DataLayer/DataProviders/SummaryDataProvider' ;
41- import {
42- DecompressionFilter
43- } from '../../sdk/tree/Filters/DecompressionFilter' ;
44- import {
45- DecompressionManager
46- } from '../../sdk/Decompress/DecompressionManager' ;
23+ import { DataProviderManager } from '../../sdk/Report/DataLayer/DataProviderManager' ;
24+ import { ComponentDataProvider } from '../../sdk/Report/DataLayer/DataProviders/ComponentDataProvider' ;
25+ import { DependencyDataProvider } from '../../sdk/Report/DataLayer/DataProviders/DependencyDataProvider' ;
26+ import { LicenseDataProvider } from '../../sdk/Report/DataLayer/DataProviders/LicenseDataProvider' ;
27+ import { SummaryDataProvider } from '../../sdk/Report/DataLayer/DataProviders/SummaryDataProvider' ;
28+ import { DecompressionFilter } from '../../sdk/tree/Filters/DecompressionFilter' ;
29+ import { DecompressionManager } from '../../sdk/Decompress/DecompressionManager' ;
4730import path from 'path' ;
4831
49-
50- export async function scanHandler ( rootPath : string , options : any ) : Promise < void > {
51-
32+ export async function scanHandler (
33+ rootPath : string ,
34+ options : any
35+ ) : Promise < void > {
5236 rootPath = path . resolve ( rootPath ) ;
5337
5438 const pathIsFolder = await isFolder ( rootPath ) ;
55- const projectName = getProjectNameFromPath ( rootPath )
39+ const projectName = getProjectNameFromPath ( rootPath ) ;
5640
5741 // Create dependency scanner and set parameters
5842 let dependencyInput : Array < string > = [ ] ;
5943 const dependencyScannerCfg = new DependencyScannerCfg ( ) ;
6044 if ( options . api2url ) dependencyScannerCfg . API_URL = options . api2url ;
6145 if ( options . proxy ) dependencyScannerCfg . PROXY = options . proxy ;
62- if ( options . pac ) dependencyScannerCfg . PAC = options . pac ;
46+ if ( options . pac ) dependencyScannerCfg . PAC = options . pac ;
6347 await dependencyScannerCfg . validate ( ) ;
6448 const dependencyScanner = new DependencyScanner ( dependencyScannerCfg ) ;
6549
66-
67-
6850 // Create scanner and set connections parameters
6951 const scannerCfg = new ScannerCfg ( ) ;
70- if ( options . concurrency ) scannerCfg . CONCURRENCY_LIMIT = parseInt ( options . concurrency ) ;
71- if ( options . postSize ) scannerCfg . WFP_FILE_MAX_SIZE = parseInt ( options . postSize ) * 1024 ;
72- if ( options . apiurl ) scannerCfg . API_URL = options . apiurl ;
73- if ( options . key ) scannerCfg . API_KEY = options . key ;
74- if ( options . timeout ) scannerCfg . TIMEOUT = options . timeout * 1000 ;
75- if ( options . maxRetry ) scannerCfg . MAX_RETRIES_FOR_RECOVERABLES_ERRORS = options . maxRetry ;
76- if ( options . caCert ) scannerCfg . CA_CERT = options . caCert ;
77- if ( options . ignoreCertErrors ) scannerCfg . IGNORE_CERT_ERRORS = true ;
78- if ( options . pac ) scannerCfg . PAC = options . pac ;
79- if ( options . proxy ) scannerCfg . PROXY = options . proxy ;
80- if ( options . obfuscate ) scannerCfg . WFP_OBFUSCATION = true ;
52+ if ( options . concurrency )
53+ scannerCfg . CONCURRENCY_LIMIT = parseInt ( options . concurrency ) ;
54+ if ( options . postSize )
55+ scannerCfg . WFP_FILE_MAX_SIZE = parseInt ( options . postSize ) * 1024 ;
56+ if ( options . apiurl ) scannerCfg . API_URL = options . apiurl ;
57+ if ( options . key ) scannerCfg . API_KEY = options . key ;
58+ if ( options . timeout ) scannerCfg . TIMEOUT = options . timeout * 1000 ;
59+ if ( options . maxRetry )
60+ scannerCfg . MAX_RETRIES_FOR_RECOVERABLES_ERRORS = options . maxRetry ;
61+ if ( options . caCert ) scannerCfg . CA_CERT = options . caCert ;
62+ if ( options . ignoreCertErrors ) scannerCfg . IGNORE_CERT_ERRORS = true ;
63+ if ( options . pac ) scannerCfg . PAC = options . pac ;
64+ if ( options . proxy ) scannerCfg . PROXY = options . proxy ;
65+ if ( options . obfuscate ) scannerCfg . WFP_OBFUSCATION = true ;
8166
8267 await scannerCfg . validate ( ) ;
8368 const scanner = new Scanner ( scannerCfg ) ;
8469
85- let scannerInput : ScannerInput = { fileList : [ ] } ;
70+ let scannerInput : ScannerInput = { fileList : [ ] } ;
8671 scannerInput . folderRoot = rootPath + path . sep ; // This will remove the project root path from the results.
87- if ( options . flags ) scannerInput . engineFlags = options . flags ;
72+ if ( options . flags ) scannerInput . engineFlags = options . flags ;
8873 if ( options . wfp ) scannerInput . wfpPath = rootPath ;
8974
90- const wfpMode = options . hpsm ? WinnowingMode . FULL_WINNOWING_HPSM : WinnowingMode . FULL_WINNOWING ;
91- scannerInput . winnowing = { mode : wfpMode } ;
75+ const wfpMode = options . hpsm
76+ ? WinnowingMode . FULL_WINNOWING_HPSM
77+ : WinnowingMode . FULL_WINNOWING ;
78+ scannerInput . winnowing = { mode : wfpMode } ;
9279
93- if ( ! options . wfp ) {
94- if ( pathIsFolder ) {
80+ if ( ! options . wfp ) {
81+ if ( pathIsFolder ) {
9582 console . error ( '\nReading directory... ' ) ;
9683 const tree = new Tree ( rootPath ) ;
9784 tree . build ( ) ;
9885
99- if ( options . extract ) {
100- const archives = tree . getFileList ( new DecompressionFilter ( "" ) ) ;
101- console . error ( "Searching archives files..." )
102- if ( archives . length ) {
103- console . error ( "Extracting archives..." )
104- const decompressionManager = new DecompressionManager ( options . extractDeep , options . extractSuffix , options . extractOverwrite ) ;
86+ if ( options . extract ) {
87+ const archives = tree . getFileList ( new DecompressionFilter ( '' ) ) ;
88+ console . error ( 'Searching archives files...' ) ;
89+ if ( archives . length ) {
90+ console . error ( 'Extracting archives...' ) ;
91+ const decompressionManager = new DecompressionManager (
92+ options . extractDeep ,
93+ options . extractSuffix ,
94+ options . extractOverwrite
95+ ) ;
10596 await decompressionManager . decompress ( archives ) ;
106- console . error ( " Reindexing files..." )
97+ console . error ( ' Reindexing files...' ) ;
10798 tree . build ( ) ;
108- } else console . error ( " No archives found." ) ;
99+ } else console . error ( ' No archives found.' ) ;
109100 }
110- scannerInput . fileList = tree . getFileList ( new ScanFilter ( "" ) ) ;
111- dependencyInput = tree . getFileList ( new DependencyFilter ( "" ) ) ;
101+ scannerInput . fileList = tree . getFileList ( new ScanFilter ( '' ) ) ;
102+ dependencyInput = tree . getFileList ( new DependencyFilter ( '' ) ) ;
112103 } else {
113104 scannerInput . fileList = [ rootPath ] ;
114105 dependencyInput = [ rootPath ] ;
115106 }
116107 } else {
117- const winnowing = fs . readFileSync ( rootPath , { encoding : 'utf-8' } ) ;
108+ const winnowing = fs . readFileSync ( rootPath , { encoding : 'utf-8' } ) ;
118109 scannerInput . fileList . length = [ ...winnowing . matchAll ( / f i l e = / g) ] . length ;
119110 }
120111
121112 if ( ! options . verbose ) {
122- const optBar1 = { format : 'Scan Progress: [{bar}] {percentage}% | Scanned {value} files of {total}' } ;
123- const bar1 = new cliProgress . SingleBar ( optBar1 , cliProgress . Presets . shades_classic ) ;
113+ const optBar1 = {
114+ format :
115+ 'Scan Progress: [{bar}] {percentage}% | Scanned {value} files of {total}' ,
116+ } ;
117+ const bar1 = new cliProgress . SingleBar (
118+ optBar1 ,
119+ cliProgress . Presets . shades_classic
120+ ) ;
124121 bar1 . start ( scannerInput . fileList . length , 0 ) ;
125122
126- scanner . on ( ScannerEvents . DISPATCHER_NEW_DATA , ( dispResp : DispatcherResponse ) => {
127- bar1 . increment ( dispResp . getFilesScanned ( ) . length ) ;
128- } ) ;
123+ scanner . on (
124+ ScannerEvents . DISPATCHER_NEW_DATA ,
125+ ( dispResp : DispatcherResponse ) => {
126+ bar1 . increment ( dispResp . getFilesScanned ( ) . length ) ;
127+ }
128+ ) ;
129129
130- scanner . on ( ScannerEvents . SCAN_DONE , async ( resultPath ) => { bar1 . stop ( ) ; } ) ;
130+ scanner . on ( ScannerEvents . SCAN_DONE , async ( resultPath ) => {
131+ bar1 . stop ( ) ;
132+ } ) ;
131133 } else {
132134 scanner . on ( ScannerEvents . SCANNER_LOG , ( logText ) => console . error ( logText ) ) ;
133135 }
134136
135-
136137 if ( options . ignore ) {
137138 scannerInput . sbom = fs . readFileSync ( options . ignore , 'utf-8' ) ;
138- scannerInput . sbomMode = SbomMode . SBOM_IGNORE
139+ scannerInput . sbomMode = SbomMode . SBOM_IGNORE ;
139140 }
140141
141-
142-
143142 // Dependency scanner
144143 let pDependencyScanner = Promise . resolve ( < IDependencyResponse > { } ) ;
145144 if ( options . dependencies ) {
@@ -149,33 +148,47 @@ export async function scanHandler(rootPath: string, options: any): Promise<void>
149148 //Launch parallel scanners
150149 const pScanner = scanner . scan ( [ scannerInput ] ) ;
151150
152- const [ scannerResultPath , depResults ] = await Promise . all ( [ pScanner , pDependencyScanner ] )
153- const scannerResults = JSON . parse ( await fs . promises . readFile ( scannerResultPath , 'utf-8' ) ) ;
151+ const [ scannerResultPath , depResults ] = await Promise . all ( [
152+ pScanner ,
153+ pDependencyScanner ,
154+ ] ) ;
155+ const scannerResults = JSON . parse (
156+ await fs . promises . readFile ( scannerResultPath , 'utf-8' )
157+ ) ;
154158
155159 //TODO Unify results.json and dependency.json. What happens with result.json that includes dependencies?
156160 const scannersResults = {
157161 scanner : scannerResults as ScannerResults ,
158- ...( options . dependencies && { dependencies : depResults } )
162+ ...( options . dependencies && { dependencies : depResults } ) ,
159163 } ;
160164
161165 let scannerResultsString = JSON . stringify ( scannersResults , null , 2 ) ;
162166
163- if ( options . format && options . format . toLowerCase ( ) === "html" ) {
164-
167+ if ( options . format && options . format . toLowerCase ( ) === 'html' ) {
165168 const dataProviderManager = new DataProviderManager ( ) ;
166- dataProviderManager . addDataProvider ( new ComponentDataProvider ( scannersResults . scanner , scannersResults . dependencies ) )
167- dataProviderManager . addDataProvider ( new DependencyDataProvider ( scannersResults . dependencies ) )
168- dataProviderManager . addDataProvider ( new LicenseDataProvider ( scannersResults . scanner , scannersResults . dependencies ) ) ;
169- dataProviderManager . addDataProvider ( new SummaryDataProvider ( projectName , new Date ( ) , scannersResults . scanner ) ) ;
169+ dataProviderManager . addDataProvider (
170+ new ComponentDataProvider (
171+ scannersResults . scanner ,
172+ scannersResults . dependencies
173+ )
174+ ) ;
175+ dataProviderManager . addDataProvider (
176+ new DependencyDataProvider ( scannersResults . dependencies )
177+ ) ;
178+ dataProviderManager . addDataProvider (
179+ new LicenseDataProvider (
180+ scannersResults . scanner ,
181+ scannersResults . dependencies
182+ )
183+ ) ;
184+ dataProviderManager . addDataProvider (
185+ new SummaryDataProvider ( projectName , new Date ( ) , scannersResults . scanner )
186+ ) ;
170187 const report = new Report ( dataProviderManager ) ;
171188 scannerResultsString = await report . getHTML ( ) ;
172-
173189 }
174190
175- if ( options . output )
176- await fs . promises . writeFile ( options . output , scannerResultsString )
177- else
178- console . log ( scannerResultsString ) ;
191+ if ( options . output )
192+ await fs . promises . writeFile ( options . output , scannerResultsString ) ;
193+ else console . log ( scannerResultsString ) ;
179194}
180-
181-
0 commit comments