Skip to content

Commit 1064fe2

Browse files
committed
feat: add scan warnings in scan result
1 parent b6de59c commit 1064fe2

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

cmd/murphy/internal/binscan/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func binScan(ctx context.Context, scanPath string) error {
152152
}
153153
cv.DisplayReportUrl(ctx, *result)
154154
cv.DisplayStatusClear(ctx)
155-
cv.DisplayScanResultSummary(ctx, result.RelyNum, result.LeakNum, len(result.VulnInfoMap))
155+
cv.DisplayScanResultSummary(ctx, result.RelyNum, result.LeakNum, len(result.VulnInfoMap), result.ScanWarnings)
156156

157157
return nil
158158
}

cmd/murphy/internal/cv/view.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"github.com/muesli/termenv"
77
"github.com/murphysecurity/murphysec/infra/ui"
88
"github.com/murphysecurity/murphysec/model"
9+
"github.com/repeale/fp-go"
10+
"github.com/samber/lo"
911
"strconv"
12+
"strings"
1013
)
1114

1215
func DisplayInitializeFailed(ctx context.Context, e error) {
@@ -94,9 +97,12 @@ func DisplayStatusClear(ctx context.Context) {
9497
ui.Use(ctx).ClearStatus()
9598
}
9699

97-
func DisplayScanResultSummary(ctx context.Context, totalDep int, totalVulnDep int, totalVuln int) {
100+
func DisplayScanResultSummary(ctx context.Context, totalDep int, totalVulnDep int, totalVuln int, warnings []model.ScanWarning) {
98101
var u = ui.Use(ctx)
99102
u.Display(ui.MsgNotice, fmt.Sprint("项目扫描完成,依赖数:", ui.Term.String(strconv.Itoa(totalDep)).Foreground(termenv.ANSIBrightCyan), ",缺陷组件数:", ui.Term.String(strconv.Itoa(totalVulnDep)).Foreground(termenv.ANSIBrightRed), ",漏洞数", ui.Term.String(strconv.Itoa(totalVuln)).Foreground(termenv.ANSIBrightRed)))
103+
if len(warnings) > 0 {
104+
u.Display(ui.MsgNotice, "扫描过程中出现了一些警告:"+strings.Join(lo.Uniq(fp.Map(func(it model.ScanWarning) string { return it.Kind })(warnings)), ", "))
105+
}
100106
}
101107
func DisplayUploading(ctx context.Context) {
102108
ui.Use(ctx).UpdateStatus(ui.StatusRunning, "正在上传...")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cv
2+
3+
import (
4+
"context"
5+
"github.com/murphysecurity/murphysec/infra/ui"
6+
"github.com/murphysecurity/murphysec/model"
7+
"testing"
8+
)
9+
10+
func TestDisplayScanResultSummary(t *testing.T) {
11+
var ctx = ui.With(context.TODO(), ui.CLI)
12+
DisplayScanResultSummary(ctx, 10, 5, 3, []model.ScanWarning{{Kind: "test_foo"}, {Kind: "bar"}})
13+
}

cmd/murphy/internal/scan/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func postScanHook(ctx context.Context) (a any, e error) {
116116
}
117117
cv.DisplayReportUrl(ctx, *result)
118118
cv.DisplayStatusClear(ctx)
119-
cv.DisplayScanResultSummary(ctx, result.RelyNum, result.LeakNum, len(result.VulnInfoMap))
119+
cv.DisplayScanResultSummary(ctx, result.RelyNum, result.LeakNum, len(result.VulnInfoMap), result.ScanWarnings)
120120
return
121121
}
122122

model/idea_output.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"github.com/murphysecurity/fix-tools/fix"
66
"github.com/murphysecurity/murphysec/utils"
7+
"github.com/repeale/fp-go"
8+
"github.com/samber/lo"
79
"time"
810
)
911

@@ -34,6 +36,11 @@ type PluginOutput struct {
3436
HitProjectRule json.RawMessage `json:"hit_project_rule,omitempty"`
3537
ShareURL string `json:"share_url,omitempty"`
3638
DetailURL string `json:"detail_url,omitempty"`
39+
ScanWarningCodes []string `json:"scan_warning_codes,omitempty"`
40+
}
41+
42+
type ScanWarning struct {
43+
Kind string
3744
}
3845

3946
type PluginComp struct {
@@ -107,6 +114,7 @@ func GetIDEAOutput(task *ScanTask) PluginOutput {
107114
HitProjectRule: r.HitProjectRule,
108115
ShareURL: r.ShareURL,
109116
DetailURL: r.DetailURL,
117+
ScanWarningCodes: lo.Uniq(fp.Map(func(it ScanWarning) string { return it.Kind })(r.ScanWarnings)),
110118
}
111119

112120
var vulnListMapper = func(effects []ScanResultCompEffect) (rs []PluginVulnDetailInfo) {

model/result.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ScanResultResponse struct {
3737
DetailURL string `json:"detail_url"`
3838
AllowAction int `json:"allow_action"`
3939
ExpireDay int `json:"expire_day"`
40+
ScanWarnings []ScanWarning `json:"scan_warnings"`
4041
}
4142

4243
type ScanResultCompInfo struct {

0 commit comments

Comments
 (0)