mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 08:34:40 +01:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
52d46a3a2c
commit
3a5932de38
2 changed files with 5 additions and 14 deletions
|
@ -64,6 +64,7 @@ func (l *Loader) Load(path string) error {
|
|||
l.rules = make(map[string]*Rule)
|
||||
|
||||
for _, fileName := range matches {
|
||||
log.Debug("Reading rule from %s", fileName)
|
||||
raw, err := ioutil.ReadFile(fileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error while reading %s: %s", fileName, err)
|
||||
|
@ -76,6 +77,8 @@ func (l *Loader) Load(path string) error {
|
|||
return fmt.Errorf("Error while parsing rule from %s: %s", fileName, err)
|
||||
}
|
||||
|
||||
r.Operator.Compile()
|
||||
|
||||
log.Debug("Loaded rule from %s: %s", fileName, r.String())
|
||||
l.rules[r.Name] = &r
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package rule
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
|
@ -45,22 +44,11 @@ func NewOperator(t Type, o Operand, data string) Operator {
|
|||
Operand: o,
|
||||
Data: data,
|
||||
}
|
||||
op.compile()
|
||||
op.Compile()
|
||||
return op
|
||||
}
|
||||
|
||||
func (o *Operator) UnmarshalJSON(b []byte) error {
|
||||
err := json.Unmarshal(b, o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// make sure it's ready to be used after being
|
||||
// deserialized from a json rule file
|
||||
o.compile()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Operator) compile() {
|
||||
func (o *Operator) Compile() {
|
||||
if o.Type == Simple {
|
||||
o.cb = o.simpleCmp
|
||||
} else if o.Type == Regexp {
|
||||
|
|
Loading…
Add table
Reference in a new issue