Skip to content
Open
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
48 changes: 30 additions & 18 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,34 @@ 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 {
dupes[prec.Content] = true
}
// 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)
}
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 5 additions & 5 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion txtsanitize/txtsanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down