1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 18:15:42 +01:00

Generate HTML output

This commit is contained in:
Sascha L. Teichmann 2021-12-10 12:25:33 +01:00
parent 11cd5a3806
commit 712b4ad856
4 changed files with 50 additions and 6 deletions

View file

@ -32,7 +32,7 @@ func run(domains []string, checks []check) (*Report, error) {
return nil, err return nil, err
} }
} }
domain := new(Domain) domain := &Domain{Name: d}
for _, ch := range checks { for _, ch := range checks {
ch.report(state, domain) ch.report(state, domain)
} }

View file

@ -9,7 +9,10 @@
package main package main
import ( import (
"bufio"
_ "embed" // Used for embedding.
"encoding/json" "encoding/json"
"html/template"
"io" "io"
"log" "log"
"os" "os"
@ -17,6 +20,9 @@ import (
"github.com/jessevdk/go-flags" "github.com/jessevdk/go-flags"
) )
//go:embed tmpl/report.html
var reportHTML string
type options struct { type options struct {
Output string `short:"o" long:"output" description:"File name of the generated report" value-name:"REPORT-FILE"` Output string `short:"o" long:"output" description:"File name of the generated report" value-name:"REPORT-FILE"`
Format string `short:"f" long:"format" choice:"json" choice:"html" description:"Format of report" default:"json"` Format string `short:"f" long:"format" choice:"json" choice:"html" description:"Format of report" default:"json"`
@ -46,8 +52,23 @@ func writeJSON(report *Report, w io.WriteCloser) error {
} }
func writeHTML(report *Report, w io.WriteCloser) error { func writeHTML(report *Report, w io.WriteCloser) error {
// TODO: Implement me! tmpl, err := template.New("Report HTML").Parse(reportHTML)
return w.Close() if err != nil {
w.Close()
return err
}
buf := bufio.NewWriter(w)
if err := tmpl.Execute(buf, report); err != nil {
w.Close()
return err
}
err = buf.Flush()
if e := w.Close(); err == nil {
err = e
}
return err
} }
type nopCloser struct{ io.Writer } type nopCloser struct{ io.Writer }

View file

@ -12,16 +12,16 @@ package main
type Requirement struct { type Requirement struct {
Num int `json:"num"` Num int `json:"num"`
Description string `json:"description"` Description string `json:"description"`
Messages []string `json:"messages"` Messages []string `json:"messages,omitempty"`
} }
// Domain are the results of a domain. // Domain are the results of a domain.
type Domain struct { type Domain struct {
Name string `json:"name"` Name string `json:"name"`
Requirements []*Requirement `json:"requirements"` Requirements []*Requirement `json:"requirements,omitempty"`
} }
// Report is the overall report. // Report is the overall report.
type Report struct { type Report struct {
Domains []*Domain `json:"domains"` Domains []*Domain `json:"domains,omitempty"`
} }

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta description="CSAF-Checker - Report">
<title>CSAF-Checker - Report</title>
</head>
<body>
<h1>CSAF-Checker - Report</h1>
{{ range .Domains }}
<h2>{{ .Name }}</h2>
Requirements:
<dl>
{{ range .Requirements }}
<dt>{{ .Num }} - {{ .Description }}</dt>
{{ range .Messages }}
{{ end }}
<dd>- {{ . }}</dd>
{{ end }}
</dl>
{{ end }}
</body>
</html>