mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 05:04:22 +01:00
[update] regexp work
This commit is contained in:
1 parent
e1a58935ea
commit
595da56eef
2 files changed
+53
-11
No files matched your search
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
_ "fmt"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkRegex(diff []byte) {
|
||||||
|
var re *regexp.Regexp
|
||||||
|
var found string
|
||||||
|
lines := bytes.Split(diff, []byte("\n"))
|
||||||
|
for _, line := range lines {
|
||||||
|
if len(line) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range regexes {
|
||||||
|
re = regexp.MustCompile(v)
|
||||||
|
found = re.FindString(string(line))
|
||||||
|
if len(found) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,20 +13,29 @@ import (
|
|||||||
// gotta be fast
|
// gotta be fast
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
url string
|
url string
|
||||||
name string
|
|
||||||
path string
|
|
||||||
branches *Branch
|
|
||||||
}
|
|
||||||
|
|
||||||
type Branch struct {
|
|
||||||
name string
|
name string
|
||||||
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// memoization for commit1+commit2 hash
|
||||||
|
var cache map[string]bool
|
||||||
var appRoot string
|
var appRoot string
|
||||||
|
var regexes map[string]string
|
||||||
|
var strictRegexes map[string]string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
appRoot, _ = os.Getwd()
|
appRoot, _ = os.Getwd()
|
||||||
|
cache = make(map[string]bool)
|
||||||
|
regexes = map[string]string{
|
||||||
|
"github": "[g|G][i|I][t|T][h|H][u|U][b|B].*",
|
||||||
|
"aws": "[a|A][w|W][s|S].*",
|
||||||
|
"heroku": "[h|H][e|E][r|R][o|O][k|K][u|U].*",
|
||||||
|
"facebook": "[f|F][a|A][c|C][e|E][b|B][o|O][o|O][k|K].*",
|
||||||
|
"twitter": "[t|T][w|W][i|I][t|T][t|T][e|E][r|R].*",
|
||||||
|
"reddit": "[r|R][e|E][d|D][d|D][i|I][t|T].*",
|
||||||
|
"twilio": "[t|T][w|W][i|I][l|L][i|I][o|O].*",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -51,7 +60,7 @@ func repoStart(repo_url string) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := Repo{repo_url, repo_name, "", nil}
|
repo := Repo{repo_url, repo_name, ""}
|
||||||
repo.audit()
|
repo.audit()
|
||||||
repo.cleanup()
|
repo.cleanup()
|
||||||
}
|
}
|
||||||
@@ -96,16 +105,23 @@ func (repo Repo) audit() {
|
|||||||
if j == len(commits)-2 {
|
if j == len(commits)-2 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO need a memoization structure for commitB vs commits[j+1]
|
||||||
|
// memoize the actual diff function
|
||||||
diff(string(commitB), string(commits[j+1]))
|
diff(string(commitB), string(commits[j+1]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func diff(commit1 string, commit2 string) {
|
func diff(commit1 string, commit2 string) {
|
||||||
// fmt.Println(commit1, commit2)
|
_, seen := cache[commit1+commit2]
|
||||||
_, err := exec.Command("git", "diff", commit1, commit2).Output()
|
if seen {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out, err := exec.Command("git", "diff", commit1, commit2).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error retrieving commits %v\n", err)
|
log.Fatalf("error retrieving commits %v\n", err)
|
||||||
}
|
}
|
||||||
//fmt.Printf("%s\n", out)
|
cache[commit1+commit2] = true
|
||||||
|
checkRegex(out)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user