From eb42900019b0fc68e1f45811978aec04277684c4 Mon Sep 17 00:00:00 2001 From: Clint Olson Date: Thu, 5 Sep 2024 13:53:46 -0700 Subject: [PATCH 1/3] Strip spurious quotes from CreateRecords return value --- provider.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/provider.go b/provider.go index a27830b..14e8763 100644 --- a/provider.go +++ b/provider.go @@ -73,6 +73,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 = dmeRec.Value[1 : len(dmeRec.Value)-1] newRec := recordFromDmeRecord(dmeRec) newRecords = append(newRecords, newRec) } From f30602eb1bd13de1a256e5edc4737e8b6da7c244 Mon Sep 17 00:00:00 2001 From: Clint Olson Date: Thu, 5 Sep 2024 13:54:14 -0700 Subject: [PATCH 2/3] True up record-to-dmerecord translation --- client.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 1f41043..da9fc20 100644 --- a/client.go +++ b/client.go @@ -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" { From f09d7bf1cc43da8b27b99ff45a65847eb7aebe8d Mon Sep 17 00:00:00 2001 From: Clint Olson Date: Thu, 5 Sep 2024 14:55:23 -0700 Subject: [PATCH 3/3] Switch to a method that won't break if DNSMadeEasy fixes the extra quotes --- provider.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/provider.go b/provider.go index 14e8763..cb88c2b 100644 --- a/provider.go +++ b/provider.go @@ -5,6 +5,7 @@ import ( "fmt" "slices" "strconv" + "strings" "sync" dme "github.com/john-k/dnsmadeeasy" @@ -74,7 +75,7 @@ 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 = dmeRec.Value[1 : len(dmeRec.Value)-1] + dmeRec.Value = strings.Trim(dmeRec.Value, "\"") newRec := recordFromDmeRecord(dmeRec) newRecords = append(newRecords, newRec) }