Skip to content

Commit 97f364f

Browse files
authored
Merge pull request #14 from n-rodriguez/fix/libdns1.0
Bump to libdns 1.0
2 parents 2da7ce1 + b4a981f commit 97f364f

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

client.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/libdns/libdns"
1212
)
1313

14-
func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Record, domain gandiDomain) error {
14+
func (p *Provider) setRecord(ctx context.Context, zone string, rr libdns.RR, domain gandiDomain) error {
1515
p.mutex.Lock()
1616
defer p.mutex.Unlock()
1717

18-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), nil)
18+
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, rr.Name, rr.Type), nil)
1919
if err != nil {
2020
return err
2121
}
@@ -31,22 +31,22 @@ func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Rec
3131
// we check if the new value does not already exists and append it if not
3232
var exists bool
3333
for _, val := range oldGandiRecord.RRSetValues {
34-
if val == record.Value {
34+
if val == rr.Data {
3535
exists = true
3636
break
3737
}
3838
}
3939

4040
recValues := oldGandiRecord.RRSetValues
4141
if !exists {
42-
recValues = append(recValues, record.Value)
42+
recValues = append(recValues, rr.Data)
4343
}
4444

4545
// we just create a new record, if an existing record was found, we just append the new value to the existing ones
4646
newGandiRecord := gandiRecord{
47-
RRSetTTL: int(record.TTL.Seconds()),
48-
RRSetType: record.Type,
49-
RRSetName: record.Name,
47+
RRSetTTL: int(rr.TTL.Seconds()),
48+
RRSetType: rr.Type,
49+
RRSetName: rr.Name,
5050
RRSetValues: recValues,
5151
}
5252

@@ -56,7 +56,7 @@ func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Rec
5656
}
5757

5858
// we update existing record or create a new record if it does not exist yet
59-
req, err = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), bytes.NewReader(raw))
59+
req, err = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, rr.Name, rr.Type), bytes.NewReader(raw))
6060
if err != nil {
6161
return err
6262
}
@@ -68,11 +68,11 @@ func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Rec
6868
return err
6969
}
7070

71-
func (p *Provider) deleteRecord(ctx context.Context, zone string, record libdns.Record, domain gandiDomain) error {
71+
func (p *Provider) deleteRecord(ctx context.Context, zone string, rr libdns.RR, domain gandiDomain) error {
7272
p.mutex.Lock()
7373
defer p.mutex.Unlock()
7474

75-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), nil)
75+
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, rr.Name, rr.Type), nil)
7676
if err != nil {
7777
return err
7878
}
@@ -91,7 +91,7 @@ func (p *Provider) deleteRecord(ctx context.Context, zone string, record libdns.
9191
// if it contains multiple values, the best is to update the record instead of deleting all the values
9292
newRRSetValues := []string{}
9393
for _, val := range rec.RRSetValues {
94-
if val != record.Value {
94+
if val != rr.Data {
9595
newRRSetValues = append(newRRSetValues, val)
9696
}
9797
}
@@ -102,15 +102,15 @@ func (p *Provider) deleteRecord(ctx context.Context, zone string, record libdns.
102102
return err
103103
}
104104

105-
req, requestErr = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), bytes.NewReader(raw))
105+
req, requestErr = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, rr.Name, rr.Type), bytes.NewReader(raw))
106106
} else {
107107
// if there is only one entry, we make sure that the value to delete is matching the one we found
108108
// otherwise we may delete the wrong record
109-
if strings.Trim(rec.RRSetValues[0], "\"") != record.Value {
109+
if strings.Trim(rec.RRSetValues[0], "\"") != rr.Data {
110110
return fmt.Errorf("LiveDNS returned a %v (%v)", http.StatusNotFound, "Can't find such a DNS value")
111111
}
112112

113-
req, requestErr = http.NewRequestWithContext(ctx, "DELETE", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), nil)
113+
req, requestErr = http.NewRequestWithContext(ctx, "DELETE", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, rr.Name, rr.Type), nil)
114114
}
115115

116116
// we check if NewRequestWithContext threw an error

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/libdns/gandi
22

33
go 1.24
44

5-
require github.com/libdns/libdns v0.2.3
5+
require github.com/libdns/libdns v1.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/libdns/libdns v0.2.3 h1:ba30K4ObwMGB/QTmqUxf3H4/GmUrCAIkMWejeGl12v8=
2-
github.com/libdns/libdns v0.2.3/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
1+
github.com/libdns/libdns v1.1.0 h1:9ze/tWvt7Df6sbhOJRB8jT33GHEHpEQXdtkE3hPthbU=
2+
github.com/libdns/libdns v1.1.0/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=

provider.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record
3838
var libRecords []libdns.Record
3939
for _, rec := range gandiRecords {
4040
for _, val := range rec.RRSetValues {
41-
rec := libdns.Record{
42-
Type: rec.RRSetType,
43-
Name: rec.RRSetName,
44-
TTL: time.Duration(rec.RRSetTTL) * time.Second,
45-
Value: val,
41+
rec := libdns.RR{
42+
Type: rec.RRSetType,
43+
Name: rec.RRSetName,
44+
TTL: time.Duration(rec.RRSetTTL) * time.Second,
45+
Data: val,
4646
}
4747

4848
libRecords = append(libRecords, rec)
@@ -61,7 +61,7 @@ func (p *Provider) AppendRecords(ctx context.Context, zone string, records []lib
6161
}
6262

6363
for _, rec := range records {
64-
err := p.setRecord(ctx, zone, rec, domain)
64+
err := p.setRecord(ctx, zone, rec.RR(), domain)
6565
if err != nil {
6666
return nil, err
6767
}
@@ -78,7 +78,7 @@ func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []lib
7878
}
7979

8080
for _, rec := range records {
81-
err := p.deleteRecord(ctx, zone, rec, domain)
81+
err := p.deleteRecord(ctx, zone, rec.RR(), domain)
8282
if err != nil {
8383
return nil, err
8484
}
@@ -96,7 +96,7 @@ func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns
9696
}
9797

9898
for _, rec := range records {
99-
err := p.setRecord(ctx, zone, rec, domain)
99+
err := p.setRecord(ctx, zone, rec.RR(), domain)
100100
if err != nil {
101101
return nil, err
102102
}

0 commit comments

Comments
 (0)