Skip to content

Commit

Permalink
rename secrets to engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Baruch Odem committed Feb 14, 2024
1 parent 9a996bd commit 8192019
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cmd/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions secrets/secrets.go → secrets/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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")
Expand All @@ -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{
Expand All @@ -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 {
Expand Down
File renamed without changes.

0 comments on commit 8192019

Please sign in to comment.