-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (65 loc) · 1.68 KB
/
main.go
File metadata and controls
71 lines (65 loc) · 1.68 KB
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
package main
import (
"encoding/json"
"flag"
"github.com/aquasecurity/trivy/pkg/log"
"github.com/aquasecurity/trivy/pkg/types"
"github.com/miao2sec/trivy-plugin-report/excel"
"github.com/miao2sec/trivy-plugin-report/markdown"
"os"
"strings"
)
func main() {
if err := run(); err != nil {
log.Fatal("failed to export excel file:%v", err)
}
}
func run() error {
// First we read Stdin to avoid Trivy freezing if we get an error
var report types.Report
log.InitLogger(false, false)
if err := json.NewDecoder(os.Stdin).Decode(&report); err != nil {
return err
}
log.Infof("success to get report for %s", report.ArtifactName)
excelFile := flag.String(
"excel-file",
"",
"specify the name of excel file",
)
beautify := flag.Bool(
"beautify",
false,
"beautify the sheet(fill the background color of the cell according to the severity of the vulnerability.)",
)
markdownFile := flag.String(
"markdown-file",
"",
"specify the name of markdown file",
)
brief := flag.Bool(
"brief",
false,
"report as markdown briefly(remove vulnerability descriptions and reference links.)",
)
flag.Parse()
if *excelFile != "" {
if !strings.HasSuffix(*excelFile, ".xlsx") {
log.Fatal("just support .xlsx file")
}
if err := excel.Export(&report, *excelFile, *beautify); err != nil {
return err
}
log.Infof("success to export %s for %s", *excelFile, report.ArtifactName)
}
if *markdownFile != "" {
if !strings.HasSuffix(*markdownFile, ".md") {
log.Fatal("just support .md file")
}
if err := markdown.Export(&report, *markdownFile, *brief); err != nil {
return err
}
log.Infof("success to export %s for %s", *markdownFile, report.ArtifactName)
}
return nil
}