mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 20:54:22 +01:00
No longer generate empty reports (#577)
* return nil when no leaks found and lowercase report format option (#3) * lowercase format options for consistency * lowercase report format description Co-authored-by: eddie-northcutt-wfp0 <eddie.northcutt.wfp0@statefarm.com>
This commit is contained in:
1 parent
ca987b3842
commit
6018a6bb70
3 files changed
+18
-18
No files matched your search
+15
-15
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -27,28 +28,27 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
|
||||
logrus.Warn("leaks found: ", len(report.Leaks))
|
||||
} else {
|
||||
logrus.Info("No leaks found")
|
||||
return nil
|
||||
}
|
||||
|
||||
if opts.Report == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if opts.Redact {
|
||||
var redactedLeaks []Leak
|
||||
for _, leak := range report.Leaks {
|
||||
redactedLeaks = append(redactedLeaks, RedactLeak(leak))
|
||||
} else {
|
||||
if opts.Redact {
|
||||
var redactedLeaks []Leak
|
||||
for _, leak := range report.Leaks {
|
||||
redactedLeaks = append(redactedLeaks, RedactLeak(leak))
|
||||
}
|
||||
report.Leaks = redactedLeaks
|
||||
}
|
||||
report.Leaks = redactedLeaks
|
||||
}
|
||||
|
||||
file, err := os.Create(opts.Report)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rable(file.Close)
|
||||
file, err := os.Create(opts.Report)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rable(file.Close)
|
||||
|
||||
if opts.Report != "" {
|
||||
switch opts.ReportFormat {
|
||||
switch strings.ToLower(opts.ReportFormat) {
|
||||
case "json":
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ")
|
||||
|
||||
Reference in new issue
Block a user