-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
63 lines (55 loc) · 1.11 KB
/
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
54
55
56
57
58
59
60
61
62
63
package main
import (
"compress/gzip"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"gopkg.in/yaml.v2"
)
var (
defaultHomeDir = AppDataDir("multus", false)
)
type BackupConfig struct {
Group string
MaxIntervals uint16
GZLevel int
PubkeyFile string
Paths []string
Excludes []string
rExcludes []*regexp.Regexp
}
type RestoreConfig struct {
SecretFile string
}
type config struct {
Debug bool
DryRun bool
Profile bool
BackupPath string
Backup BackupConfig
Restore RestoreConfig
}
func loadConfig() (*config, error) {
if err := os.MkdirAll(defaultHomeDir, 0700); err != nil {
return nil, err
}
configPath := filepath.Join(defaultHomeDir, "multus.conf")
configFile, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
cfg := config{
Backup: BackupConfig{
GZLevel: gzip.DefaultCompression,
},
}
if err = yaml.UnmarshalStrict(configFile, &cfg); err != nil {
return nil, err
}
for _, exclude := range cfg.Backup.Excludes {
cfg.Backup.rExcludes = append(cfg.Backup.rExcludes,
regexp.MustCompile(exclude))
}
return &cfg, nil
}