mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 04:04:25 +01:00
67 lines
976 B
Go
67 lines
976 B
Go
package report
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"io"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type CsvReporter struct {
|
|
}
|
|
|
|
var _ Reporter = (*CsvReporter)(nil)
|
|
|
|
func (r *CsvReporter) Write(w io.WriteCloser, findings []Finding) error {
|
|
if len(findings) == 0 {
|
|
return nil
|
|
}
|
|
|
|
cw := csv.NewWriter(w)
|
|
err := cw.Write([]string{"RuleID",
|
|
"Commit",
|
|
"File",
|
|
"SymlinkFile",
|
|
"Secret",
|
|
"Match",
|
|
"StartLine",
|
|
"EndLine",
|
|
"StartColumn",
|
|
"EndColumn",
|
|
"Author",
|
|
"Message",
|
|
"Date",
|
|
"Email",
|
|
"Fingerprint",
|
|
"Tags",
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, f := range findings {
|
|
err = cw.Write([]string{f.RuleID,
|
|
f.Commit,
|
|
f.File,
|
|
f.SymlinkFile,
|
|
f.Secret,
|
|
f.Match,
|
|
strconv.Itoa(f.StartLine),
|
|
strconv.Itoa(f.EndLine),
|
|
strconv.Itoa(f.StartColumn),
|
|
strconv.Itoa(f.EndColumn),
|
|
f.Author,
|
|
f.Message,
|
|
f.Date,
|
|
f.Email,
|
|
f.Fingerprint,
|
|
strings.Join(f.Tags, " "),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
cw.Flush()
|
|
return cw.Error()
|
|
}
|