@@ -121,84 +121,86 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
121
121
122
122
// Present creates a TXT record to fulfill the dns-01 challenge.
123
123
func (d * DNSProvider ) Present (domain , token , keyAuth string ) error {
124
+ ctx := context .Background ()
125
+
124
126
info := dns01 .GetChallengeInfo (domain , keyAuth )
125
127
126
128
authZone , err := dns01 .FindZoneByFqdn (info .EffectiveFQDN )
127
129
if err != nil {
128
130
return fmt .Errorf ("pdns: could not find zone for domain %q: %w" , domain , err )
129
131
}
130
132
131
- ctx := context .Background ()
132
-
133
133
zone , err := d .client .GetHostedZone (ctx , authZone )
134
134
if err != nil {
135
- return fmt .Errorf ("pdns: %w" , err )
135
+ return fmt .Errorf ("pdns: get hosted zone for %s: %w" , authZone , err )
136
136
}
137
137
138
+ // Look for existing records.
139
+ existingRRSet := findTxtRecord (zone , info .EffectiveFQDN )
140
+
138
141
name := info .EffectiveFQDN
139
142
if d .client .APIVersion () == 0 {
140
143
// pre-v1 API wants non-fqdn
141
144
name = dns01 .UnFqdn (info .EffectiveFQDN )
142
145
}
143
146
144
- // Look for existing records.
145
- existingRRSet := findTxtRecord (zone , info .EffectiveFQDN )
146
-
147
- // merge the existing and new records
148
147
var records []internal.Record
149
148
if existingRRSet != nil {
150
149
records = existingRRSet .Records
151
150
}
152
151
153
- rec := internal.Record {
152
+ records = append ( records , internal.Record {
154
153
Content : strconv .Quote (info .Value ),
155
154
Disabled : false ,
156
155
157
156
// pre-v1 API
158
157
Type : "TXT" ,
159
158
Name : name ,
160
159
TTL : d .config .TTL ,
161
- }
160
+ })
162
161
163
162
rrSets := internal.RRSets {
164
- RRSets : []internal.RRSet {
165
- {
166
- Name : name ,
167
- ChangeType : "REPLACE" ,
168
- Type : "TXT" ,
169
- Kind : "Master" ,
170
- TTL : d .config .TTL ,
171
- Records : append (records , rec ),
172
- },
173
- },
163
+ RRSets : []internal.RRSet {{
164
+ Name : name ,
165
+ ChangeType : "REPLACE" ,
166
+ Type : "TXT" ,
167
+ Kind : "Master" ,
168
+ TTL : d .config .TTL ,
169
+ Records : records ,
170
+ }},
174
171
}
175
172
176
173
err = d .client .UpdateRecords (ctx , zone , rrSets )
177
174
if err != nil {
178
- return fmt .Errorf ("pdns: %w" , err )
175
+ return fmt .Errorf ("pdns: update records: %w" , err )
176
+ }
177
+
178
+ err = d .client .Notify (ctx , zone )
179
+ if err != nil {
180
+ return fmt .Errorf ("pdns: notify: %w" , err )
179
181
}
180
182
181
- return d . client . Notify ( ctx , zone )
183
+ return nil
182
184
}
183
185
184
186
// CleanUp removes the TXT record matching the specified parameters.
185
187
func (d * DNSProvider ) CleanUp (domain , token , keyAuth string ) error {
188
+ ctx := context .Background ()
189
+
186
190
info := dns01 .GetChallengeInfo (domain , keyAuth )
187
191
188
192
authZone , err := dns01 .FindZoneByFqdn (info .EffectiveFQDN )
189
193
if err != nil {
190
194
return fmt .Errorf ("pdns: could not find zone for domain %q: %w" , domain , err )
191
195
}
192
196
193
- ctx := context .Background ()
194
-
195
197
zone , err := d .client .GetHostedZone (ctx , authZone )
196
198
if err != nil {
197
- return fmt .Errorf ("pdns: %w" , err )
199
+ return fmt .Errorf ("pdns: get hosted zone for %s: %w" , authZone , err )
198
200
}
199
201
202
+ // Look for existing records.
200
203
set := findTxtRecord (zone , info .EffectiveFQDN )
201
-
202
204
if set == nil {
203
205
return fmt .Errorf ("pdns: no existing record found for %s" , info .EffectiveFQDN )
204
206
}
@@ -225,10 +227,15 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
225
227
226
228
err = d .client .UpdateRecords (ctx , zone , internal.RRSets {RRSets : []internal.RRSet {rrSet }})
227
229
if err != nil {
228
- return fmt .Errorf ("pdns: %w" , err )
230
+ return fmt .Errorf ("pdns: update record:s %w" , err )
231
+ }
232
+
233
+ err = d .client .Notify (ctx , zone )
234
+ if err != nil {
235
+ return fmt .Errorf ("pdns: notify: %w" , err )
229
236
}
230
237
231
- return d . client . Notify ( ctx , zone )
238
+ return nil
232
239
}
233
240
234
241
func findTxtRecord (zone * internal.HostedZone , fqdn string ) * internal.RRSet {
0 commit comments