From dc71c8c0dee3450af9bed15044783310ffe720dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E5=BB=BA=E5=BA=B7?= Date: Mon, 5 Feb 2024 11:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=85=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=BC=8F=E6=B4=9E=E7=BB=84=E4=BB=B6=E7=94=9F=E6=95=88=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E4=B8=BA=E8=B7=9F=E6=BC=8F=E6=B4=9E=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84html=E5=92=8Cjson=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=A3=80=E6=B5=8B=E6=8A=A5=E5=91=8A=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BB=A5=E5=8F=8ASBOM=E6=B8=85=E5=8D=95=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E5=AE=8C=E6=95=B4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/format/save.go | 26 +++++++++++++++++++++++--- main.go | 4 ++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cmd/format/save.go b/cmd/format/save.go index 6ace8ed..f6bb448 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 1457e73..a5da552 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") -- Gitee