Skip to content

Commit

Permalink
appending custom rules to all rules array
Browse files Browse the repository at this point in the history
  • Loading branch information
hagarfisher committed Aug 11, 2023
1 parent 00f0410 commit 92f1fe9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ func (s *Secrets) AddRegexRules(patterns []string) error {
return nil
}

func addCustomRules(rules []CustomRuleConfiguration) ([]Rule, error) {
var customRules []Rule
customRules = make([]Rule, len(rules))
for idx, rule := range rules {
regex, err := regexp.Compile(rule.RegexPattern)
if err != nil {
return nil, fmt.Errorf("failed to compile custom regex rule %s: %w", rule.RuleID, err)
}
customRules[idx] = Rule{
Rule: config.Rule{
Description: rule.Description,
RuleID: rule.RuleID,
Regex: regex,
Keywords: []string{},
},
Tags: rule.Tags,
}
if rule.SecretGroup != 0 {
customRules[idx].Rule.SecretGroup = rule.SecretGroup
}
}
return customRules, nil
}

func getFindingId(item plugins.Item, finding report.Finding) string {
idParts := []string{item.ID, finding.RuleID, finding.Secret}
sha := sha1.Sum([]byte(strings.Join(idParts, "-")))
Expand Down Expand Up @@ -369,6 +393,12 @@ func loadAllRules() ([]Rule, error) {
allRules = append(allRules, Rule{Rule: *rules.YandexAccessToken(), Tags: []string{TagAccessToken}})
allRules = append(allRules, Rule{Rule: *rules.ZendeskSecretKey(), Tags: []string{TagSecretKey}})

builtCustomRules, err := addCustomRules(customRules)
if err != nil {
return nil, err
}
allRules = append(allRules, builtCustomRules...)

return allRules, nil
}

Expand Down

0 comments on commit 92f1fe9

Please sign in to comment.