diff --git a/cmd/format/save.go b/cmd/format/save.go index 6ace8ed73a434b0424a16931e80b67123e9d25c1..f6bb44886a3971d9c3dc171713dd36f88a2ac1bc 100644 --- a/cmd/format/save.go +++ b/cmd/format/save.go @@ -7,6 +7,7 @@ import ( "path/filepath" "strings" + "github.com/xmirrorsecurity/opensca-cli/v3/cmd/config" "github.com/xmirrorsecurity/opensca-cli/v3/cmd/detail" "github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs" ) @@ -37,7 +38,7 @@ func Save(report Report, output string) { logs.Infof("result save to %s", out) switch filepath.Ext(out) { case ".html": - Html(report, out) + Html(genReport(report), out) case ".json": if strings.HasSuffix(out, ".spdx.json") { SpdxJson(report, out) @@ -48,7 +49,7 @@ func Save(report Report, output string) { } else if strings.HasSuffix(out, ".swid.json") { SwidJson(report, out) } else { - Json(report, out) + Json(genReport(report), out) } case ".dsdx": Dsdx(report, out) @@ -73,11 +74,30 @@ func Save(report Report, output string) { case ".sarif": Sarif(report, out) default: - Json(report, out) + Json(genReport(report), out) } } } +func genReport(report Report) Report { + optional := config.Conf().Optional + var newReport = report + if optional.VulnOnly { + var deps []*detail.DepDetailGraph + report.DepDetailGraph.ForEach(func(n *detail.DepDetailGraph) bool { + if len(n.Vulnerabilities) > 0 { + deps = append(deps, n) + } + return true + }) + for _, d := range deps { + d.Children = nil + } + newReport.DepDetailGraph = &detail.DepDetailGraph{Children: deps} + } + return newReport +} + func outWrite(out string, do func(io.Writer) error) { if out == "" { diff --git a/main.go b/main.go index 1457e730d47cdcca3d32558f5c00728563f1625f..a5da5527fefdb3e1e637751dd1c07321c478d0c2 100644 --- a/main.go +++ b/main.go @@ -249,7 +249,7 @@ func taskReport(r opensca.TaskResult) format.Report { } // 仅保留漏洞组件 - if optional.VulnOnly { + /*if optional.VulnOnly { var deps []*detail.DepDetailGraph report.ForEach(func(n *detail.DepDetailGraph) bool { if len(n.Vulnerabilities) > 0 { @@ -261,7 +261,7 @@ func taskReport(r opensca.TaskResult) format.Report { d.Children = nil } report.DepDetailGraph = &detail.DepDetailGraph{Children: deps} - } + }*/ end := time.Now() report.TaskInfo.StartTime = r.Start.Format("2006-01-02 15:04:05")