mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 13:34:23 +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
+36
-24
No files matched your search
@@ -21,6 +21,7 @@ import (
|
|||||||
// Options stores values of command line options
|
// Options stores values of command line options
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
|
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
|
||||||
|
Quiet bool `short:"q" long:"quiet" description:"Sets log level to error and only output leaks, one json object per line"`
|
||||||
RepoURL string `short:"r" long:"repo-url" description:"Repository URL"`
|
RepoURL string `short:"r" long:"repo-url" description:"Repository URL"`
|
||||||
Path string `short:"p" long:"path" description:"Path to directory (repo if contains .git) or file"`
|
Path string `short:"p" long:"path" description:"Path to directory (repo if contains .git) or file"`
|
||||||
ConfigPath string `short:"c" long:"config-path" description:"Path to config"`
|
ConfigPath string `short:"c" long:"config-path" description:"Path to config"`
|
||||||
@@ -83,6 +84,9 @@ func ParseOptions() (Options, error) {
|
|||||||
if opts.Debug {
|
if opts.Debug {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
if opts.Quiet {
|
||||||
|
log.SetLevel(log.ErrorLevel)
|
||||||
|
}
|
||||||
|
|
||||||
return opts, nil
|
return opts, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-6
@@ -95,9 +95,8 @@ func (cs *CommitScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
|
||||||
if cs.opts.Verbose {
|
leak.Log(cs.opts)
|
||||||
leak.Log(cs.opts.Redact)
|
|
||||||
}
|
|
||||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -137,9 +136,9 @@ func (cs *CommitScanner) Scan() (Report, error) {
|
|||||||
leak.LeakURL = leak.URL()
|
leak.LeakURL = leak.URL()
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
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)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,8 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
|
||||||
if fs.opts.Verbose {
|
leak.Log(fs.opts)
|
||||||
leak.Log(fs.opts.Redact)
|
|
||||||
}
|
|
||||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -122,9 +121,9 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
|||||||
leak.LeakURL = leak.URL()
|
leak.LeakURL = leak.URL()
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
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)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-2
@@ -6,6 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/zricethezav/gitleaks/v7/options"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,14 +58,23 @@ func (leak Leak) WithCommit(commit *object.Commit) Leak {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log logs a leak and redacts if necessary
|
// Log logs a leak and redacts if necessary
|
||||||
func (leak Leak) Log(redact bool) {
|
func (leak Leak) Log(opts options.Options) {
|
||||||
if redact {
|
if !opts.Quiet && !opts.Verbose {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if opts.Redact {
|
||||||
leak = RedactLeak(leak)
|
leak = RedactLeak(leak)
|
||||||
}
|
}
|
||||||
|
if opts.Quiet {
|
||||||
|
var b []byte
|
||||||
|
b, _ = json.Marshal(leak)
|
||||||
|
fmt.Println(string(b))
|
||||||
|
} else {
|
||||||
var b []byte
|
var b []byte
|
||||||
b, _ = json.MarshalIndent(leak, "", " ")
|
b, _ = json.MarshalIndent(leak, "", " ")
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// URL generates a url to the leak if leak.RepoURL is set
|
// URL generates a url to the leak if leak.RepoURL is set
|
||||||
func (leak Leak) URL() string {
|
func (leak Leak) URL() string {
|
||||||
|
|||||||
+5
-6
@@ -77,9 +77,8 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
|
|
||||||
if ngs.opts.Verbose {
|
leak.Log(ngs.opts)
|
||||||
leak.Log(ngs.opts.Redact)
|
|
||||||
}
|
|
||||||
leaks <- leak
|
leaks <- leak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,9 +119,9 @@ func (ngs *NoGitScanner) Scan() (Report, error) {
|
|||||||
leak.LineNumber = lineNumber
|
leak.LineNumber = lineNumber
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
if ngs.opts.Verbose {
|
|
||||||
leak.Log(ngs.opts.Redact)
|
leak.Log(ngs.opts)
|
||||||
}
|
|
||||||
leaks <- leak
|
leaks <- leak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -86,7 +86,7 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
|||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||||
if us.opts.Verbose {
|
if us.opts.Verbose {
|
||||||
leak.Log(us.opts.Redact)
|
leak.Log(us.opts)
|
||||||
}
|
}
|
||||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
@@ -198,9 +198,9 @@ func (us *UnstagedScanner) Scan() (Report, error) {
|
|||||||
leak.Repo = us.repoName
|
leak.Repo = us.repoName
|
||||||
leak.Rule = rule.Description
|
leak.Rule = rule.Description
|
||||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
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)
|
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user