Skip to content

Commit

Permalink
Support order filter in scans list api
Browse files Browse the repository at this point in the history
  • Loading branch information
ramanan-ravi committed Jul 30, 2024
1 parent 0a8ce41 commit 6ea4a4f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions deepfence_server/reporters/scan/scan_reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ func GetScansList(ctx context.Context, scanType utils.Neo4jScanType, nodeIDs []m
}
defer tx.Close(ctx)

var orderFilter string
if len(ff.OrderFilter.OrderFields) > 0 {
orderFilter = reporters.OrderFilter2CypherCondition("m", ff.OrderFilter, []string{"n"})
} else {
orderFilter = "WITH n,m ORDER BY m.updated_at"
}
var scansInfo []model.ScanInfo
var query string
var nodeIDsStr []string
Expand All @@ -535,14 +541,16 @@ func GetScansList(ctx context.Context, scanType utils.Neo4jScanType, nodeIDs []m
WHERE n.node_id IN $node_ids
AND (` + strings.Join(nodeTypesStr, " OR ") + `)
` + reporters.ParseFieldFilters2CypherWhereConditions("m", mo.Some(ff), false) + `
` + orderFilter + `
RETURN m.node_id, m.status, m.status_message, m.created_at, m.updated_at, n.node_id, n.node_name, labels(n) as node_type
ORDER BY m.updated_at ` + fw.FetchWindow2CypherQuery()
` + fw.FetchWindow2CypherQuery()
} else {
query = `
MATCH (m:` + string(scanType) + `) -[:SCANNED]-> (n)
` + reporters.ParseFieldFilters2CypherWhereConditions("m", mo.Some(ff), true) + `
` + orderFilter + `
RETURN m.node_id, m.status, m.status_message, m.created_at, m.updated_at, n.node_id, n.node_name, labels(n) as node_type
ORDER BY m.updated_at ` + fw.FetchWindow2CypherQuery()
` + fw.FetchWindow2CypherQuery()
}
scansInfo, err = processScansListQuery(ctx, query, nodeIDsStr, tx)
if err != nil {
Expand Down

0 comments on commit 6ea4a4f

Please sign in to comment.