-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
53 lines (45 loc) · 1021 Bytes
/
config.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
package brimcap
import (
_ "embed"
"fmt"
"os"
"github.com/brimdata/brimcap/analyzer"
"gopkg.in/yaml.v3"
)
//go:embed suricata.zed
var suricatashaper string
var DefaultConfig = Config{
Analyzers: []analyzer.Config{
{
Name: "suricata",
Cmd: "suricatarunner",
Globs: []string{"*.json"},
Shaper: suricatashaper,
},
{
Name: "zeek",
Cmd: "zeekrunner",
},
},
}
type Config struct {
RootPath string `yaml:"root,omitempty"`
Analyzers []analyzer.Config `yaml:"analyzers,omitempty"`
}
func LoadConfigYAML(path string) (Config, error) {
b, err := os.ReadFile(path)
if err != nil {
return Config{}, fmt.Errorf("error loading config file: %w", err)
}
s := os.ExpandEnv(string(b))
var c Config
err = yaml.Unmarshal([]byte(s), &c)
if err != nil {
err = fmt.Errorf("error loading config file: %w", err)
}
return c, err
}
func (c Config) Root() Root { return Root(c.RootPath) }
func (c Config) Validate() error {
return analyzer.Configs(c.Analyzers).Validate()
}