diff --git a/cmd/hungryfox/main.go b/cmd/hungryfox/main.go index 9a9844e..2327e06 100644 --- a/cmd/hungryfox/main.go +++ b/cmd/hungryfox/main.go @@ -117,7 +117,7 @@ func main() { logger.Error().Str("service", "leaks searcher").Str("error", err.Error()).Msg("fail") os.Exit(1) } - logger.Debug().Str("service", "leaks searcher").Msg("started") + logger.Debug().Str("service", "leaks searcher").Int("workers", numCPUs).Msg("started") logger.Debug().Str("service", "state manager").Msg("start") stateManager := &filestate.StateManager{ diff --git a/hungryfox.go b/hungryfox.go index 79f94ce..e656c92 100644 --- a/hungryfox.go +++ b/hungryfox.go @@ -45,14 +45,14 @@ type Repo struct { type IMessageSender interface { Start() error - Send(*Leak) error + Send(Leak) error Stop() error } type ILeakSearcher interface { Start() error SetConfig() error - Search(*Diff) + Search(Diff) Stop() error } diff --git a/router/router.go b/router/router.go index f35e867..5e8d792 100644 --- a/router/router.go +++ b/router/router.go @@ -28,19 +28,20 @@ func (r *LeaksRouter) Start() error { return fmt.Errorf("can't parse delay with: %v", err) } r.senders = map[string]hungryfox.IMessageSender{} - - r.senders["email"] = &email.Sender{ - AuditorEmail: r.Config.SMTP.Recipient, - Config: &email.Config{ - From: r.Config.SMTP.From, - SMTPHost: r.Config.SMTP.Host, - SMTPPort: r.Config.SMTP.Port, - InsecureTLS: !r.Config.SMTP.TLS, - Username: r.Config.SMTP.Username, - Password: r.Config.SMTP.Password, - Delay: delay, - }, - Log: r.Log, + if r.Config.SMTP.Enable { + r.senders["email"] = &email.Sender{ + AuditorEmail: r.Config.SMTP.Recipient, + Config: &email.Config{ + From: r.Config.SMTP.From, + SMTPHost: r.Config.SMTP.Host, + SMTPPort: r.Config.SMTP.Port, + InsecureTLS: !r.Config.SMTP.TLS, + Username: r.Config.SMTP.Username, + Password: r.Config.SMTP.Password, + Delay: delay, + }, + Log: r.Log, + } } r.senders["file"] = &file.File{ LeaksFile: r.Config.Common.LeaksFile, @@ -60,7 +61,7 @@ func (r *LeaksRouter) Start() error { return nil case leak := <-r.LeakChannel: for _, sender := range r.senders { - sender.Send(leak) + sender.Send(*leak) } } } diff --git a/searcher/searcher.go b/searcher/searcher.go index b3123e8..8d7cebc 100644 --- a/searcher/searcher.go +++ b/searcher/searcher.go @@ -104,12 +104,12 @@ func (s *Searcher) worker() error { case diff := <-s.DiffChannel: leaks := s.GetLeaks(*diff) filtredLeaks := 0 - for _, leak := range leaks { - if s.filterLeak(leak) { + for i := range leaks { + if s.filterLeak(leaks[i]) { filtredLeaks++ continue } - s.LeakChannel <- &leak + s.LeakChannel <- &leaks[i] } leaksCount := len(leaks) - filtredLeaks if leaksCount > 0 || filtredLeaks > 0 { @@ -214,7 +214,7 @@ func (s *Searcher) GetLeaks(diff hungryfox.Diff) []hungryfox.Leak { if len(line) > 1024 { line = line[:1024] } - leak := hungryfox.Leak{ + leaks = append(leaks, hungryfox.Leak{ RepoPath: diff.RepoPath, FilePath: diff.FilePath, PatternName: pattern.Name, @@ -225,8 +225,7 @@ func (s *Searcher) GetLeaks(diff hungryfox.Diff) []hungryfox.Leak { CommitAuthor: diff.Author, CommitEmail: diff.AuthorEmail, RepoURL: diff.RepoURL, - } - leaks = append(leaks, leak) + }) } } } diff --git a/senders/email/sender.go b/senders/email/sender.go index 8597645..1e60312 100644 --- a/senders/email/sender.go +++ b/senders/email/sender.go @@ -21,7 +21,7 @@ type mailTemplateStruct struct { type mailTemplateRepoStruct struct { RepoURL string - Items []*hungryfox.Leak + Items []hungryfox.Leak } func (s *Sender) batchMaker() muster.Batch { @@ -58,7 +58,7 @@ func (b *batch) Fire(notifier muster.Notifier) { } func (b *batch) Add(item interface{}) { - leak := item.(*hungryfox.Leak) + leak := item.(hungryfox.Leak) leak.LeakString = strings.TrimSpace(leak.LeakString) if len(leak.LeakString) > 512 { leak.LeakString = "too long" @@ -66,7 +66,7 @@ func (b *batch) Add(item interface{}) { if b.Repos[leak.RepoURL] == nil { b.Repos[leak.RepoURL] = &mailTemplateRepoStruct{ RepoURL: leak.RepoURL, - Items: []*hungryfox.Leak{}, + Items: []hungryfox.Leak{}, } } b.Repos[leak.RepoURL].Items = append(b.Repos[leak.RepoURL].Items, leak) diff --git a/senders/email/server.go b/senders/email/server.go index 5e90c9d..20445c6 100644 --- a/senders/email/server.go +++ b/senders/email/server.go @@ -76,7 +76,7 @@ func (s *Sender) Stop() error { } // Send - send leaks -func (s *Sender) Send(leak *hungryfox.Leak) error { +func (s *Sender) Send(leak hungryfox.Leak) error { s.muster.Work <- leak return nil } diff --git a/senders/file/file.go b/senders/file/file.go index 2e47043..f14e408 100644 --- a/senders/file/file.go +++ b/senders/file/file.go @@ -19,7 +19,7 @@ func (self *File) Stop() error { return nil } -func (self *File) Send(leak *hungryfox.Leak) error { +func (self *File) Send(leak hungryfox.Leak) error { f, err := os.OpenFile(self.LeaksFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) if err != nil { return err