diff --git a/gitleaks_test.go b/gitleaks_test.go index 77c07ddf..b6b4ae75 100644 --- a/gitleaks_test.go +++ b/gitleaks_test.go @@ -8,6 +8,7 @@ import ( "regexp" "strings" "testing" + "time" "github.com/franela/goblin" git "gopkg.in/src-d/go-git.v4" @@ -368,6 +369,7 @@ func TestWriteReport(t *testing.T) { Author: "some", File: "sleep", Branch: "thxu", + Date: time.Now(), }, } diff --git a/main.go b/main.go index af67f8b2..c2e4d565 100644 --- a/main.go +++ b/main.go @@ -37,15 +37,16 @@ import ( // Leak represents a leaked secret or regex match. type Leak struct { - Line string `json:"line"` - Commit string `json:"commit"` - Offender string `json:"offender"` - Type string `json:"reason"` - Message string `json:"commitMsg"` - Author string `json:"author"` - File string `json:"file"` - Branch string `json:"branch"` - Repo string `json:"repo"` + Line string `json:"line"` + Commit string `json:"commit"` + Offender string `json:"offender"` + Type string `json:"reason"` + Message string `json:"commitMsg"` + Author string `json:"author"` + File string `json:"file"` + Branch string `json:"branch"` + Repo string `json:"repo"` + Date time.Time `json:"date"` } // RepoDescriptor contains a src-d git repository and other data about the repo @@ -128,6 +129,7 @@ type gitDiff struct { sha string message string author string + date time.Time } type entropyRange struct { @@ -348,9 +350,9 @@ func writeReport(leaks []Leak) error { } defer f.Close() w := csv.NewWriter(f) - w.Write([]string{"repo", "line", "commit", "offender", "reason", "commitMsg", "author", "file", "branch"}) + w.Write([]string{"repo", "line", "commit", "offender", "reason", "commitMsg", "author", "file", "branch", "date"}) for _, leak := range leaks { - w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Type, leak.Message, leak.Author, leak.File, leak.Branch}) + w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Type, leak.Message, leak.Author, leak.File, leak.Branch, leak.Date.Format(time.RFC3339)}) } w.Flush() } else { @@ -561,6 +563,7 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak { sha: c.Hash.String(), author: c.Author.String(), message: c.Message, + date: c.Author.When, } chunkLeaks := inspect(diff) for _, leak := range chunkLeaks { @@ -651,6 +654,7 @@ func addLeak(leaks []Leak, line string, offender string, leakType string, diff g Branch: diff.branchName, Repo: diff.repoName, Message: diff.message, + Date: diff.date, } if opts.Redact { leak.Offender = "REDACTED"