-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (64 loc) · 1.56 KB
/
main.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
package main
import (
"flag"
"log"
"os"
"path/filepath"
"strings"
"snorba.art/hugo/dns-yml/mapper"
"snorba.art/hugo/dns-yml/util"
)
const mapperPDNS = "pdns"
const mapperScaleway = "scaleway"
const mapperDry = "dry"
var mappers = []string{mapperPDNS, mapperScaleway, mapperDry}
func main() {
cmd := flag.NewFlagSet("dns-yml", flag.ExitOnError)
mapperFlag := cmd.String(
"mapper",
"scaleway",
"Mapper to use. Use the \"dry\" mapper to check the config without persisting it. Available mappers: "+strings.Join(mappers, ", "),
)
help := cmd.Bool("help", false, "Show this help")
err := cmd.Parse(os.Args[1:])
if err != nil {
log.Fatal(err)
}
if !util.SliceContainsString(mappers, *mapperFlag) {
log.Printf("Invalid mapper parameter %s", *mapperFlag)
cmd.Usage()
os.Exit(1)
}
if *help {
cmd.Usage()
os.Exit(0)
}
definitionPath := cmd.Arg(0)
if definitionPath == "" {
cmd.Usage()
os.Exit(1)
}
definitionReader, err := os.Open(definitionPath)
var dnsMapper mapper.Mapper
if *mapperFlag == mapperPDNS {
dnsMapper, err = mapper.NewPDNSMapper(os.Getenv)
if err != nil {
log.Fatal(err)
}
} else if *mapperFlag == mapperScaleway {
dnsMapper, err = mapper.NewScalewayMapper(os.Getenv)
if err != nil {
log.Fatal(err)
}
} else if *mapperFlag == mapperDry {
dnsMapper, err = mapper.NewDryMapper(os.Getenv)
if err != nil {
log.Fatal(err)
}
}
err = dnsMapper.MapYaml(filepath.Dir(definitionPath), definitionReader)
if err != nil {
log.Fatal(err)
}
log.Printf("Successfully finished execution of %s mapper", *mapperFlag)
}