Skip to content

Commit

Permalink
feat(rule): add a method for evaluation (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin authored Oct 20, 2023
1 parent e1ce1b3 commit 7ccc467
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pkg/scan/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import (
"regexp"
"strings"

"github.com/aquasecurity/defsec/pkg/framework"

"golang.org/x/text/language"

"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/aquasecurity/defsec/pkg/terraform"

"github.com/aquasecurity/defsec/pkg/framework"
"github.com/aquasecurity/defsec/pkg/providers"
"github.com/aquasecurity/defsec/pkg/severity"

"github.com/aquasecurity/defsec/pkg/state"

"github.com/aquasecurity/defsec/pkg/providers"
"github.com/aquasecurity/defsec/pkg/terraform"
)

type CheckFunc func(s *state.State) (results Results)
Expand Down Expand Up @@ -57,6 +52,7 @@ type Rule struct {
CustomChecks CustomChecks `json:"-"`
RegoPackage string `json:"-"`
Frameworks map[framework.Framework][]string `json:"frameworks"`
Check CheckFunc `json:"-"`
}

func (r Rule) HasID(id string) bool {
Expand All @@ -83,6 +79,21 @@ func (r Rule) ShortCodeDisplayName() string {
return nicify(r.ShortCode)
}

func (r Rule) CanCheck() bool {
return r.Check != nil
}

func (r Rule) Evaluate(s *state.State) Results {
if !r.CanCheck() {
return nil
}
results := r.Check(s)
for i := range results {
results[i].SetRule(r)
}
return results
}

var acronyms = []string{
"acl",
"alb",
Expand Down

0 comments on commit 7ccc467

Please sign in to comment.