Skip to content

Commit

Permalink
Merge pull request #13 from Acmarr/main
Browse files Browse the repository at this point in the history
NVSHAS-8116 fixed an issue that could cause incorrect report pruning.
  • Loading branch information
becitsthere authored Jul 10, 2023
2 parents dd02397 + dff1d9b commit c0adfd9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func scan(w http.ResponseWriter, req *http.Request) {
}
scanRequest.Authorization = req.Header.Get("Authorization")

log.WithFields(log.Fields{"auth": scanRequest.Authorization, "registry": scanRequest.Registry, "artifact": scanRequest.Artifact}).Debug("Scan request received")
//Add to resultmap with wait http code
w.WriteHeader(http.StatusAccepted)

Expand All @@ -193,13 +192,15 @@ func scan(w http.ResponseWriter, req *http.Request) {
scanId := ScanRequestReturn{ID: fmt.Sprintf("%v", workloadID.GetNoLock())}
scanRequest.WorkloadID = scanId.ID
scanRequestQueue.Enqueue(scanRequest)
log.WithFields(log.Fields{"workloadid": scanId, "auth": scanRequest.Authorization, "registry": scanRequest.Registry, "artifact": scanRequest.Artifact}).Debug("Scan request received")
workloadID.Increment()
scanRequestQueue.Unlock()
workloadID.Unlock()

reportCache.Lock()
expirationTime := generateExpirationTime()
reportCache.ScanReports[scanId.ID] = ScanReport{Status: http.StatusFound, ExpirationTime: expirationTime}
ScanReport := ScanReport{Status: http.StatusFound, ExpirationTime: expirationTime}
reportCache.ScanReports[scanId.ID] = ScanReport
reportCache.Unlock()

err = json.NewEncoder(w).Encode(scanId)
Expand Down Expand Up @@ -350,7 +351,7 @@ func pruneOldEntries() {
for key, value := range reportCache.ScanReports {
if value.ExpirationTime.Before(time.Now()) {
delete(reportCache.ScanReports, key)
log.WithFields(log.Fields{"key": key, "expires": value.ExpirationTime, "now": time.Now()}).Debug("Deleted entry due to expiration time")
log.WithFields(log.Fields{"workloadid": key, "expires": value.ExpirationTime, "now": time.Now()}).Debug("Deleted entry due to expiration time")
}
}
reportCache.Unlock()
Expand Down Expand Up @@ -404,6 +405,7 @@ func scanResult(w http.ResponseWriter, req *http.Request) {
}
} else {
w.Header().Add("Location", req.URL.String())
log.WithFields(log.Fields{"id": id}).Debug("Entry not found for scan report")
w.WriteHeader(http.StatusNotFound)
}
reportCache.Unlock()
Expand Down

0 comments on commit c0adfd9

Please sign in to comment.