mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 05:04:22 +01:00
1 parent
b5a726e96a
commit
bbfa8239a8
6 files changed
+19
-5
No files matched your search
@@ -152,6 +152,7 @@ Flags:
|
|||||||
-h, --help help for gitleaks
|
-h, --help help for gitleaks
|
||||||
-l, --log-level string log level (trace, debug, info, warn, error, fatal) (default "info")
|
-l, --log-level string log level (trace, debug, info, warn, error, fatal) (default "info")
|
||||||
--max-target-megabytes int files larger than this will be skipped
|
--max-target-megabytes int files larger than this will be skipped
|
||||||
|
--no-color turn off color for verbose output
|
||||||
--no-banner suppress banner
|
--no-banner suppress banner
|
||||||
--redact redact secrets from logs and stdout
|
--redact redact secrets from logs and stdout
|
||||||
-f, --report-format string output format (json, csv, sarif) (default "json")
|
-f, --report-format string output format (json, csv, sarif) (default "json")
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
// set color flag
|
||||||
|
if detector.NoColor, err = cmd.Flags().GetBool("no-color"); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("")
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ func runProtect(cmd *cobra.Command, args []string) {
|
|||||||
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
|
||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
// set color flag
|
||||||
|
if detector.NoColor, err = cmd.Flags().GetBool("no-color"); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("")
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringP("baseline-path", "b", "", "path to baseline with issues that can be ignored")
|
rootCmd.PersistentFlags().StringP("baseline-path", "b", "", "path to baseline with issues that can be ignored")
|
||||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)")
|
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal)")
|
||||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
||||||
|
rootCmd.PersistentFlags().BoolP("no-color", "", false, "turn off color for verbose output")
|
||||||
rootCmd.PersistentFlags().Int("max-target-megabytes", 0, "files larger than this will be skipped")
|
rootCmd.PersistentFlags().Int("max-target-megabytes", 0, "files larger than this will be skipped")
|
||||||
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
||||||
rootCmd.PersistentFlags().Bool("no-banner", false, "suppress banner")
|
rootCmd.PersistentFlags().Bool("no-banner", false, "suppress banner")
|
||||||
|
|||||||
+5
-2
@@ -57,6 +57,9 @@ type Detector struct {
|
|||||||
// followSymlinks is a flag to enable scanning symlink files
|
// followSymlinks is a flag to enable scanning symlink files
|
||||||
FollowSymlinks bool
|
FollowSymlinks bool
|
||||||
|
|
||||||
|
// NoColor is a flag to disable color output
|
||||||
|
NoColor bool
|
||||||
|
|
||||||
// commitMap is used to keep track of commits that have been scanned.
|
// commitMap is used to keep track of commits that have been scanned.
|
||||||
// This is only used for logging purposes and git scans.
|
// This is only used for logging purposes and git scans.
|
||||||
commitMap map[string]bool
|
commitMap map[string]bool
|
||||||
@@ -536,7 +539,7 @@ func (d *Detector) DetectReader(r io.Reader, bufSize int) ([]report.Finding, err
|
|||||||
for _, finding := range d.Detect(fragment) {
|
for _, finding := range d.Detect(fragment) {
|
||||||
findings = append(findings, finding)
|
findings = append(findings, finding)
|
||||||
if d.Verbose {
|
if d.Verbose {
|
||||||
printFinding(finding)
|
printFinding(finding, d.NoColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -610,7 +613,7 @@ func (d *Detector) addFinding(finding report.Finding) {
|
|||||||
d.findingMutex.Lock()
|
d.findingMutex.Lock()
|
||||||
d.findings = append(d.findings, finding)
|
d.findings = append(d.findings, finding)
|
||||||
if d.Verbose {
|
if d.Verbose {
|
||||||
printFinding(finding)
|
printFinding(finding, d.NoColor)
|
||||||
}
|
}
|
||||||
d.findingMutex.Unlock()
|
d.findingMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -91,7 +91,7 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
|||||||
return retFindings
|
return retFindings
|
||||||
}
|
}
|
||||||
|
|
||||||
func printFinding(f report.Finding) {
|
func printFinding(f report.Finding, noColor bool) {
|
||||||
// trim all whitespace and tabs from the line
|
// trim all whitespace and tabs from the line
|
||||||
f.Line = strings.TrimSpace(f.Line)
|
f.Line = strings.TrimSpace(f.Line)
|
||||||
// trim all whitespace and tabs from the secret
|
// trim all whitespace and tabs from the secret
|
||||||
@@ -104,7 +104,7 @@ func printFinding(f report.Finding) {
|
|||||||
|
|
||||||
skipColor := false
|
skipColor := false
|
||||||
|
|
||||||
if matchInLineIDX == -1 {
|
if matchInLineIDX == -1 || noColor {
|
||||||
skipColor = true
|
skipColor = true
|
||||||
matchInLineIDX = 0
|
matchInLineIDX = 0
|
||||||
}
|
}
|
||||||
@@ -144,11 +144,12 @@ func printFinding(f report.Finding) {
|
|||||||
|
|
||||||
if skipColor {
|
if skipColor {
|
||||||
fmt.Printf("%-12s %s\n", "Finding:", f.Match)
|
fmt.Printf("%-12s %s\n", "Finding:", f.Match)
|
||||||
|
fmt.Printf("%-12s %s\n", "Secret:", f.Secret)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%-12s %s", "Finding:", finding)
|
fmt.Printf("%-12s %s", "Finding:", finding)
|
||||||
|
fmt.Printf("%-12s %s\n", "Secret:", secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%-12s %s\n", "Secret:", secret)
|
|
||||||
fmt.Printf("%-12s %s\n", "RuleID:", f.RuleID)
|
fmt.Printf("%-12s %s\n", "RuleID:", f.RuleID)
|
||||||
fmt.Printf("%-12s %f\n", "Entropy:", f.Entropy)
|
fmt.Printf("%-12s %f\n", "Entropy:", f.Entropy)
|
||||||
if f.File == "" {
|
if f.File == "" {
|
||||||
|
|||||||
Reference in new issue
Block a user