mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
New provider: Loopia DNS service provider (#2140)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
66
providers/loopia/convert.go
Normal file
66
providers/loopia/convert.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package loopia
|
||||
|
||||
// Convert the provider's native record description to models.RecordConfig.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
)
|
||||
|
||||
// nativeToRecord takes a DNS record from Loopia and returns a native RecordConfig struct.
|
||||
func nativeToRecord(zr zoneRecord, origin string, subdomain string) (rc *models.RecordConfig, err error) {
|
||||
record := zr.GetZR()
|
||||
|
||||
rc = &models.RecordConfig{
|
||||
TTL: record.TTL,
|
||||
Original: record,
|
||||
Type: record.Type,
|
||||
}
|
||||
rc.SetLabel(subdomain, origin)
|
||||
rc.SetTarget(record.Rdata)
|
||||
|
||||
switch rtype := record.Type; rtype {
|
||||
case "CAA":
|
||||
err = rc.SetTargetCAAString(record.Rdata)
|
||||
case "MX":
|
||||
err = rc.SetTargetMX(record.Priority, record.Rdata)
|
||||
case "NAPTR":
|
||||
err = rc.SetTargetNAPTRString(record.Rdata)
|
||||
case "TXT":
|
||||
err = rc.SetTargetTXT(record.Rdata)
|
||||
default:
|
||||
err = rc.PopulateFromString(rtype, record.Rdata, origin)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from loopia: %w", err)
|
||||
}
|
||||
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func recordToNative(rc *models.RecordConfig, id ...uint32) paramStruct {
|
||||
//rc is the record from dnscontrol to loopia
|
||||
zrec := zRec{}
|
||||
zrec.Type = rc.Type
|
||||
zrec.TTL = rc.TTL
|
||||
zrec.Rdata = rc.GetTargetCombined()
|
||||
|
||||
if rc.Original != nil {
|
||||
zrec.RecordID = rc.Original.(*zRec).RecordID
|
||||
} else if len(id) > 0 {
|
||||
zrec.RecordID = id[0]
|
||||
}
|
||||
switch zrec.Type {
|
||||
case "TXT":
|
||||
zrec.Rdata = rc.GetTargetTXTJoined()
|
||||
case "MX":
|
||||
zrec.Priority = rc.MxPreference
|
||||
zrec.Rdata = rc.GetTargetField()
|
||||
case "SRV":
|
||||
zrec.Priority = rc.SrvPriority
|
||||
}
|
||||
// fmt.Printf("r2n:zr %+v\n", zrec)
|
||||
|
||||
return zrec.SetPS()
|
||||
}
|
Reference in New Issue
Block a user