Skip to content

Commit

Permalink
parse the rules
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Sep 9, 2018
1 parent 6a14737 commit 5fb411d
Show file tree
Hide file tree
Showing 16 changed files with 3,264 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions rules/rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package rules

import (
"fmt"
"io/ioutil"

"github.com/BurntSushi/toml"
"github.com/jessfraz/bpfd/types"
)

// Parse parses the rules files and returns an array of rules for each program.
func Parse(files ...string) (map[string][]types.Rule, error) {
rules := map[string][]types.Rule{}

for _, file := range files {
b, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("reading file %s failed: %v", file, err)
}

var rule types.Rule
if _, err := toml.Decode(string(b), &rule); err != nil {
return nil, fmt.Errorf("decoding file %s as rule failed: %v", file, err)
}

rules[rule.Program] = append(rules[rule.Program], rule)
}

return rules, nil
}
21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5fb411d

Please sign in to comment.