1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Check for duplicate records much earlier (#467)

* Check for duplicate records much earlier.

* Change GetTargetDiffable to ToDiffable

* fixup!
This commit is contained in:
Tom Limoncelli
2019-04-22 15:41:39 -04:00
committed by GitHub
parent b19074e6dc
commit 61a00a7d7e
4 changed files with 98 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package models
import (
"fmt"
"log"
"sort"
"strings"
"github.com/miekg/dns"
@@ -176,6 +177,31 @@ func (rc *RecordConfig) GetLabelFQDN() string {
return rc.NameFQDN
}
// ToDiffable returns a string that is comparable by a differ.
// extraMaps: a list of maps that should be included in the comparison.
func (rc *RecordConfig) ToDiffable(extraMaps ...map[string]string) string {
content := fmt.Sprintf("%v ttl=%d", rc.GetTargetCombined(), rc.TTL)
for _, valueMap := range extraMaps {
// sort the extra values map keys to perform a deterministic
// comparison since Golang maps iteration order is not guaranteed
// FIXME(tlim) The keys of each map is sorted per-map, not across
// all maps. This may be intentional since we'd have no way to
// deal with duplicates.
keys := make([]string, 0)
for k := range valueMap {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := valueMap[k]
content += fmt.Sprintf(" %s=%s", k, v)
}
}
return content
}
// ToRR converts a RecordConfig to a dns.RR.
func (rc *RecordConfig) ToRR() dns.RR {