Fix 312 - rewrite IGNORE to use GetLabel (#331)

As discussed after the refactor to generalize the use of `GetLabel`,
this change makes IGNORE also use `GetLabel`.
This commit is contained in:
Brice Figureau 2018-03-08 15:43:54 +01:00 committed by Tom Limoncelli
parent dfd015e5cd
commit 2d7a48950c

View file

@ -6,7 +6,6 @@ import (
"sort" "sort"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/miekg/dns/dnsutil"
) )
// Correlation stores a difference between two domains. // Correlation stores a difference between two domains.
@ -75,16 +74,16 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
existingByNameAndType := map[key][]*models.RecordConfig{} existingByNameAndType := map[key][]*models.RecordConfig{}
desiredByNameAndType := map[key][]*models.RecordConfig{} desiredByNameAndType := map[key][]*models.RecordConfig{}
for _, e := range existing { for _, e := range existing {
if d.matchIgnored(e.NameFQDN, d.dc.Name) { if d.matchIgnored(e.GetLabel()) {
log.Printf("Ignoring record %s %s due to IGNORE", e.NameFQDN, e.Type) log.Printf("Ignoring record %s %s due to IGNORE", e.GetLabel(), e.Type)
} else { } else {
k := key{e.NameFQDN, e.Type} k := key{e.NameFQDN, e.Type}
existingByNameAndType[k] = append(existingByNameAndType[k], e) existingByNameAndType[k] = append(existingByNameAndType[k], e)
} }
} }
for _, dr := range desired { for _, dr := range desired {
if d.matchIgnored(dr.NameFQDN, d.dc.Name) { if d.matchIgnored(dr.GetLabel()) {
panic(fmt.Sprintf("Trying to update/add IGNOREd record: %s %s", dr.NameFQDN, dr.Type)) panic(fmt.Sprintf("Trying to update/add IGNOREd record: %s %s", dr.GetLabel(), dr.Type))
} else { } else {
k := key{dr.NameFQDN, dr.Type} k := key{dr.NameFQDN, dr.Type}
desiredByNameAndType[k] = append(desiredByNameAndType[k], dr) desiredByNameAndType[k] = append(desiredByNameAndType[k], dr)
@ -215,11 +214,9 @@ func sortedKeys(m map[string]*models.RecordConfig) []string {
return s return s
} }
func (d *differ) matchIgnored(nameFQDN, domain string) bool { func (d *differ) matchIgnored(name string) bool {
// ignored labels are not fqdn
name := dnsutil.TrimDomainName(nameFQDN, domain)
for _, tst := range d.dc.IgnoredLabels { for _, tst := range d.dc.IgnoredLabels {
if name == tst || nameFQDN == tst { if name == tst {
return true return true
} }
} }