From ba8ce0b69472836c51915a2d37b9802569fc6b52 Mon Sep 17 00:00:00 2001 From: victories <1463038+victories@users.noreply.github.com> Date: Sat, 11 Oct 2025 20:41:54 +0300 Subject: [PATCH] Fix: Update for libdns v1.0 API compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated rec.Value → rec.RR().Data - Updated rec.Type/Name/TTL → rec.RR().Type/Name/TTL - Updated go.mod to require libdns v1.0.0 - Fixed all type compatibility issues with Caddy v2.10+ --- client.go | 48 ++++++++++++++++++++++++-------------- go.mod | 4 ++-- provider.go | 10 ++++---- txtsanitize/txtsanitize.go | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/client.go b/client.go index 72e315f..849f0b0 100644 --- a/client.go +++ b/client.go @@ -56,15 +56,18 @@ func mergeRRecs(fullZone *zones.Zone, records []libdns.Record) ([]zones.Resource for _, t := range fullZone.ResourceRecordSets { k := key(t.Name, t.Type) if recs, ok := inHash[k]; ok && len(recs) > 0 { - rr := zones.ResourceRecordSet{ + // Convert first record to RR to get TTL + rr0 := recs[0].RR() + + rrset := zones.ResourceRecordSet{ Name: t.Name, Type: t.Type, - TTL: int(recs[0].TTL.Seconds()), + TTL: int(rr0.TTL.Seconds()), ChangeType: zones.ChangeTypeReplace, Comments: t.Comments, Records: make([]zones.Record, len(t.Records)), } - copy(rr.Records, t.Records) + copy(rrset.Records, t.Records) // squash duplicate values dupes := make(map[string]bool) for _, prec := range t.Records { @@ -72,14 +75,15 @@ func mergeRRecs(fullZone *zones.Zone, records []libdns.Record) ([]zones.Resource } // now for our additions for _, rec := range recs { - if !dupes[rec.Value] { - rr.Records = append(rr.Records, zones.Record{ - Content: rec.Value, + recRR := rec.RR() + if !dupes[recRR.Data] { + rrset.Records = append(rrset.Records, zones.Record{ + Content: recRR.Data, }) - dupes[rec.Value] = true + dupes[recRR.Data] = true } } - rrsets = append(rrsets, rr) + rrsets = append(rrsets, rrset) delete(inHash, k) } } @@ -121,7 +125,8 @@ func removeRecords(rRSet zones.ResourceRecordSet, culls []libdns.Record) zones.R return recs } for _, c := range culls { - rRSet.Records = deleteItem(c.Value) + cRR := c.RR() + rRSet.Records = deleteItem(cRR.Data) } return rRSet } @@ -133,15 +138,19 @@ func convertLDHash(inHash map[string][]libdns.Record) []zones.ResourceRecordSet continue } + // Convert first record to RR + rec0RR := recs[0].RR() + rr := zones.ResourceRecordSet{ - Name: recs[0].Name, - Type: recs[0].Type, - TTL: int(recs[0].TTL.Seconds()), + Name: rec0RR.Name, + Type: rec0RR.Type, + TTL: int(rec0RR.TTL.Seconds()), ChangeType: zones.ChangeTypeReplace, } for _, rec := range recs { + recRR := rec.RR() rr.Records = append(rr.Records, zones.Record{ - Content: rec.Value, + Content: recRR.Data, }) } rrsets = append(rrsets, rr) @@ -158,7 +167,8 @@ func makeLDRecHash(records []libdns.Record) map[string][]libdns.Record { inHash := make(map[string][]libdns.Record) for _, r := range records { - k := key(r.Name, r.Type) + rRR := r.RR() + k := key(rRR.Name, rRR.Type) inHash[k] = append(inHash[k], r) } return inHash @@ -201,14 +211,16 @@ func convertNamesToAbsolute(zone string, records []libdns.Record) []libdns.Recor out := make([]libdns.Record, len(records)) copy(out, records) for i := range out { - name := libdns.AbsoluteName(out[i].Name, zone) + outRR := out[i].RR() + name := libdns.AbsoluteName(outRR.Name, zone) if !strings.HasSuffix(name, ".") { name = name + "." } - out[i].Name = name - if out[i].Type == "TXT" { - out[i].Value = txtsanitize.TXTSanitize(out[i].Value) + outRR.Name = name + if outRR.Type == "TXT" { + outRR.Data = txtsanitize.TXTSanitize(outRR.Data) } + out[i] = outRR } return out } diff --git a/go.mod b/go.mod index 35444e0..f1e292d 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/libdns/powerdns -go 1.16 +go 1.21 require ( - github.com/libdns/libdns v0.2.2 + github.com/libdns/libdns v1.0.0 github.com/mittwald/go-powerdns v0.6.6 ) diff --git a/provider.go b/provider.go index 885749d..30c0558 100644 --- a/provider.go +++ b/provider.go @@ -47,14 +47,14 @@ func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record recs := make([]libdns.Record, 0, len(prec.ResourceRecordSets)) for _, rec := range prec.ResourceRecordSets { for _, v := range rec.Records { - recs = append(recs, libdns.Record{ - ID: prec.ID, + // Create RR struct for the new API + rr := libdns.RR{ Type: rec.Type, Name: libdns.RelativeName(rec.Name, zone), - Value: v.Content, + Data: v.Content, TTL: time.Second * time.Duration(rec.TTL), - Priority: 0, - }) + } + recs = append(recs, rr) } } return recs, nil diff --git a/txtsanitize/txtsanitize.go b/txtsanitize/txtsanitize.go index 98965b8..a0d0c46 100644 --- a/txtsanitize/txtsanitize.go +++ b/txtsanitize/txtsanitize.go @@ -33,7 +33,7 @@ func TXTSanitize(in string) string { bldr.Write(contents[ind : ind+tInd]) ind += tInd - // look for \", but be aware of \\" is not escaped, but \\\" is + // look for \", but be aware of \\\" is not escaped, but \\\\\" is escCt := 0 for j := ind - 1; j >= 0 && contents[j] == '\\'; j-- { escCt++