@@ -29,7 +29,7 @@ const dataCheckInterval = 1.0
29
29
30
30
const rpcTimeout = time .Minute * 20
31
31
const expirationTime = time .Minute * 25
32
- const pruneTime = time .Minute * 5
32
+ const pruneTime = time .Minute * 60
33
33
34
34
var workloadID Counter
35
35
var concurrentJobs Counter
@@ -57,10 +57,13 @@ func InitializeServer(config *config.ServerConfig) {
57
57
defer http .DefaultClient .CloseIdleConnections ()
58
58
_ , err := GetControllerServiceClient (serverConfig .ControllerIP , serverConfig .ControllerPort )
59
59
if err != nil {
60
- log .WithFields (log.Fields {"error" : err }).Error ("Error retrieving rpc client" )
60
+ log .WithFields (log.Fields {"error" : err }).Error ("Error establishing grpc connection to controller" )
61
+ return
62
+ }
63
+ for nvScanner .Version == "" {
64
+ time .Sleep (time .Second * 3 )
65
+ pollMaxConcurrent ()
61
66
}
62
- time .Sleep (time .Second * 3 )
63
- pollMaxConcurrent ()
64
67
http .HandleFunc ("/" , unhandled )
65
68
http .HandleFunc (metadataEndpoint , authenticateHarbor (metadata ))
66
69
http .HandleFunc (scanEndpoint , authenticateHarbor (scan ))
@@ -195,7 +198,8 @@ func scan(w http.ResponseWriter, req *http.Request) {
195
198
workloadID .Unlock ()
196
199
197
200
reportCache .Lock ()
198
- reportCache .ScanReports [scanId .ID ] = ScanReport {Status : http .StatusFound , ExpirationTime : generateExpirationTime ()}
201
+ expirationTime := generateExpirationTime ()
202
+ reportCache .ScanReports [scanId .ID ] = ScanReport {Status : http .StatusFound , ExpirationTime : expirationTime }
199
203
reportCache .Unlock ()
200
204
201
205
err = json .NewEncoder (w ).Encode (scanId )
@@ -246,8 +250,10 @@ func processScanTask(scanRequest ScanRequest) {
246
250
reportCache .Lock ()
247
251
report := reportCache .ScanReports [scanRequest .WorkloadID ]
248
252
report .Status = http .StatusInternalServerError
253
+ reportCache .ScanReports [scanRequest .WorkloadID ] = report
249
254
reportCache .Unlock ()
250
- log .WithFields (log.Fields {"error" : err }).Error ("Error retrieving rpc client" )
255
+ log .WithFields (log.Fields {"error" : err }).Error ("Error establishing grpc connection to controller" )
256
+ concurrentJobs .Decrement ()
251
257
return
252
258
}
253
259
request := share.AdapterScanImageRequest {
@@ -259,27 +265,27 @@ func processScanTask(scanRequest ScanRequest) {
259
265
}
260
266
ctx , cancel := context .WithTimeout (context .Background (), rpcTimeout )
261
267
defer cancel ()
268
+ log .WithFields (log.Fields {"workloadId" : scanRequest .WorkloadID , "artifact" : scanRequest .Artifact , "registry" : scanRequest .Registry }).Debug ("Scan request forwarded to controller" )
262
269
result , err := client .ScanImage (ctx , & request )
263
270
if err != nil {
264
271
reportCache .Lock ()
265
272
report := reportCache .ScanReports [scanRequest .WorkloadID ]
266
273
report .Status = http .StatusInternalServerError
274
+ reportCache .ScanReports [scanRequest .WorkloadID ] = report
267
275
reportCache .Unlock ()
268
276
log .WithFields (log.Fields {"error" : err }).Error ("Error sending scan request" )
277
+ concurrentJobs .Decrement ()
269
278
return
270
279
}
271
280
concurrentJobs .Decrement ()
272
-
273
281
reportCache .Lock ()
274
- log .WithFields (log.Fields {"workloadId" : scanRequest .WorkloadID , "artifact" : scanRequest .Artifact , "registry" : scanRequest .Registry }).Debug ("Scan request forwarded to controller" )
275
282
reportCache .ScanReports [scanRequest .WorkloadID ] = convertRPCReportToScanReport (result )
276
283
reportCache .Unlock ()
277
284
}
278
285
279
286
//convertRPCReportToScanReport converts the rpc results from the controller into a Harbor readable format.
280
287
func convertRPCReportToScanReport (scanResult * share.ScanResult ) ScanReport {
281
288
var result ScanReport
282
- //TODO: Finish conversion/translation of Results
283
289
result .Status = http .StatusOK
284
290
result .Vulnerabilities = convertVulns (scanResult .Vuls )
285
291
return result
@@ -315,7 +321,7 @@ func convertVulns(controllerVulns []*share.ScanVulnerability) []Vuln {
315
321
func pollMaxConcurrent () (uint32 , error ) {
316
322
client , err := GetControllerServiceClient (serverConfig .ControllerIP , serverConfig .ControllerPort )
317
323
if err != nil {
318
- log .WithFields (log.Fields {"error" : err }).Error ("Error retrieving rpc client " )
324
+ log .WithFields (log.Fields {"error" : err }).Error ("Error establishing grpc connection to controller " )
319
325
return 0 , err
320
326
}
321
327
@@ -390,7 +396,7 @@ func scanResult(w http.ResponseWriter, req *http.Request) {
390
396
delete (reportCache .ScanReports , id )
391
397
case http .StatusInternalServerError :
392
398
log .WithFields (log.Fields {"id" : id }).Debug ("returned http 500 for workload id" )
393
- http . Error ( w , "NV Internal Server Error" , http .StatusInternalServerError )
399
+ w . WriteHeader ( http .StatusInternalServerError )
394
400
delete (reportCache .ScanReports , id )
395
401
default :
396
402
w .Header ().Add ("Location" , req .URL .String ())
0 commit comments