Skip to content

Commit

Permalink
Use SetTargetTXT in GetZoneRecords
Browse files Browse the repository at this point in the history
This fixes the behavior documented in StackExchange#1622

Also apply cleanup to GetZoneRecords
  • Loading branch information
onlyhavecans committed Jul 14, 2022
1 parent 46613a9 commit a4f71bd
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions providers/dnsimple/dnsimpleProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
"sort"
"strconv"
"strings"
Expand All @@ -14,6 +13,7 @@ import (

"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
"github.com/StackExchange/dnscontrol/v3/providers"
)
Expand Down Expand Up @@ -77,51 +77,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)
}

Expand Down

0 comments on commit a4f71bd

Please sign in to comment.