diff --git a/providers/gandiv5/convert.go b/providers/gandiv5/convert.go index 0187a756c..cfcf79232 100644 --- a/providers/gandiv5/convert.go +++ b/providers/gandiv5/convert.go @@ -4,6 +4,7 @@ package gandiv5 import ( "fmt" + "github.com/go-gandi/go-gandi/livedns" "github.com/StackExchange/dnscontrol/v3/models" @@ -11,7 +12,7 @@ import ( ) // nativeToRecord takes a DNS record from Gandi and returns a native RecordConfig struct. -func nativeToRecords(n livedns.DomainRecord, origin string) (rcs []*models.RecordConfig) { +func nativeToRecords(n livedns.DomainRecord, origin string) (rcs []*models.RecordConfig, err error) { // Gandi returns all the values for a given label/rtype pair in each // livedns.DomainRecord. In other words, if there are multiple A @@ -24,19 +25,24 @@ func nativeToRecords(n livedns.DomainRecord, origin string) (rcs []*models.Recor Original: n, } rc.SetLabel(n.RrsetName, origin) + switch rtype := n.RrsetType; rtype { case "ALIAS": rc.Type = "ALIAS" - rc.SetTarget(value) - default: // "A", "AAAA", "CAA", "DS", "NS", "CNAME", "MX", "PTR", "SRV", "TXT" - if err := rc.PopulateFromString(rtype, value, origin); err != nil { - panic(fmt.Errorf("unparsable record received from gandi: %w", err)) - } + err = rc.SetTarget(value) + case "TXT": + err = rc.SetTargetTXTfromRFC1035Quoted(value) + default: + err = rc.PopulateFromString(rtype, value, origin) } + if err != nil { + return nil, fmt.Errorf("unparsable record received from gandi: %w", err) + } + rcs = append(rcs, rc) } - return rcs + return rcs, nil } func recordsToNative(rcs []*models.RecordConfig, origin string) []livedns.DomainRecord { diff --git a/providers/gandiv5/gandi_v5Provider.go b/providers/gandiv5/gandi_v5Provider.go index 61416f148..cc624c80a 100644 --- a/providers/gandiv5/gandi_v5Provider.go +++ b/providers/gandiv5/gandi_v5Provider.go @@ -163,7 +163,11 @@ func (client *gandiv5Provider) GetZoneRecords(domain string) (models.Records, er // Convert them to DNScontrol's native format: existingRecords := []*models.RecordConfig{} for _, rr := range records { - existingRecords = append(existingRecords, nativeToRecords(rr, domain)...) + rrs, err := nativeToRecords(rr, domain) + if err != nil { + return nil, err + } + existingRecords = append(existingRecords, rrs...) } return existingRecords, nil