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:
Eddie Austinandeddie-northcutt-wfp0 authored and GitHub committed 2021-09-06 16:39:50 -05:00
1 parent ca987b3842
commit 6018a6bb70
3 files changed
+18 -18

No files matched your search

+2 -2
View File
@@ -27,7 +27,7 @@ Gitleaks is a SAST tool for detecting hardcoded secrets like passwords, api keys
- Run [Gitleaks Action](https://github.com/marketplace/actions/gitleaks) in your CI/CD pipeline
- [Custom rules](https://github.com/zricethezav/gitleaks#configuration) via toml configuration
- Increased performance using [go-git](https://github.com/go-git/go-git)
- JSON, SARIF, and CSV reporting
- json, sarif, and csv reporting
- Private repo scans using key or password based authentication
@@ -94,7 +94,7 @@ Application Options:
--append-repo-config Append the provided or default config with the repo config.
--additional-config= Path to an additional gitleaks config to append with an existing config. Can be used with --append-repo-config to append up to three configurations
-o, --report= Report output path
-f, --format= JSON, CSV, SARIF (default: json)
-f, --format= json, csv, sarif (default: json)
--files-at-commit= Sha of commit to scan all files at commit
--commit= Sha of commit to scan or "latest" to scan the last commit of the repository
--commits= Comma separated list of a commits to scan
+1 -1
View File
@@ -44,7 +44,7 @@ type Options struct {
// Report Options
Report string `short:"o" long:"report" description:"Report output path"`
ReportFormat string `short:"f" long:"format" default:"json" description:"JSON, CSV, SARIF"`
ReportFormat string `short:"f" long:"format" default:"json" description:"json, csv, sarif"`
// Commit Options
FilesAtCommit string `long:"files-at-commit" description:"Sha of commit to scan all files at commit"`
+15 -15
View File
@@ -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("", " ")