@@ -86,7 +86,7 @@ func (s APIService) scanDirect(w http.ResponseWriter, r *http.Request, zs *zap.S
86
86
setSpanError (span , "No WFP contents supplied" )
87
87
return 0
88
88
}
89
- flags , scanType , sbom := s .getFlags (r , zs )
89
+ flags , scanType , sbom , dbName := s .getFlags (r , zs )
90
90
// Check if we have an SBOM (and type) supplied
91
91
var sbomFilename string
92
92
if len (sbom ) > 0 && len (scanType ) > 0 {
@@ -121,9 +121,9 @@ func (s APIService) scanDirect(w http.ResponseWriter, r *http.Request, zs *zap.S
121
121
s .countScanSize (wfps , wfpCount , zs , context , span )
122
122
// Only one worker selected, so send the whole WFP in a single command
123
123
if s .config .Scanning .Workers <= 1 {
124
- s .singleScan (string (contentsTrimmed ), flags , scanType , sbomFilename , zs , w )
124
+ s .singleScan (string (contentsTrimmed ), flags , scanType , sbomFilename , dbName , zs , w )
125
125
} else {
126
- s .scanThreaded (wfps , int (wfpCount ), flags , scanType , sbomFilename , zs , w , span )
126
+ s .scanThreaded (wfps , int (wfpCount ), flags , scanType , sbomFilename , dbName , zs , w , span )
127
127
}
128
128
return wfpCount
129
129
}
@@ -155,10 +155,11 @@ func (s APIService) countScanSize(wfps []string, wfpCount int64, zs *zap.Sugared
155
155
}
156
156
157
157
// getFlags extracts the form values from a request returns the flags, scan type, and sbom data if detected.
158
- func (s APIService ) getFlags (r * http.Request , zs * zap.SugaredLogger ) (string , string , string ) {
159
- flags := strings .TrimSpace (r .FormValue ("flags" )) // Check form for Scanning flags
160
- scanType := strings .TrimSpace (r .FormValue ("type" )) // Check form for SBOM type
161
- sbom := strings .TrimSpace (r .FormValue ("assets" )) // Check form for SBOM contents
158
+ func (s APIService ) getFlags (r * http.Request , zs * zap.SugaredLogger ) (string , string , string , string ) {
159
+ flags := strings .TrimSpace (r .FormValue ("flags" )) // Check form for Scanning flags
160
+ scanType := strings .TrimSpace (r .FormValue ("type" )) // Check form for SBOM type
161
+ sbom := strings .TrimSpace (r .FormValue ("assets" )) // Check form for SBOM contents
162
+ dbName := strings .TrimSpace (r .FormValue ("db_name" )) // Check form for db name
162
163
// TODO is it necessary to check the header also for these values?
163
164
if len (flags ) == 0 {
164
165
flags = strings .TrimSpace (r .Header .Get ("flags" )) // Check header for Scanning flags
@@ -169,10 +170,13 @@ func (s APIService) getFlags(r *http.Request, zs *zap.SugaredLogger) (string, st
169
170
if len (sbom ) == 0 {
170
171
sbom = strings .TrimSpace (r .Header .Get ("assets" )) // Check header for SBOM contents
171
172
}
173
+ if len (dbName ) == 0 {
174
+ dbName = strings .TrimSpace (r .Header .Get ("db_name" )) // Check header for SBOM contents
175
+ }
172
176
if s .config .App .Trace {
173
- zs .Debugf ("Header: %v, Form: %v, flags: %v, type: %v, assets: %v" , r .Header , r .Form , flags , scanType , sbom )
177
+ zs .Debugf ("Header: %v, Form: %v, flags: %v, type: %v, assets: %v, db_name %v " , r .Header , r .Form , flags , scanType , sbom , dbName )
174
178
}
175
- return flags , scanType , sbom
179
+ return flags , scanType , sbom , dbName
176
180
}
177
181
178
182
// writeSbomFile writes the given string into an SBOM temporary file.
@@ -192,9 +196,9 @@ func (s APIService) writeSbomFile(sbom string, zs *zap.SugaredLogger) (*os.File,
192
196
}
193
197
194
198
// singleScan runs a scan of the WFP in a single thread.
195
- func (s APIService ) singleScan (wfp , flags , sbomType , sbomFile string , zs * zap.SugaredLogger , w http.ResponseWriter ) {
199
+ func (s APIService ) singleScan (wfp , flags , sbomType , sbomFile , dbName string , zs * zap.SugaredLogger , w http.ResponseWriter ) {
196
200
zs .Debugf ("Single threaded scan..." )
197
- result , err := s .scanWfp (wfp , flags , sbomType , sbomFile , zs )
201
+ result , err := s .scanWfp (wfp , flags , sbomType , sbomFile , dbName , zs )
198
202
if err != nil {
199
203
zs .Errorf ("Engine scan failed: %v" , err )
200
204
http .Error (w , "ERROR engine scan failed" , http .StatusInternalServerError )
@@ -212,7 +216,7 @@ func (s APIService) singleScan(wfp, flags, sbomType, sbomFile string, zs *zap.Su
212
216
}
213
217
214
218
// scanThreaded scan the given WFPs in multiple threads.
215
- func (s APIService ) scanThreaded (wfps []string , wfpCount int , flags , sbomType , sbomFile string , zs * zap.SugaredLogger , w http.ResponseWriter , span oteltrace.Span ) {
219
+ func (s APIService ) scanThreaded (wfps []string , wfpCount int , flags , sbomType , sbomFile , dbName string , zs * zap.SugaredLogger , w http.ResponseWriter , span oteltrace.Span ) {
216
220
addSpanEvent (span , "Started Scanning." )
217
221
numWorkers := s .config .Scanning .Workers
218
222
groupedWfps := wfpCount / s .config .Scanning .WfpGrouping
@@ -229,7 +233,7 @@ func (s APIService) scanThreaded(wfps []string, wfpCount int, flags, sbomType, s
229
233
zs .Debugf ("Creating %v scanning workers..." , numWorkers )
230
234
// Create workers
231
235
for i := 1 ; i <= numWorkers ; i ++ {
232
- go s .workerScan (fmt .Sprintf ("%d_%s" , i , uuid .New ().String ()), requests , results , flags , sbomType , sbomFile , zs )
236
+ go s .workerScan (fmt .Sprintf ("%d_%s" , i , uuid .New ().String ()), requests , results , flags , sbomType , sbomFile , dbName , zs )
233
237
}
234
238
requestCount := 0 // Count the number of actual requests sent
235
239
var wfpRequests []string
@@ -304,7 +308,7 @@ func (s APIService) validateHPSM(contents []byte, zs *zap.SugaredLogger, w http.
304
308
}
305
309
306
310
// workerScan attempts to process all incoming scanning jobs and dumps the results into the subsequent results channel.
307
- func (s APIService ) workerScan (id string , jobs <- chan string , results chan <- string , flags , sbomType , sbomFile string , zs * zap.SugaredLogger ) {
311
+ func (s APIService ) workerScan (id string , jobs <- chan string , results chan <- string , flags , sbomType , sbomFile , dbName string , zs * zap.SugaredLogger ) {
308
312
if s .config .App .Trace {
309
313
zs .Debugf ("Starting up scanning worker: %v" , id )
310
314
}
@@ -318,7 +322,7 @@ func (s APIService) workerScan(id string, jobs <-chan string, results chan<- str
318
322
zs .Warnf ("Nothing in the job request to scan. Ignoring" )
319
323
results <- ""
320
324
} else {
321
- result , err := s .scanWfp (job , flags , sbomType , sbomFile , zs )
325
+ result , err := s .scanWfp (job , flags , sbomType , sbomFile , dbName , zs )
322
326
if s .config .App .Trace {
323
327
zs .Debugf ("scan result (%v): %v, %v" , id , result , err )
324
328
}
@@ -343,7 +347,7 @@ func (s APIService) workerScan(id string, jobs <-chan string, results chan<- str
343
347
}
344
348
345
349
// scanWfp run the scanoss engine scan of the supplied WFP.
346
- func (s APIService ) scanWfp (wfp , flags , sbomType , sbomFile string , zs * zap.SugaredLogger ) (string , error ) {
350
+ func (s APIService ) scanWfp (wfp , flags , sbomType , sbomFile , dbName string , zs * zap.SugaredLogger ) (string , error ) {
347
351
if len (wfp ) == 0 {
348
352
zs .Warnf ("Nothing in the job request to scan. Ignoring" )
349
353
return "" , fmt .Errorf ("no wfp supplied to scan. ignoring" )
@@ -367,6 +371,11 @@ func (s APIService) scanWfp(wfp, flags, sbomType, sbomFile string, zs *zap.Sugar
367
371
if s .config .Scanning .ScanDebug {
368
372
args = append (args , "-d" ) // Set debug mode
369
373
}
374
+ if len (dbName ) > 0 && dbName != "" { // we want to prefer request over the local config
375
+ args = append (args , fmt .Sprintf ("-n%s" , dbName ))
376
+ } else if s .config .Scanning .ScanKbName != "" { // Set scanning KB name
377
+ args = append (args , fmt .Sprintf ("-n%s" , s .config .Scanning .ScanKbName ))
378
+ }
370
379
if s .config .Scanning .ScanFlags > 0 { // Set system flags if enabled
371
380
args = append (args , fmt .Sprintf ("-F %v" , s .config .Scanning .ScanFlags ))
372
381
} else if len (flags ) > 0 && flags != "0" { // Set user supplied flags if enabled
0 commit comments