Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

feat(rule): add a method for evaluation #1482

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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