MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / Html

Function Html

cmd/format/html.go:30–95  ·  view source on GitHub ↗
(report Report, out string)

Source from the content-addressed store, hash-verified

28}
29
30func Html(report Report, out string) {
31
32 deps := []htmlDep{}
33 statis := htmlStatis{
34 Component: map[int]int{},
35 Vuln: map[int]int{},
36 }
37 vulnMap := map[string]int{}
38
39 // 遍历所有组件
40 report.DepDetailGraph.ForEach(func(n *detail.DepDetailGraph) bool {
41
42 // 组件风险
43 secid := 5
44 // 不同风险等级的漏洞数
45 vuln_statis := map[int]int{}
46 for _, v := range n.Vulnerabilities {
47 vulnMap[v.Id] = v.SecurityLevelId
48 vuln_statis[v.SecurityLevelId]++
49 if secid > v.SecurityLevelId {
50 secid = v.SecurityLevelId
51 }
52 }
53
54 if n.Name != "" {
55 statis.Component[secid]++
56 deps = append(deps, htmlDep{
57 DepDetailGraph: n,
58 Children: nil,
59 SecId: secid,
60 Statis: vuln_statis,
61 })
62 }
63
64 return true
65 })
66
67 // 统计漏洞风险
68 for _, secid := range vulnMap {
69 statis.Vuln[secid]++
70 }
71
72 // report依赖信息临时置空用于生成html报告
73 graph := report.DepDetailGraph
74 report.DepDetailGraph = nil
75 defer func() { report.DepDetailGraph = graph }()
76
77 // 生成html报告需要的json数据
78 if data, err := json.Marshal(struct {
79 TaskInfo TaskInfo `json:"task_info"`
80 Statis htmlStatis `json:"statis"`
81 Components []htmlDep `json:"components"`
82 }{
83 TaskInfo: report.TaskInfo,
84 Statis: statis,
85 Components: deps,
86 }); err != nil {
87 logs.Warn(err)

Callers 1

SaveFunction · 0.85

Calls 5

WarnFunction · 0.92
outWriteFunction · 0.85
WriteMethod · 0.80
ReplaceMethod · 0.80
ForEachMethod · 0.45

Tested by

no test coverage detected