MCPcopy
hub / github.com/evilsocket/opensnitch / Load

Method Load

daemon/rule/loader.go:121–156  ·  view source on GitHub ↗

Load loads rules files from disk.

(path string)

Source from the content-addressed store, hash-verified

119
120// Load loads rules files from disk.
121func (l *Loader) Load(path string) error {
122 log.Debug("rules.Loader.Load(): %s", path)
123 if core.Exists(path) == false {
124 return fmt.Errorf("Path '%s' does not exist\nCreate it if you want to save rules to disk", path)
125 }
126 path, err := core.ExpandPath(path)
127 if err != nil {
128 return fmt.Errorf("Error accessing rules path: %s.\nCreate it if you want to save rules to disk", err)
129 }
130
131 expr := filepath.Join(path, "*.json")
132 matches, err := filepath.Glob(expr)
133 if err != nil {
134 return fmt.Errorf("Error globbing '%s': %s", expr, err)
135 }
136
137 l.Path = path
138 if len(l.rules) == 0 {
139 l.rules = make(map[string]*Rule)
140 }
141
142 for _, fileName := range matches {
143 log.Debug("Reading rule from %s", fileName)
144
145 if err := l.loadRule(fileName); err != nil {
146 log.Warning("%s", err)
147 continue
148 }
149 }
150
151 if l.liveReload && l.isLiveReloadRunning() == false {
152 go l.liveReloadWorker()
153 }
154
155 return nil
156}
157
158// Add adds a rule to the list of rules, and optionally saves it to disk.
159func (l *Loader) Add(rule *Rule, saveToDisk bool) error {

Callers 12

TestRuleLoaderFunction · 0.95
TestLiveReloadFunction · 0.95
ReloadMethod · 0.95
loadDiskConfigurationFunction · 0.45
InsertRuleMethod · 0.45
AddRuleMethod · 0.45
delRulesByKeyMethod · 0.45
GetChainFunction · 0.45
AddChainMethod · 0.45
AddInterceptionChainsMethod · 0.45
loadDiskConfigurationMethod · 0.45
reloadConfigurationMethod · 0.45

Calls 3

loadRuleMethod · 0.95
isLiveReloadRunningMethod · 0.95
liveReloadWorkerMethod · 0.95

Tested by 2

TestRuleLoaderFunction · 0.76
TestLiveReloadFunction · 0.76