Fix parsing of MX and SRV records to use Vultr's priority field
This commit is contained in:
parent
62cb30921f
commit
08474842cc
24
helpers.go
24
helpers.go
@ -2,6 +2,7 @@ package vultr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/libdns/libdns"
|
||||
@ -23,10 +24,12 @@ func fromAPIRecord(r govultr.DomainRecord, zone string) VultrRecord {
|
||||
name := libdns.RelativeName(r.Name, zone)
|
||||
ttl := time.Duration(r.TTL) * time.Second
|
||||
|
||||
// Vultr uses a custom priority field for MX records
|
||||
// Vultr uses a custom priority field for MX and SRV records
|
||||
data := r.Data
|
||||
if r.Type == "MX" {
|
||||
data = fmt.Sprintf("%d %s", r.Priority, r.Data)
|
||||
} else if r.Type == "SRV" {
|
||||
data = fmt.Sprintf("%d %s", r.Priority, r.Data)
|
||||
}
|
||||
|
||||
return VultrRecord{
|
||||
@ -51,12 +54,29 @@ func fromLibdnsRecord(r libdns.Record, id string) VultrRecord {
|
||||
|
||||
// Converts a libdns.Record to a govultr.DomainRecordReq
|
||||
func toDomainRecordReq(r libdns.Record) govultr.DomainRecordReq {
|
||||
data := r.RR().Data
|
||||
var priority int
|
||||
|
||||
// Vultr uses a custom priority field for MX and SRV records
|
||||
if rec, ok := r.RR().Parse(); ok == nil {
|
||||
if r.RR().Type == "MX" {
|
||||
mx := rec.(libdns.MX)
|
||||
priority = int(mx.Preference)
|
||||
data = mx.Target
|
||||
} else if r.RR().Type == "SRV" {
|
||||
srv := rec.(libdns.SRV)
|
||||
priority = int(srv.Priority)
|
||||
data = data[strings.Index(data, " ")+1:]
|
||||
}
|
||||
}
|
||||
|
||||
rr := r.RR()
|
||||
return govultr.DomainRecordReq{
|
||||
Name: rr.Name,
|
||||
Type: rr.Type,
|
||||
TTL: int(rr.TTL.Seconds()),
|
||||
Data: rr.Data,
|
||||
Data: data,
|
||||
Priority: &priority,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user