mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
DNSIMPLE: Fix TXT Handling, Second Edition (#1624)
* Fix typo and add sandbox information * Use SetTargetTXT in GetZoneRecords This fixes the behavior documented in #1622 Also apply cleanup to GetZoneRecords * Remove SetTargetTXT, does not work in all tests * Set The most correct TXT handling * Well, There's your problem * Add an audit and test for unpaired quotes * Add some commentary Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -14,7 +13,7 @@ import (
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
|
||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
||||
)
|
||||
|
||||
@@ -77,51 +76,54 @@ func (c *dnsimpleProvider) GetZoneRecords(domain string) (models.Records, error)
|
||||
if r.Type == "SOA" {
|
||||
continue
|
||||
}
|
||||
|
||||
if r.Name == "" {
|
||||
r.Name = "@"
|
||||
}
|
||||
|
||||
if r.Type == "CNAME" || r.Type == "MX" || r.Type == "ALIAS" || r.Type == "NS" {
|
||||
r.Content += "."
|
||||
}
|
||||
|
||||
// DNSimple adds TXT records that mirror the alias records.
|
||||
// They manage them on ALIAS updates, so pretend they don't exist
|
||||
if r.Type == "TXT" && strings.HasPrefix(r.Content, "ALIAS for ") {
|
||||
continue
|
||||
}
|
||||
|
||||
rec := &models.RecordConfig{
|
||||
TTL: uint32(r.TTL),
|
||||
Original: r,
|
||||
}
|
||||
rec.SetLabel(r.Name, domain)
|
||||
|
||||
var err error
|
||||
switch rtype := r.Type; rtype {
|
||||
case "DNSKEY", "CDNSKEY", "CDS":
|
||||
continue
|
||||
case "ALIAS", "URL":
|
||||
rec.Type = r.Type
|
||||
if err := rec.SetTarget(r.Content); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from dnsimple: %w", err)
|
||||
}
|
||||
err = rec.SetTarget(r.Content)
|
||||
case "DS":
|
||||
if err := rec.SetTargetDSString(r.Content); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from dnsimple: %w", err)
|
||||
}
|
||||
err = rec.SetTargetDSString(r.Content)
|
||||
case "MX":
|
||||
if err := rec.SetTargetMX(uint16(r.Priority), r.Content); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from dnsimple: %w", err)
|
||||
}
|
||||
err = rec.SetTargetMX(uint16(r.Priority), r.Content)
|
||||
case "SRV":
|
||||
parts := strings.Fields(r.Content)
|
||||
if len(parts) == 3 {
|
||||
r.Content += "."
|
||||
}
|
||||
if err := rec.SetTargetSRVPriorityString(uint16(r.Priority), r.Content); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from dnsimple: %w", err)
|
||||
}
|
||||
err = rec.SetTargetSRVPriorityString(uint16(r.Priority), r.Content)
|
||||
case "TXT":
|
||||
err = rec.SetTargetTXT(r.Content)
|
||||
default:
|
||||
if err := rec.PopulateFromString(r.Type, r.Content, domain); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from dnsimple: %w", err)
|
||||
}
|
||||
err = rec.PopulateFromString(r.Type, r.Content, domain)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from dnsimple: %w", err)
|
||||
}
|
||||
|
||||
cleanedRecords = append(cleanedRecords, rec)
|
||||
}
|
||||
|
||||
@@ -152,7 +154,6 @@ func (c *dnsimpleProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
|
||||
|
||||
// Normalize
|
||||
models.PostProcessRecords(actual)
|
||||
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
|
||||
|
||||
differ := diff.New(dc)
|
||||
_, create, del, modify, err := differ.IncrementalDiff(actual)
|
||||
@@ -592,7 +593,7 @@ func getTargetRecordContent(rc *models.RecordConfig) string {
|
||||
case "SRV":
|
||||
return fmt.Sprintf("%d %d %s", rc.SrvWeight, rc.SrvPort, rc.GetTargetField())
|
||||
case "TXT":
|
||||
return rc.GetTargetRFC1035Quoted()
|
||||
return rc.GetTargetTXTJoined()
|
||||
default:
|
||||
return rc.GetTargetField()
|
||||
}
|
||||
|
Reference in New Issue
Block a user