-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule.go
54 lines (46 loc) · 1.09 KB
/
rule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package types
import "github.com/avahidi/molly/util"
const (
ActionModeNormal = 0
ActionModeIgnore = 1
ActionModeExit = 2
RulePassMin = 0
RulePassMax = 2
)
type Action struct {
Mode int
Action Expression
}
// Rule defines a single rule
type Rule struct {
ID string
Metadata *util.Register
Parent *Rule `json:"-"` // this will avoid circular marshalling
Children []*Rule
Conditions []Expression
Actions []Action
Variables map[string]Expression
}
// NewRule creates a new rule with the given ID
func NewRule(id string) *Rule {
return &Rule{
ID: id,
Metadata: util.NewRegister(),
Variables: make(map[string]Expression),
}
}
// RuleSet represents a group of rules parsed from one or more file
// it also includes the rule hierarchy
type RuleSet struct {
Files map[string][]*Rule
Top map[string]*Rule
Flat map[string]*Rule
}
// NewRuleSet creates a new set of rules, to be populated by a rule scanner
func NewRuleSet() *RuleSet {
return &RuleSet{
Files: make(map[string][]*Rule),
Top: make(map[string]*Rule),
Flat: make(map[string]*Rule),
}
}