Compare commits

...
5 Commits
9 changed files with 28 additions and 10 deletions

No files matched your search

+11 -1
View File
@@ -290,7 +290,17 @@ will be given precedence.
## Sponsorships ## Sponsorships
[![Tines-Sponsorship-Badge-Purple](https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png)](https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks) <p align="left">
<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
<img alt="Tines Sponsorship" src="https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png" width=200>
</a>
</p>
<a href="https://www.typeform.com/">
<img src="https://user-images.githubusercontent.com/15034943/146945294-a6473d55-86b8-4f53-941e-7f185ad6b3d7.png" width=200/>
</a>
</p>
## Exit Codes ## Exit Codes
+2
View File
@@ -17,6 +17,8 @@ type Options struct {
Redact bool Redact bool
} }
const MAXGOROUTINES = 4
func DetectFindings(cfg config.Config, b []byte, filePath string, commit string) []report.Finding { func DetectFindings(cfg config.Config, b []byte, filePath string, commit string) []report.Finding {
var findings []report.Finding var findings []report.Finding
linePairs := regexp.MustCompile("\n").FindAllIndex(b, -1) linePairs := regexp.MustCompile("\n").FindAllIndex(b, -1)
+5
View File
@@ -20,6 +20,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
findings []report.Finding findings []report.Finding
mu sync.Mutex mu sync.Mutex
) )
concurrentGoroutines := make(chan struct{}, MAXGOROUTINES)
g, _ := errgroup.WithContext(context.Background()) g, _ := errgroup.WithContext(context.Background())
paths := make(chan string) paths := make(chan string)
g.Go(func() error { g.Go(func() error {
@@ -40,7 +41,11 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
}) })
for pa := range paths { for pa := range paths {
p := pa p := pa
concurrentGoroutines <- struct{}{}
g.Go(func() error { g.Go(func() error {
defer func() {
<-concurrentGoroutines
}()
b, err := os.ReadFile(p) b, err := os.ReadFile(p)
if err != nil { if err != nil {
return err return err
+6 -2
View File
@@ -19,16 +19,20 @@ func FromGit(files <-chan *gitdiff.File, cfg config.Config, outputOptions Option
var findings []report.Finding var findings []report.Finding
mu := sync.Mutex{} mu := sync.Mutex{}
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
concurrentGoroutines := make(chan struct{}, MAXGOROUTINES)
commitMap := make(map[string]bool) commitMap := make(map[string]bool)
for f := range files { for f := range files {
// keep track of commits for logging // keep track of commits for logging
if f.PatchHeader != nil { if f.PatchHeader != nil {
commitMap[f.PatchHeader.SHA] = true commitMap[f.PatchHeader.SHA] = true
} }
wg.Add(1) wg.Add(1)
concurrentGoroutines <- struct{}{}
go func(f *gitdiff.File) { go func(f *gitdiff.File) {
defer wg.Done() defer func() {
wg.Done()
<-concurrentGoroutines
}()
if f.IsBinary { if f.IsBinary {
return return
} }
+1 -1
View File
@@ -7,7 +7,7 @@ import (
func writeJson(findings []Finding, w io.WriteCloser) error { func writeJson(findings []Finding, w io.WriteCloser) error {
if len(findings) == 0 { if len(findings) == 0 {
return nil findings = []Finding{}
} }
encoder := json.NewEncoder(w) encoder := json.NewEncoder(w)
encoder.SetIndent("", " ") encoder.SetIndent("", " ")
+1 -2
View File
@@ -39,9 +39,8 @@ func TestWriteJSON(t *testing.T) {
}}, }},
{ {
wantEmpty: true,
testReportName: "empty", testReportName: "empty",
expected: filepath.Join(expectPath, "report", "this_should_not_exist.json"), expected: filepath.Join(expectPath, "report", "empty.json"),
findings: []Finding{}}, findings: []Finding{}},
} }
-3
View File
@@ -14,9 +14,6 @@ const (
) )
func Write(findings []Finding, cfg config.Config, ext string, reportPath string) error { func Write(findings []Finding, cfg config.Config, ext string, reportPath string) error {
if len(findings) == 0 {
return nil
}
file, err := os.Create(reportPath) file, err := os.Create(reportPath)
if err != nil { if err != nil {
return err return err
+1 -1
View File
@@ -64,7 +64,7 @@ func messageText(f Finding) string {
} }
func getResults(findings []Finding) []Results { func getResults(findings []Finding) []Results {
var results []Results results := []Results{}
for _, f := range findings { for _, f := range findings {
r := Results{ r := Results{
Message: Message{ Message: Message{
+1
View File
@@ -0,0 +1 @@
[]