-
Notifications
You must be signed in to change notification settings - Fork 80
/
report.go
84 lines (74 loc) · 1.69 KB
/
report.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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Authors of KubeArmor
package report
import (
"errors"
"strings"
"github.com/kubearmor/kubearmor-client/recommend/common"
"github.com/kubearmor/kubearmor-client/recommend/image"
)
/*
Init()
for every image {
Start()
for every policy {
Record()
}
SectEnd()
}
Render()
*/
// Handler interface
var Handler interface{}
// Init called once per execution
func Init(fname string) {
if Handler != nil {
return
}
if strings.Contains(fname, ".html") {
Handler = NewHTMLReport()
} else {
Handler = NewTextReport()
}
}
// Start called once per container image at the start
func Start(img *image.Info, options common.Options, currentVersion string) error {
switch v := Handler.(type) {
case HTMLReport:
return v.Start(img, options.OutDir, currentVersion)
case TextReport:
return v.Start(img, options.OutDir, currentVersion)
}
return errors.New("unknown reporter type")
}
// Record called once per policy
func Record(in interface{}, policyName string) error {
ms := in.(common.MatchSpec)
switch v := Handler.(type) {
case HTMLReport:
return v.Record(ms, policyName)
case TextReport:
return v.Record(ms, policyName)
}
return errors.New("unknown reporter type")
}
// SectEnd called once per container image at the end
func SectEnd() error {
switch v := Handler.(type) {
case HTMLReport:
return v.SectionEnd()
case TextReport:
return v.SectionEnd()
}
return errors.New("unknown reporter type")
}
// Render called finaly to render the report
func Render(out string) error {
switch v := Handler.(type) {
case HTMLReport:
return v.Render(out)
case TextReport:
return v.Render(out)
}
return errors.New("unknown reporter type")
}