-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
54 lines (45 loc) · 1.12 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
package main
import (
"os"
"github.com/miekg/dns"
"gopkg.in/yaml.v3"
)
type Config struct {
DSN string `yaml:"dsn"`
Forward map[string]ServerDefinition `yaml:"forward zones"`
Reverse map[string]ServerDefinition `yaml:"reverse zones"`
}
type ServerDefinition struct {
Server string `yaml:"server"`
Algo string `yaml:"algo"`
KeyName string `yaml:"keyname"`
Secret string `yaml:"secret"`
}
func (s *Config) Load(configfile string) *Config {
data, err := os.ReadFile(configfile)
if err != nil {
panic(err)
}
return s.parse(data)
}
func (s *Config) parse(configdata []byte) *Config {
err := yaml.Unmarshal(configdata, &s)
if err != nil {
panic(err)
// return nil, err
}
// Sanitization fwd and reverse
for _, zonemap := range []map[string]ServerDefinition{s.Forward, s.Reverse} {
for zonename, serverdef := range zonemap {
if !dns.IsFqdn(serverdef.KeyName) {
serverdef.KeyName = dns.Fqdn(serverdef.KeyName)
zonemap[zonename] = serverdef
}
if !dns.IsFqdn(zonename) {
zonemap[dns.Fqdn(zonename)] = zonemap[zonename]
delete(zonemap, zonename)
}
}
}
return s
}