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

@@ -387,6 +387,8 @@ func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) {
if err != nil {
errs = append(errs, err)
}
// Check for duplicates
errs = append(errs, checkDuplicates(d.Records)...)
// Validate FQDN consistency
for _, r := range d.Records {
if r.NameFQDN == "" || !strings.HasSuffix(r.NameFQDN, d.Name) {
@@ -416,6 +418,18 @@ func checkCNAMEs(dc *models.DomainConfig) (errs []error) {
return
}
func checkDuplicates(records []*models.RecordConfig) (errs []error) {
seen := map[string]*models.RecordConfig{}
for _, r := range records {
diffable := fmt.Sprintf("%s %s %s", r.GetLabelFQDN(), r.Type, r.ToDiffable())
if seen[diffable] != nil {
errs = append(errs, errors.Errorf("Exact duplicate record found: %s", diffable))
}
seen[diffable] = r
}
return errs
}
func checkProviderCapabilities(dc *models.DomainConfig) error {
types := []struct {
rType string