Skip to content

Commit

Permalink
Update scan status on start #728
Browse files Browse the repository at this point in the history
  • Loading branch information
noboruma committed Dec 19, 2022
1 parent 41f96f9 commit 7cd9740
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions deepfence_server/handler/scan_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func (h *Handler) StartSecretScanHandler(w http.ResponseWriter, r *http.Request)
return
}

err = ingesters.UpdateScanStatus(r.Context(), "SecretScan", scanId, "STARTING")
if err != nil {
httpext.JSON(w, http.StatusInternalServerError, model.Response{Success: false, Data: err})
return
}

startScan(w, r, scanId, req.NodeId, ctl.StartSecretScan, string(b))
}

Expand Down
36 changes: 36 additions & 0 deletions deepfence_server/ingesters/scan_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ingesters

import (
"context"

"github.com/deepfence/ThreatMapper/deepfence_utils/directory"
"github.com/neo4j/neo4j-go-driver/v4/neo4j"
)

func UpdateScanStatus(ctx context.Context, scan_type string, scan_id string, status string) error {

driver, err := directory.Neo4jClient(ctx)

if err != nil {
return err
}

session := driver.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeWrite})
if err != nil {
return err
}
defer session.Close()

tx, err := session.BeginTransaction()
if err != nil {
return err
}
defer tx.Close()

if _, err = tx.Run("MERGE (n:$scan_type{node_id: $scan_id}) SET n.status = $status",
map[string]interface{}{"scan_id": scan_id, "status": status, "scan_type": scan_type}); err != nil {
return err
}

return tx.Commit()
}

0 comments on commit 7cd9740

Please sign in to comment.