@@ -5,14 +5,15 @@ import (
5
5
"crypto/tls"
6
6
"encoding/json"
7
7
"fmt"
8
- "github.com/libdns/libdns"
9
8
"io"
10
9
"log"
11
10
"net/http"
12
11
"net/url"
13
12
"runtime"
14
13
"strconv"
15
14
"strings"
15
+
16
+ "github.com/libdns/libdns"
16
17
)
17
18
18
19
func (p * Provider ) getZoneRecords (ctx context.Context , zone string ) ([]libdns.Record , error ) {
@@ -80,7 +81,8 @@ func (p *Provider) getZoneRecords(ctx context.Context, zone string) ([]libdns.Re
80
81
if err != nil {
81
82
switch err {
82
83
case ErrUnsupported :
83
- fmt .Printf ("[%s] unsupported record conversion of type %v: %v\n " , p .caller (callerSkipDepth ), libDnsRecord .Type , libDnsRecord .Name )
84
+ rr := libDnsRecord .RR ()
85
+ fmt .Printf ("[%s] unsupported record conversion of type %v: %v\n " , p .caller (callerSkipDepth ), rr .Type , rr .Name )
84
86
continue
85
87
default :
86
88
return nil , err
@@ -99,7 +101,7 @@ func (p *Provider) appendZoneRecord(ctx context.Context, zone string, record lib
99
101
reqURL , err := url .Parse (p .ServerURL )
100
102
if err != nil {
101
103
fmt .Printf ("[%s] failed to parse server url: %v\n " , p .caller (2 ), err )
102
- return libdns. Record {} , err
104
+ return nil , err
103
105
}
104
106
105
107
reqURL .Path = "/CMD_API_DNS_CONTROL"
@@ -110,24 +112,25 @@ func (p *Provider) appendZoneRecord(ctx context.Context, zone string, record lib
110
112
queryString .Set ("full_mx_records" , "yes" )
111
113
queryString .Set ("allow_dns_underscore" , "yes" )
112
114
queryString .Set ("domain" , zone )
113
- queryString .Set ("type" , record .Type )
114
- queryString .Set ("name" , record .Name )
115
- queryString .Set ("value" , record .Value )
116
115
117
- if record .Type != "NS" {
118
- queryString .Set ("ttl" , strconv .Itoa (int (record .TTL .Seconds ())))
116
+ rr := record .RR ()
117
+ queryString .Set ("type" , rr .Type )
118
+ queryString .Set ("name" , rr .Name )
119
+ queryString .Set ("value" , rr .Data )
120
+
121
+ if rr .Type != "NS" {
122
+ queryString .Set ("ttl" , strconv .Itoa (int (rr .TTL .Seconds ())))
119
123
}
120
124
121
125
reqURL .RawQuery = queryString .Encode ()
122
126
123
127
err = p .executeRequest (ctx , http .MethodGet , reqURL .String ())
124
128
if err != nil {
125
- return libdns. Record {} , err
129
+ return nil , err
126
130
}
127
131
128
- record .ID = fmt .Sprintf ("name=%v&value=%v" , record .Name , record .Value )
129
-
130
- return record , nil
132
+ rr .Data = fmt .Sprintf ("name=%v&value=%v" , rr .Name , rr .Data )
133
+ return & rr , nil
131
134
}
132
135
133
136
func (p * Provider ) setZoneRecord (ctx context.Context , zone string , record libdns.Record ) (libdns.Record , error ) {
@@ -137,7 +140,7 @@ func (p *Provider) setZoneRecord(ctx context.Context, zone string, record libdns
137
140
reqURL , err := url .Parse (p .ServerURL )
138
141
if err != nil {
139
142
fmt .Printf ("[%s] failed to parse server url: %v\n " , p .caller (2 ), err )
140
- return libdns. Record {} , err
143
+ return nil , err
141
144
}
142
145
143
146
reqURL .Path = "/CMD_API_DNS_CONTROL"
@@ -146,18 +149,21 @@ func (p *Provider) setZoneRecord(ctx context.Context, zone string, record libdns
146
149
queryString .Set ("action" , "edit" )
147
150
queryString .Set ("json" , "yes" )
148
151
queryString .Set ("domain" , zone )
149
- queryString .Set ("type" , record .Type )
150
- queryString .Set ("name" , record .Name )
151
- queryString .Set ("value" , record .Value )
152
152
153
- if record .Type != "NS" {
154
- queryString .Set ("ttl" , strconv .Itoa (int (record .TTL .Seconds ())))
153
+ rr := record .RR ()
154
+ queryString .Set ("type" , rr .Type )
155
+ queryString .Set ("name" , rr .Name )
156
+ queryString .Set ("value" , rr .Data )
157
+
158
+ if rr .Type != "NS" {
159
+ queryString .Set ("ttl" , strconv .Itoa (int (rr .TTL .Seconds ())))
155
160
}
156
161
157
162
existingRecords , _ := p .getZoneRecords (ctx , zone )
158
163
var existingRecordIndex = - 1
159
164
for i := range existingRecords {
160
- if existingRecords [i ].Name == record .Name && existingRecords [i ].Type == record .Type {
165
+ existingRR := existingRecords [i ].RR ()
166
+ if existingRR .Name == rr .Name && existingRR .Type == rr .Type {
161
167
existingRecordIndex = i
162
168
break
163
169
}
@@ -166,21 +172,20 @@ func (p *Provider) setZoneRecord(ctx context.Context, zone string, record libdns
166
172
// If we're not -1, we found a matching existing record. This changes the API call
167
173
// from create only to edit.
168
174
if existingRecordIndex != - 1 {
169
- editKey := fmt .Sprintf ("%vrecs0" , strings .ToLower (record .Type ))
170
- editValue := existingRecords [existingRecordIndex ].ID
175
+ editKey := fmt .Sprintf ("%vrecs0" , strings .ToLower (rr .Type ))
176
+ editValue := existingRecords [existingRecordIndex ].RR (). Data
171
177
queryString .Set (editKey , editValue )
172
178
}
173
179
174
180
reqURL .RawQuery = queryString .Encode ()
175
181
176
182
err = p .executeRequest (ctx , http .MethodGet , reqURL .String ())
177
183
if err != nil {
178
- return libdns. Record {} , err
184
+ return nil , err
179
185
}
180
186
181
- record .ID = fmt .Sprintf ("name=%v&value=%v" , record .Name , record .Value )
182
-
183
- return record , nil
187
+ rr .Data = fmt .Sprintf ("name=%v&value=%v" , rr .Name , rr .Data )
188
+ return & rr , nil
184
189
}
185
190
186
191
func (p * Provider ) deleteZoneRecord (ctx context.Context , zone string , record libdns.Record ) (libdns.Record , error ) {
@@ -190,7 +195,7 @@ func (p *Provider) deleteZoneRecord(ctx context.Context, zone string, record lib
190
195
reqURL , err := url .Parse (p .ServerURL )
191
196
if err != nil {
192
197
fmt .Printf ("[%s] failed to parse server url: %v\n " , p .caller (2 ), err )
193
- return libdns. Record {} , err
198
+ return nil , err
194
199
}
195
200
196
201
reqURL .Path = "/CMD_API_DNS_CONTROL"
@@ -200,15 +205,16 @@ func (p *Provider) deleteZoneRecord(ctx context.Context, zone string, record lib
200
205
queryString .Set ("json" , "yes" )
201
206
queryString .Set ("domain" , zone )
202
207
203
- editKey := fmt .Sprintf ("%vrecs0" , strings .ToLower (record .Type ))
204
- editValue := fmt .Sprintf ("name=%v&value=%v" , record .Name , record .Value )
208
+ rr := record .RR ()
209
+ editKey := fmt .Sprintf ("%vrecs0" , strings .ToLower (rr .Type ))
210
+ editValue := fmt .Sprintf ("name=%v&value=%v" , rr .Name , rr .Data )
205
211
queryString .Set (editKey , editValue )
206
212
207
213
reqURL .RawQuery = queryString .Encode ()
208
214
209
215
err = p .executeRequest (ctx , http .MethodGet , reqURL .String ())
210
216
if err != nil {
211
- return libdns. Record {} , err
217
+ return nil , err
212
218
}
213
219
214
220
return record , nil
0 commit comments