concurrency option functional

This commit is contained in:
zricethezav committed 2018-02-18 17:58:53 -06:00
1 parent 5d924ecc53
commit 825d434c66
2 files changed
+10 -5

No files matched your search

+10 -4
View File
@@ -20,6 +20,7 @@ type LeakElem struct {
Commit string `json:"commit"` Commit string `json:"commit"`
} }
// start clones and determines if there are any leaks
func start(opts *Options) { func start(opts *Options) {
fmt.Printf("\nEvaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) fmt.Printf("\nEvaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL)
c := make(chan os.Signal, 2) c := make(chan os.Signal, 2)
@@ -40,7 +41,7 @@ func start(opts *Options) {
os.Exit(1) os.Exit(1)
}() }()
report := getLeaks(repoName) report := getLeaks(repoName, opts.Concurrency)
if len(report) == 0 { if len(report) == 0 {
fmt.Printf("No Leaks detected for \x1b[35;2m%s\x1b[0m...\n\n", opts.RepoURL) fmt.Printf("No Leaks detected for \x1b[35;2m%s\x1b[0m...\n\n", opts.RepoURL)
} }
@@ -63,6 +64,7 @@ func getLocalRepoName(url string) string {
return name return name
} }
// cleanup deletes the repo
func cleanup(repoName string) { func cleanup(repoName string) {
if err := os.Chdir(appRoot); err != nil { if err := os.Chdir(appRoot); err != nil {
log.Fatalf("failed cleaning up repo. Does the repo exist? %v", err) log.Fatalf("failed cleaning up repo. Does the repo exist? %v", err)
@@ -73,18 +75,22 @@ func cleanup(repoName string) {
} }
} }
func getLeaks(repoName string) []LeakElem { // getLeaks will attempt to find gitleaks
func getLeaks(repoName string, concurrency int) []LeakElem {
var ( var (
out []byte out []byte
err error err error
commitWG sync.WaitGroup commitWG sync.WaitGroup
gitLeakReceiverWG sync.WaitGroup gitLeakReceiverWG sync.WaitGroup
concurrent = 100
semaphoreChan = make(chan struct{}, concurrent)
gitLeaks = make(chan LeakElem) gitLeaks = make(chan LeakElem)
report []LeakElem report []LeakElem
) )
if concurrency == 0 {
concurrency = 100
}
semaphoreChan := make(chan struct{}, concurrency)
go func(commitWG *sync.WaitGroup, gitLeakReceiverWG *sync.WaitGroup) { go func(commitWG *sync.WaitGroup, gitLeakReceiverWG *sync.WaitGroup) {
for gitLeak := range gitLeaks { for gitLeak := range gitLeaks {
fmt.Println(gitLeak) fmt.Println(gitLeak)
-1
View File
@@ -42,7 +42,6 @@ func init() {
func main() { func main() {
args := os.Args[1:] args := os.Args[1:]
opts := parseOptions(args) opts := parseOptions(args)
fmt.Println(opts)
if opts.RepoURL != "" { if opts.RepoURL != "" {
start(opts) start(opts)
} else if opts.UserURL != "" || opts.OrgURL != "" { } else if opts.UserURL != "" || opts.OrgURL != "" {