mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
GANDI_V5: better error handling (#1639)
* GANDI_V5: better error handling * use newer parsers * fixup!
This commit is contained in:
@@ -4,6 +4,7 @@ package gandiv5
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/go-gandi/go-gandi/livedns"
|
"github.com/go-gandi/go-gandi/livedns"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
@@ -11,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// nativeToRecord takes a DNS record from Gandi and returns a native RecordConfig struct.
|
// 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
|
// Gandi returns all the values for a given label/rtype pair in each
|
||||||
// livedns.DomainRecord. In other words, if there are multiple A
|
// 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,
|
Original: n,
|
||||||
}
|
}
|
||||||
rc.SetLabel(n.RrsetName, origin)
|
rc.SetLabel(n.RrsetName, origin)
|
||||||
|
|
||||||
switch rtype := n.RrsetType; rtype {
|
switch rtype := n.RrsetType; rtype {
|
||||||
case "ALIAS":
|
case "ALIAS":
|
||||||
rc.Type = "ALIAS"
|
rc.Type = "ALIAS"
|
||||||
rc.SetTarget(value)
|
err = rc.SetTarget(value)
|
||||||
default: // "A", "AAAA", "CAA", "DS", "NS", "CNAME", "MX", "PTR", "SRV", "TXT"
|
case "TXT":
|
||||||
if err := rc.PopulateFromString(rtype, value, origin); err != nil {
|
err = rc.SetTargetTXTfromRFC1035Quoted(value)
|
||||||
panic(fmt.Errorf("unparsable record received from gandi: %w", err))
|
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)
|
rcs = append(rcs, rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return rcs
|
return rcs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordsToNative(rcs []*models.RecordConfig, origin string) []livedns.DomainRecord {
|
func recordsToNative(rcs []*models.RecordConfig, origin string) []livedns.DomainRecord {
|
||||||
|
@@ -163,7 +163,11 @@ func (client *gandiv5Provider) GetZoneRecords(domain string) (models.Records, er
|
|||||||
// Convert them to DNScontrol's native format:
|
// Convert them to DNScontrol's native format:
|
||||||
existingRecords := []*models.RecordConfig{}
|
existingRecords := []*models.RecordConfig{}
|
||||||
for _, rr := range records {
|
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
|
return existingRecords, nil
|
||||||
|
Reference in New Issue
Block a user