mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 20:54:22 +01:00
1 parent
7d9dd260f4
commit
96eed6aa0f
12 files changed
+134
-15
No files matched your search
+53
-4
@@ -1,12 +1,14 @@
|
||||
package detect
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
// "encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
|
||||
"github.com/gitleaks/go-gitdiff/gitdiff"
|
||||
@@ -90,9 +92,56 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
|
||||
}
|
||||
|
||||
func printFinding(f report.Finding) {
|
||||
var b []byte
|
||||
b, _ = json.MarshalIndent(f, "", " ")
|
||||
fmt.Println(string(b))
|
||||
// trim all whitespace and tabs from the line
|
||||
f.Line = strings.TrimSpace(f.Line)
|
||||
// trim all whitespace and tabs from the secret
|
||||
f.Secret = strings.TrimSpace(f.Secret)
|
||||
// trim all whitespace and tabs from the match
|
||||
f.Match = strings.TrimSpace(f.Match)
|
||||
|
||||
matchInLineIDX := strings.Index(f.Line, f.Match)
|
||||
secretInMatchIdx := strings.Index(f.Match, f.Secret)
|
||||
|
||||
start := f.Line[0:matchInLineIDX]
|
||||
startMatchIdx := 0
|
||||
if matchInLineIDX > 20 {
|
||||
startMatchIdx = matchInLineIDX - 20
|
||||
start = "..." + f.Line[startMatchIdx:matchInLineIDX]
|
||||
}
|
||||
|
||||
matchBeginning := lipgloss.NewStyle().SetString(f.Match[0:secretInMatchIdx]).Foreground(lipgloss.Color("#f5d445"))
|
||||
secret := lipgloss.NewStyle().SetString(f.Secret).
|
||||
Bold(true).
|
||||
Italic(true).
|
||||
Foreground(lipgloss.Color("#f05c07"))
|
||||
matchEnd := lipgloss.NewStyle().SetString(f.Match[secretInMatchIdx+len(f.Secret):]).Foreground(lipgloss.Color("#f5d445"))
|
||||
lineEnd := f.Line[matchInLineIDX+len(f.Match):]
|
||||
if len(f.Secret) > 100 {
|
||||
secret = lipgloss.NewStyle().SetString(f.Secret[0:100] + "...").
|
||||
Bold(true).
|
||||
Italic(true).
|
||||
Foreground(lipgloss.Color("#f05c07"))
|
||||
}
|
||||
if len(lineEnd) > 20 {
|
||||
lineEnd = lineEnd[0:20] + "..."
|
||||
}
|
||||
|
||||
finding := fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
|
||||
fmt.Printf("%-8s %s", "Finding:", finding)
|
||||
fmt.Printf("%-8s %s\n", "Secret:", secret)
|
||||
fmt.Printf("%-8s %s\n", "RuleID:", f.RuleID)
|
||||
fmt.Printf("%-8s %f\n", "Entropy:", f.Entropy)
|
||||
fmt.Printf("%-8s %s\n", "File:", f.File)
|
||||
fmt.Printf("%-8s %d\n", "Line:", f.StartLine)
|
||||
if f.Commit == "" {
|
||||
fmt.Println("")
|
||||
return
|
||||
}
|
||||
fmt.Printf("%-8s %s\n", "Commit:", f.Commit)
|
||||
fmt.Printf("%-8s %s\n", "Author:", f.Author)
|
||||
fmt.Printf("%-8s %s\n", "Email:", f.Email)
|
||||
fmt.Printf("%-8s %s\n", "Date:", f.Date)
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func containsDigit(s string) bool {
|
||||
|
||||
Reference in new issue
Block a user