Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support order filter in scans list api #2281

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading