-
Notifications
You must be signed in to change notification settings - Fork 1
/
definition.go
82 lines (75 loc) · 2.2 KB
/
definition.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2019 Luis Guillén Civera <luisguillenc@gmail.com>. View LICENSE.
package builder
import (
"encoding/json"
"io/ioutil"
"os"
)
//PluginDef is used for construct plugins
type PluginDef struct {
// Name must exist and be unique in databases for its correct operation
Name string `json:"name"`
// Class defines the class
Class string `json:"class"`
// Disabled
Disabled bool `json:"disabled"`
// Services is a map of services used by plugin
Services map[string]string `json:"services,omitempty"`
// Actions is a list of actions
Actions []ActionDef `json:"actions,omitempty"`
// Opts allow optional fields
Opts map[string]interface{} `json:"opts,omitempty"`
}
// ActionDef is used for construct actions
type ActionDef struct {
// Name must exist and be unique in databases for its correct operation
Name string `json:"name"`
// Class defines the class
Class string `json:"class"`
// Disabled
Disabled bool `json:"disabled"`
// Services is a map of services used by plugin
Services map[string]string `json:"services,omitempty"`
// Rules is a list of ruleset definitions
Rules []RuleItemDef `json:"rules,omitempty"`
// OnError stores on error verdict
OnError string `json:"onerror,omitempty"`
// Opts allow optional fields
Opts map[string]interface{} `json:"opts,omitempty"`
}
// RuleItemDef defines a set of rules
type RuleItemDef struct {
// When defines condition
When string `json:"when"`
// Rule stores definition
Rule RuleDef `json:"rule"`
}
// RuleDef stores information about rules
type RuleDef struct {
// Merge option
Merge bool `json:"merge,omitempty"`
// Event stores event level
Event string `json:"event,omitempty"`
// Log enable logging in action
Log bool `json:"log"`
// Verdict stores verdict to firewall processors
Verdict string `json:"verdict,omitempty"`
}
// PluginDefsFromFile creates a slice of PluginDef from a file in json format.
func PluginDefsFromFile(path string) ([]PluginDef, error) {
var plugins []PluginDef
f, err := os.Open(path)
defer f.Close()
if err != nil {
return nil, err
}
byteValue, err := ioutil.ReadAll(f)
if err != nil {
return nil, err
}
err = json.Unmarshal(byteValue, &plugins)
if err != nil {
return nil, err
}
return plugins, nil
}