restructure config to allow user credentials to update multiple records

This commit separates user credentials from resource record configs to
allow user credentials to be used for multiple records instead of one.
This commit is contained in:
Thomas Preisner 2021-09-08 14:55:04 +02:00
parent 7f1500d53d
commit 451776bde0
4 changed files with 116 additions and 38 deletions

View file

@ -11,7 +11,7 @@ import (
func requiresRRUpdate(entry *RRConfig, addr net.IP) bool {
// TODO: use custom resolver to query authoritive nameserver instead of
// local resolver
addrs, err := net.LookupIP(entry.Hostname)
addrs, err := net.LookupIP(entry.Recordname)
if err != nil {
log.Printf("dns lookup failed: %s", err)
// enforce update, it's better than not trying at all
@ -36,11 +36,11 @@ func updateRR(entry *RRConfig, addr net.IP) error {
func generateQuery(entry *RRConfig, addr net.IP) string {
var q strings.Builder
fmt.Fprintf(&q, "key %s\n", entry.Tsigkey)
fmt.Fprintf(&q, "key %s:%s %s\n", entry.Tsigalgo, entry.Tsigid, entry.Tsigkey)
fmt.Fprintf(&q, "server %s\n", entry.Nameserver)
fmt.Fprintf(&q, "zone %s\n", entry.Zonename)
// TODO: check if addr is ipv4 or ipv6 (-> update A or AAAA)
fmt.Fprintf(&q, "add %s. %d A %s\n", entry.Hostname, entry.Ttl, addr.String())
fmt.Fprintf(&q, "add %s. %d A %s\n", entry.Recordname, entry.Ttl, addr.String())
fmt.Fprintf(&q, "send\n")
return q.String()