Skip to content

Commit cf79db1

Browse files
Merge pull request XmirrorSecurity#277 from yutons/master
调整仅保留漏洞组件生效范围
2 parents 4385230 + 7b6621a commit cf79db1

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

cmd/format/save.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1011
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/detail"
1112
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
1213
)
@@ -37,7 +38,7 @@ func Save(report Report, output string) {
3738
logs.Infof("result save to %s", out)
3839
switch filepath.Ext(out) {
3940
case ".html":
40-
Html(report, out)
41+
Html(genReport(report), out)
4142
case ".json":
4243
if strings.HasSuffix(out, ".spdx.json") {
4344
SpdxJson(report, out)
@@ -48,7 +49,7 @@ func Save(report Report, output string) {
4849
} else if strings.HasSuffix(out, ".swid.json") {
4950
SwidJson(report, out)
5051
} else {
51-
Json(report, out)
52+
Json(genReport(report), out)
5253
}
5354
case ".dsdx":
5455
Dsdx(report, out)
@@ -73,11 +74,30 @@ func Save(report Report, output string) {
7374
case ".sarif":
7475
Sarif(report, out)
7576
default:
76-
Json(report, out)
77+
Json(genReport(report), out)
7778
}
7879
}
7980
}
8081

82+
func genReport(report Report) Report {
83+
optional := config.Conf().Optional
84+
var newReport = report
85+
if optional.VulnOnly {
86+
var deps []*detail.DepDetailGraph
87+
report.DepDetailGraph.ForEach(func(n *detail.DepDetailGraph) bool {
88+
if len(n.Vulnerabilities) > 0 {
89+
deps = append(deps, n)
90+
}
91+
return true
92+
})
93+
for _, d := range deps {
94+
d.Children = nil
95+
}
96+
newReport.DepDetailGraph = &detail.DepDetailGraph{Children: deps}
97+
}
98+
return newReport
99+
}
100+
81101
func outWrite(out string, do func(io.Writer) error) {
82102

83103
if out == "" {

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func args() {
126126

127127
logs.CreateLog(config.Conf().LogFile)
128128

129-
logs.Infof("opensca-cli version: %s", version)
129+
logs.Infof("nsca-xcheck-cli version: %s", version)
130130
logs.Infof("use config: %s", cfgf)
131131

132132
if login {
@@ -253,7 +253,7 @@ func taskReport(r opensca.TaskResult) format.Report {
253253
}
254254

255255
// 仅保留漏洞组件
256-
if optional.VulnOnly {
256+
/*if optional.VulnOnly {
257257
logs.Info("remove no-vuln component")
258258
var deps []*detail.DepDetailGraph
259259
report.ForEach(func(n *detail.DepDetailGraph) bool {
@@ -266,7 +266,7 @@ func taskReport(r opensca.TaskResult) format.Report {
266266
d.Children = nil
267267
}
268268
report.DepDetailGraph = &detail.DepDetailGraph{Children: deps}
269-
}
269+
}*/
270270

271271
end := time.Now()
272272
report.TaskInfo.StartTime = r.Start.Format("2006-01-02 15:04:05")

0 commit comments

Comments
 (0)