From caa71c4031843c73fad06dd152e918497c2dccf6 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Thu, 20 Jul 2017 18:59:09 -0400 Subject: [PATCH] Mark RecordConfig when Target contains multiple embedded fields. --- models/dns.go | 21 +++++++++++++++++++++ providers/google/google.go | 9 +++++---- providers/route53/route53Provider.go | 9 +++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/models/dns.go b/models/dns.go index 1c6766b24..93bc9843c 100644 --- a/models/dns.go +++ b/models/dns.go @@ -72,10 +72,16 @@ type RecordConfig struct { SrvWeight uint16 `json:"srvweight,omitempty"` SrvPort uint16 `json:"srvport,omitempty"` + CombinedTarget bool `json:"omit"` + Original interface{} `json:"-"` // Store pointer to provider-specific record object. Used in diffing. } func (r *RecordConfig) String() (content string) { + if r.CombinedTarget { + return r.Target + } + switch r.Type { case "A", "AAAA", "PTR": content = fmt.Sprintf("%s %s %s %d", r.Type, r.NameFQDN, r.Target, r.TTL) @@ -94,6 +100,9 @@ func (r *RecordConfig) String() (content string) { // Content combines Target and other fields into one string. func (r *RecordConfig) Content() string { + if r.CombinedTarget { + return r.Target + } // If this is a pseudo record, just return the target. if _, ok := dns.StringToType[r.Type]; !ok { @@ -115,6 +124,11 @@ func (r *RecordConfig) Content() string { // MergeToTarget combines "extra" fields into .Target, and zeros the merged fields. func (r *RecordConfig) MergeToTarget() { + if r.CombinedTarget { + pm := strings.Join([]string{"MergeToTarget: Already collapsed: ", r.Name, r.Target}, " ") + panic(pm) + } + // Merge "extra" fields into the Target. r.Target = r.Content() @@ -123,6 +137,8 @@ func (r *RecordConfig) MergeToTarget() { r.SrvPriority = 0 r.SrvWeight = 0 r.SrvPort = 0 + + r.CombinedTarget = true } /// Convert RecordConfig -> dns.RR. @@ -259,8 +275,13 @@ func (dc *DomainConfig) Punycode() error { func (dc *DomainConfig) CombineMXs() { for _, rec := range dc.Records { if rec.Type == "MX" { + if rec.CombinedTarget { + pm := strings.Join([]string{"CombineMXs: Already collapsed: ", rec.Name, rec.Target}, " ") + panic(pm) + } rec.Target = fmt.Sprintf("%d %s", rec.MxPreference, rec.Target) rec.MxPreference = 0 + rec.CombinedTarget = true } } } diff --git a/providers/google/google.go b/providers/google/google.go index d934c5720..246088ec9 100644 --- a/providers/google/google.go +++ b/providers/google/google.go @@ -116,10 +116,11 @@ func (g *gcloud) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correc oldRRs[keyFor(set)] = set for _, rec := range set.Rrdatas { r := &models.RecordConfig{ - NameFQDN: nameWithoutDot, - Type: set.Type, - Target: rec, - TTL: uint32(set.Ttl), + NameFQDN: nameWithoutDot, + Type: set.Type, + Target: rec, + TTL: uint32(set.Ttl), + CombinedTarget: true, } existingRecords = append(existingRecords, r) } diff --git a/providers/route53/route53Provider.go b/providers/route53/route53Provider.go index 18e2c7bb9..aa9259942 100644 --- a/providers/route53/route53Provider.go +++ b/providers/route53/route53Provider.go @@ -133,10 +133,11 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode continue } r := &models.RecordConfig{ - NameFQDN: unescape(set.Name), - Type: *set.Type, - Target: *rec.Value, - TTL: uint32(*set.TTL), + NameFQDN: unescape(set.Name), + Type: *set.Type, + Target: *rec.Value, + TTL: uint32(*set.TTL), + CombinedTarget: true, } existingRecords = append(existingRecords, r) }