@@ -121,18 +121,18 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
121121
122122// Present creates a TXT record to fulfill the dns-01 challenge.
123123func (d * DNSProvider ) Present (domain , token , keyAuth string ) error {
124+ ctx := context .Background ()
125+
124126 info := dns01 .GetChallengeInfo (domain , keyAuth )
125127
126128 authZone , err := dns01 .FindZoneByFqdn (info .EffectiveFQDN )
127129 if err != nil {
128130 return fmt .Errorf ("pdns: could not find zone for domain %q: %w" , domain , err )
129131 }
130132
131- ctx := context .Background ()
132-
133133 zone , err := d .client .GetHostedZone (ctx , authZone )
134134 if err != nil {
135- return fmt .Errorf ("pdns: %w" , err )
135+ return fmt .Errorf ("pdns: get hosted zone for %s: %w" , authZone , err )
136136 }
137137
138138 name := info .EffectiveFQDN
@@ -144,61 +144,63 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
144144 // Look for existing records.
145145 existingRRSet := findTxtRecord (zone , info .EffectiveFQDN )
146146
147- // merge the existing and new records
148147 var records []internal.Record
149148 if existingRRSet != nil {
150149 records = existingRRSet .Records
151150 }
152151
153- rec := internal.Record {
152+ records = append ( records , internal.Record {
154153 Content : strconv .Quote (info .Value ),
155154 Disabled : false ,
156155
157156 // pre-v1 API
158157 Type : "TXT" ,
159158 Name : name ,
160159 TTL : d .config .TTL ,
161- }
160+ })
162161
163162 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+ }},
174171 }
175172
176173 err = d .client .UpdateRecords (ctx , zone , rrSets )
177174 if err != nil {
178- return fmt .Errorf ("pdns: %w" , err )
175+ return fmt .Errorf ("pdns: update records: %w" , err )
179176 }
180177
181- return d .client .Notify (ctx , zone )
178+ err = d .client .Notify (ctx , zone )
179+ if err != nil {
180+ return fmt .Errorf ("pdns: notify: %w" , err )
181+ }
182+
183+ return nil
182184}
183185
184186// CleanUp removes the TXT record matching the specified parameters.
185187func (d * DNSProvider ) CleanUp (domain , token , keyAuth string ) error {
188+ ctx := context .Background ()
189+
186190 info := dns01 .GetChallengeInfo (domain , keyAuth )
187191
188192 authZone , err := dns01 .FindZoneByFqdn (info .EffectiveFQDN )
189193 if err != nil {
190194 return fmt .Errorf ("pdns: could not find zone for domain %q: %w" , domain , err )
191195 }
192196
193- ctx := context .Background ()
194-
195197 zone , err := d .client .GetHostedZone (ctx , authZone )
196198 if err != nil {
197- return fmt .Errorf ("pdns: %w" , err )
199+ return fmt .Errorf ("pdns: get hosted zone for %s: %w" , authZone , err )
198200 }
199201
202+ // Look for existing records.
200203 set := findTxtRecord (zone , info .EffectiveFQDN )
201-
202204 if set == nil {
203205 return fmt .Errorf ("pdns: no existing record found for %s" , info .EffectiveFQDN )
204206 }
@@ -225,10 +227,15 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
225227
226228 err = d .client .UpdateRecords (ctx , zone , internal.RRSets {RRSets : []internal.RRSet {rrSet }})
227229 if err != nil {
228- return fmt .Errorf ("pdns: %w" , err )
230+ return fmt .Errorf ("pdns: update records: %w" , err )
229231 }
230232
231- return d .client .Notify (ctx , zone )
233+ err = d .client .Notify (ctx , zone )
234+ if err != nil {
235+ return fmt .Errorf ("pdns: notify: %w" , err )
236+ }
237+
238+ return nil
232239}
233240
234241func findTxtRecord (zone * internal.HostedZone , fqdn string ) * internal.RRSet {
0 commit comments