-
Notifications
You must be signed in to change notification settings - Fork 0
/
html-template.go
176 lines (165 loc) · 5.46 KB
/
html-template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"os"
"sort"
"gopkg.in/yaml.v2"
)
var tmplStr = `
<!DOCTYPE html>
<html>
<head>
<title>O-RAN Risk Assessment</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
.accordion {
width: 100%;
max-width: 1000px;
margin: 0 auto;
}
details {
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
summary {
padding: 15px;
background-color: #f8f9fa;
cursor: pointer;
font-weight: bold;
border-radius: 8px 8px 0 0;
}
summary:hover {
background-color: #e9ecef;
}
.content {
padding: 20px;
line-height: 1.6;
}
.severity-High {
color: #dc3545;
font-weight: bold;
}
h4 {
color: #495057;
margin-top: 15px;
margin-bottom: 10px;
}
.checkpoint {
background-color: #f8f9fa;
padding: 10px;
margin: 5px 0;
border-radius: 4px;
}
.risk-section {
border-left: 4px solid #007bff;
margin: 10px 0;
padding: 10px;
background-color: #f8f9fa;
}
.checkpoint .status {
margin-right: 10px;
}
.status-pass {
color: #28a745;
}
.status-fail {
color: #dc3545;
}
</style>
</head>
<body>
<div class="accordion">
{{range .}}
<details>
<summary>{{.WorkloadName}}</summary>
<div class="content">
{{range .Risks}}
<div class="risk-section">
<p><strong>Risk ID:</strong> {{.RiskID}}</p>
<p><strong>Risk Description:</strong> {{.RiskDescription}}</p>
<p><strong>Severity:</strong> <span class="severity-{{.Severity}}">{{.Severity}}</span></p>
<h4>Checkpoints:</h4>
{{with .Checkpoints.CHK_TLS}}
<div class="checkpoint">
<strong>TLS Check:</strong>
{{ with index . 0 }}
<div>
<span class="status {{if .Status }}status-pass{{else}}status-fail{{end}}">
{{if .Status }}✓{{else}}✗{{end}}
</span>
{{.Description}}
</div>
{{end}}
</div>
{{end}}
{{with .Checkpoints.CHK_POLP_EGRESS}}
<div class="checkpoint">
<strong>Egress Policy Check:</strong>
{{ with index . 0 }}
<div>
<span class="status {{if .Status }}status-pass{{else}}status-fail{{end}}">
{{if .Status }}✓{{else}}✗{{end}}
</span>
{{.Description}}
</div>
{{end}}
</div>
{{end}}
{{with .Checkpoints.CHK_SENSITIVE_ASSETS}}
<div class="checkpoint">
<strong>Sensitive Assets Check:</strong>
{{ with index . 0 }}
<div>
<span class="status {{if .Status }}status-pass{{else}}status-fail{{end}}">
{{if .Status }}✓{{else}}✗{{end}}
</span>
{{.Description}}
</div>
{{end}}
</div>
{{end}}
</div>
{{end}}
</div>
</details>
{{end}}
</div>
</body>
</html>`
func loadRisks(filename string) ([]Risk, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var risks []Risk
err = yaml.Unmarshal(data, &risks)
if err != nil {
return nil, err
}
return risks, nil
}
func groupRisksByWorkload(risks []Risk) []WorkloadRisks {
workloadMap := make(map[string][]Risk)
for _, risk := range risks {
for _, workload := range risk.Workload {
workloadMap[workload] = append(workloadMap[workload], risk)
}
}
var result []WorkloadRisks
for workload, risks := range workloadMap {
result = append(result, WorkloadRisks{
WorkloadName: workload,
Risks: risks,
})
}
sort.Slice(result, func(i, j int) bool {
return result[i].WorkloadName < result[j].WorkloadName
})
return result
}