From 8192019bc96eb1c512332e4399103d1c0e43efd3 Mon Sep 17 00:00:00 2001 From: Baruch Odem Date: Wed, 14 Feb 2024 11:39:26 +0200 Subject: [PATCH] rename secrets to engine --- cmd/main.go | 6 +++--- cmd/workers.go | 4 ++-- secrets/{secrets.go => engine.go} | 10 +++++----- secrets/{secrets_test.go => engine_test.go} | 0 4 files changed, 10 insertions(+), 10 deletions(-) rename secrets/{secrets.go => engine.go} (92%) rename secrets/{secrets_test.go => engine_test.go} (100%) diff --git a/cmd/main.go b/cmd/main.go index f266cced..4ff06db3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -120,17 +120,17 @@ func preRun(cmd *cobra.Command, args []string) error { return err } - secrets, err := secrets.Init(secretsConfigVar) + engine, err := secrets.Init(secretsConfigVar) if err != nil { return err } - if err := secrets.AddRegexRules(customRegexRuleVar); err != nil { + if err := engine.AddRegexRules(customRegexRuleVar); err != nil { return err } channels.WaitGroup.Add(1) - go processItems(secrets) + go processItems(engine) channels.WaitGroup.Add(1) go processSecrets() diff --git a/cmd/workers.go b/cmd/workers.go index c5ef1770..2246949b 100644 --- a/cmd/workers.go +++ b/cmd/workers.go @@ -6,14 +6,14 @@ import ( "github.com/checkmarx/2ms/secrets" ) -func processItems(detector *secrets.Secrets) { +func processItems(engine *secrets.Engine) { defer channels.WaitGroup.Done() wgItems := &sync.WaitGroup{} for item := range channels.Items { report.TotalItemsScanned++ wgItems.Add(1) - go detector.Detect(item, secretsChan, wgItems, ignoreVar) + go engine.Detect(item, secretsChan, wgItems, ignoreVar) } wgItems.Wait() close(secretsChan) diff --git a/secrets/secrets.go b/secrets/engine.go similarity index 92% rename from secrets/secrets.go rename to secrets/engine.go index 2b6e71e2..4f2f05a2 100644 --- a/secrets/secrets.go +++ b/secrets/engine.go @@ -19,7 +19,7 @@ import ( "github.com/zricethezav/gitleaks/v8/report" ) -type Secrets struct { +type Engine struct { rules map[string]config.Rule detector detect.Detector } @@ -34,7 +34,7 @@ type SecretsConfig struct { MaxTargetMegabytes int } -func Init(secretsConfig SecretsConfig) (*Secrets, error) { +func Init(secretsConfig SecretsConfig) (*Engine, error) { selectedRules := rules.FilterRules(secretsConfig.SelectedList, secretsConfig.IgnoreList, secretsConfig.SpecialList) if len(*selectedRules) == 0 { return nil, fmt.Errorf("no rules were selected") @@ -52,13 +52,13 @@ func Init(secretsConfig SecretsConfig) (*Secrets, error) { }) detector.MaxTargetMegaBytes = secretsConfig.MaxTargetMegabytes - return &Secrets{ + return &Engine{ rules: rulesToBeApplied, detector: *detector, }, nil } -func (s *Secrets) Detect(item plugins.Item, secretsChannel chan *reporting.Secret, wg *sync.WaitGroup, ignoredIds []string) { +func (s *Engine) Detect(item plugins.Item, secretsChannel chan *reporting.Secret, wg *sync.WaitGroup, ignoredIds []string) { defer wg.Done() fragment := detect.Fragment{ @@ -84,7 +84,7 @@ func (s *Secrets) Detect(item plugins.Item, secretsChannel chan *reporting.Secre } } -func (s *Secrets) AddRegexRules(patterns []string) error { +func (s *Engine) AddRegexRules(patterns []string) error { for idx, pattern := range patterns { regex, err := regexp.Compile(pattern) if err != nil { diff --git a/secrets/secrets_test.go b/secrets/engine_test.go similarity index 100% rename from secrets/secrets_test.go rename to secrets/engine_test.go