mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 05:04:22 +01:00
Quiet flag (#491)
* Adding a quiet option * better description Co-authored-by: Zach Rice <zrice@gitlab.com>
This commit is contained in:
1 parent
091ea81e68
commit
58d130c5f3
6 files changed
+39
-27
No files matched your search
+5
-6
@@ -95,9 +95,8 @@ func (cs *CommitScanner) Scan() (Report, error) {
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
if cs.opts.Verbose {
|
||||
leak.Log(cs.opts.Redact)
|
||||
}
|
||||
leak.Log(cs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
continue
|
||||
}
|
||||
@@ -137,9 +136,9 @@ func (cs *CommitScanner) Scan() (Report, error) {
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
if cs.opts.Verbose {
|
||||
leak.Log(cs.opts.Redact)
|
||||
}
|
||||
|
||||
leak.Log(cs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,8 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
if fs.opts.Verbose {
|
||||
leak.Log(fs.opts.Redact)
|
||||
}
|
||||
leak.Log(fs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
continue
|
||||
}
|
||||
@@ -122,9 +121,9 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
if fs.opts.Verbose {
|
||||
leak.Log(fs.opts.Redact)
|
||||
}
|
||||
|
||||
leak.Log(fs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
|
||||
+16
-5
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
@@ -56,13 +58,22 @@ func (leak Leak) WithCommit(commit *object.Commit) Leak {
|
||||
}
|
||||
|
||||
// Log logs a leak and redacts if necessary
|
||||
func (leak Leak) Log(redact bool) {
|
||||
if redact {
|
||||
func (leak Leak) Log(opts options.Options) {
|
||||
if !opts.Quiet && !opts.Verbose {
|
||||
return
|
||||
}
|
||||
if opts.Redact {
|
||||
leak = RedactLeak(leak)
|
||||
}
|
||||
var b []byte
|
||||
b, _ = json.MarshalIndent(leak, "", " ")
|
||||
fmt.Println(string(b))
|
||||
if opts.Quiet {
|
||||
var b []byte
|
||||
b, _ = json.Marshal(leak)
|
||||
fmt.Println(string(b))
|
||||
} else {
|
||||
var b []byte
|
||||
b, _ = json.MarshalIndent(leak, "", " ")
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
}
|
||||
|
||||
// URL generates a url to the leak if leak.RepoURL is set
|
||||
|
||||
+5
-6
@@ -77,9 +77,8 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
if ngs.opts.Verbose {
|
||||
leak.Log(ngs.opts.Redact)
|
||||
}
|
||||
leak.Log(ngs.opts)
|
||||
|
||||
leaks <- leak
|
||||
}
|
||||
}
|
||||
@@ -120,9 +119,9 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
||||
leak.LineNumber = lineNumber
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
if ngs.opts.Verbose {
|
||||
leak.Log(ngs.opts.Redact)
|
||||
}
|
||||
|
||||
leak.Log(ngs.opts)
|
||||
|
||||
leaks <- leak
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -86,7 +86,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
if us.opts.Verbose {
|
||||
leak.Log(us.opts.Redact)
|
||||
leak.Log(us.opts)
|
||||
}
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
@@ -198,9 +198,9 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
leak.Repo = us.repoName
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
if us.opts.Verbose {
|
||||
leak.Log(us.opts.Redact)
|
||||
}
|
||||
|
||||
leak.Log(us.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user