-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (60 loc) · 1.51 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
package main
import (
"fmt"
"log"
"os"
"strings"
dns "github.com/searchspring.com/spf-flatten/dns"
r53 "github.com/searchspring.com/spf-flatten/route53"
)
func main() {
envs := map[string]string{
"aws_Region": os.Getenv("AWS_REGION"),
"template_Domain": os.Getenv("TEMPLATE_DOMAIN"),
"update_Domain": os.Getenv("UPDATE_DOMAIN"),
"test_IP": os.Getenv("TEST_IP"),
"zone_ID": os.Getenv("ZONEID"),
}
for k, v := range envs {
if v == "" {
log.Fatalf("You must test '%s' ENV variable.", strings.ToUpper(k))
}
}
// Retrieve SPF record for the domain
d := dns.New()
record, err := d.DNSLookupSPF(envs["template_Domain"])
if err != nil {
log.Fatalf("DNSLookupSPF: %s", err)
}
d.UpdateDomain = envs["update_Domain"]
d.TestIP = envs["test_IP"]
// Flatten SPF record
flat, err := d.FlattenSPF(*record)
if err != nil {
log.Fatal(err)
}
// Split up records into top level record and include records
txtRecs := d.SplitSPFRecords(flat)
// Check records for validity
_, err = d.SPFRecordsAreValid(txtRecs)
if err != nil {
log.Fatal(err)
}
// Update Route53
r53updater, err := r53.New(r53.Route53Updater{
Region: envs["aws_Region"],
UpdateDomain: envs["update_Domain"],
Zoneid: envs["zone_ID"],
DryRun: true,
})
if err != nil {
log.Fatal(err)
}
for domain, rec := range txtRecs {
fmt.Printf("%v\tTXT\t%v\n\n", domain, rec)
err = r53updater.UpdateTXTRecord(domain, rec)
if err != nil {
log.Printf("Update Record Fail: %v\n", err)
}
}
}