Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libdns::Record to dnsmadeeasy::Record translation #4

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,28 @@ func recordFromDmeRecord(dmeRecord dme.Record) libdns.Record {

func dmeRecordFromRecord(record libdns.Record) (dme.Record, error) {
var dmeRecord dme.Record
id, err := strconv.Atoi(record.ID)
if err != nil {
return dme.Record{}, err
var id int
var err error
// Since dmeRecord.ID is set to `json:"id,omitempty"`, this properly preserves empty values
if record.ID == "" {
id = 0
} else {
id, err = strconv.Atoi(record.ID)
if err != nil {
return dme.Record{}, err
}
}
dmeRecord.ID = id
dmeRecord.Name = record.Name
dmeRecord.Type = record.Type
dmeRecord.Value = record.Value
dmeRecord.Ttl = int(record.TTL)
// DNSMadeEasy fails to accept zero TTL, so use a default value
if dmeRecord.Ttl == 0 {
dmeRecord.Ttl = 120
}
// Likewise, DNSMadeEasy doesn't accept a blank GtdLocation
dmeRecord.GtdLocation = "DEFAULT"
if record.Type == "MX" {
dmeRecord.MxLevel = int(record.Priority)
} else if record.Type == "SRV" {
Expand Down
3 changes: 3 additions & 0 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"slices"
"strconv"
"strings"
"sync"

dme "github.com/john-k/dnsmadeeasy"
Expand Down Expand Up @@ -73,6 +74,8 @@ func createRecords(client dme.Client, zone string, records []libdns.Record) ([]l

var newRecords []libdns.Record
for _, dmeRec := range newDmeRecords {
// The client.CreateRecords call wraps the value in spurious quotes
dmeRec.Value = strings.Trim(dmeRec.Value, "\"")
newRec := recordFromDmeRecord(dmeRec)
newRecords = append(newRecords, newRec)
}
Expand Down