From a1366210526caaed5469d631b21afea5214d8dcc Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Sat, 28 Jan 2023 11:10:02 -0500 Subject: [PATCH] Improve warnings related to _ and TTLs (#1989) --- pkg/normalize/validate.go | 16 +++++++++++----- providers/cloudflare/cloudflareProvider.go | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/normalize/validate.go b/pkg/normalize/validate.go index 0d27e13b3..a6195af6c 100644 --- a/pkg/normalize/validate.go +++ b/pkg/normalize/validate.go @@ -126,13 +126,13 @@ func checkLabel(label string, rType string, target, domain string, meta map[stri } // Don't warn for records that start with _ // See https://github.com/StackExchange/dnscontrol/issues/829 - if strings.HasPrefix(label, "_") || strings.Contains(label, "._") { + if strings.HasPrefix(label, "_") || strings.Contains(label, "._") || strings.HasPrefix(label, "sql-") { return nil } // Otherwise, warn. if strings.ContainsRune(label, '_') { - return Warning{fmt.Errorf("label %s.%s contains an underscore", label, domain)} + return Warning{fmt.Errorf("label %s.%s contains \"_\" (can't be used in a URL)", label, domain)} } return nil @@ -598,9 +598,15 @@ func checkLabelHasMultipleTTLs(records []*models.RecordConfig) (errs []error) { } for label := range m { - // if after the uniq() pass we still have more than one ttl, it means we have multiple TTLs for that label - if len(uniq(m[label])) > 1 { - errs = append(errs, Warning{fmt.Errorf("multiple TTLs detected for: %s. This should be avoided", label)}) + // The RFCs say that all records at a particular label should have + // the same TTL. Most providers don't care, and if they do the + // code usually picks the lowest TTL for all of them. + // + // If after the uniq() pass we still have more than one ttl, it + // means we have multiple TTLs for that label. + u := uniq(m[label]) + if len(u) > 1 { + errs = append(errs, Warning{fmt.Errorf("label with multipe TTLs: %s (%v)", label, u)}) } } return errs diff --git a/providers/cloudflare/cloudflareProvider.go b/providers/cloudflare/cloudflareProvider.go index e0be04078..400599321 100644 --- a/providers/cloudflare/cloudflareProvider.go +++ b/providers/cloudflare/cloudflareProvider.go @@ -421,7 +421,7 @@ func (c *cloudflareProvider) preprocessConfig(dc *models.DomainConfig) error { rec.TTL = 1 } if rec.TTL != 1 && rec.TTL < 60 { - rec.TTL = 60 + rec.TTL = 60 } if rec.Type != "A" && rec.Type != "CNAME" && rec.Type != "AAAA" && rec.Type != "ALIAS" {