Skip to content

Commit 444e311

Browse files
authored
desec: improvement of error logs. (#1161)
1 parent e07bf64 commit 444e311

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

providers/dns/desec/desec.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,25 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
102102

103103
recordName := getRecordName(fqdn, authZone)
104104

105-
rrSet, err := d.client.GetTxtRRSet(dns01.UnFqdn(authZone), recordName)
106-
107-
var nf *internal.NotFound
108-
if err != nil && !errors.As(err, &nf) {
109-
return fmt.Errorf("desec: failed to get records: %w", err)
110-
}
105+
domainName := dns01.UnFqdn(authZone)
111106

107+
rrSet, err := d.client.GetTxtRRSet(domainName, recordName)
112108
if err != nil {
113109
var nf *internal.NotFound
114110
if !errors.As(err, &nf) {
115-
return fmt.Errorf("desec: failed to get records: %w", err)
111+
return fmt.Errorf("desec: failed to get records: domainName=%s, recordName=%s: %w", domainName, recordName, err)
116112
}
117113

118114
// Not found case -> create
119115
_, err = d.client.AddTxtRRSet(internal.RRSet{
120-
Domain: dns01.UnFqdn(authZone),
116+
Domain: domainName,
121117
SubName: recordName,
122118
Type: "TXT",
123119
Records: []string{quotedValue},
124120
TTL: d.config.TTL,
125121
})
126122
if err != nil {
127-
return fmt.Errorf("desec: failed to create records: %w", err)
123+
return fmt.Errorf("desec: failed to create records: domainName=%s, recordName=%s: %w", domainName, recordName, err)
128124
}
129125

130126
return nil
@@ -133,9 +129,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
133129
// update
134130
records := append(rrSet.Records, quotedValue)
135131

136-
_, err = d.client.UpdateTxtRRSet(dns01.UnFqdn(authZone), recordName, records)
132+
_, err = d.client.UpdateTxtRRSet(domainName, recordName, records)
137133
if err != nil {
138-
return fmt.Errorf("desec: failed to update records: %w", err)
134+
return fmt.Errorf("desec: failed to update records: domainName=%s, recordName=%s: %w", domainName, recordName, err)
139135
}
140136

141137
return nil
@@ -152,9 +148,11 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
152148

153149
recordName := getRecordName(fqdn, authZone)
154150

155-
rrSet, err := d.client.GetTxtRRSet(dns01.UnFqdn(authZone), recordName)
151+
domainName := dns01.UnFqdn(authZone)
152+
153+
rrSet, err := d.client.GetTxtRRSet(domainName, recordName)
156154
if err != nil {
157-
return fmt.Errorf("desec: failed to create records: %w", err)
155+
return fmt.Errorf("desec: failed to get records: domainName=%s, recordName=%s: %w", domainName, recordName, err)
158156
}
159157

160158
records := make([]string, 0)
@@ -164,9 +162,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
164162
}
165163
}
166164

167-
_, err = d.client.UpdateTxtRRSet(dns01.UnFqdn(authZone), recordName, records)
165+
_, err = d.client.UpdateTxtRRSet(domainName, recordName, records)
168166
if err != nil {
169-
return fmt.Errorf("desec: failed to update records: %w", err)
167+
return fmt.Errorf("desec: failed to update records: domainName=%s, recordName=%s: %w", domainName, recordName, err)
170168
}
171169

172170
return nil

providers/dns/desec/internal/client.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ func (c *Client) UpdateTxtRRSet(domainName string, subName string, records []str
156156
return nil, fmt.Errorf("failed to call API: %w", err)
157157
}
158158

159-
body, err := ioutil.ReadAll(resp.Body)
160-
if err != nil {
161-
return nil, fmt.Errorf("failed to read response body: %w", err)
162-
}
163-
164159
// when a RRSet is deleted (empty records)
165160
if resp.StatusCode == http.StatusNoContent {
166161
return nil, nil
167162
}
168163

164+
body, err := ioutil.ReadAll(resp.Body)
165+
if err != nil {
166+
return nil, fmt.Errorf("failed to read response body: %w", err)
167+
}
168+
169169
if resp.StatusCode != http.StatusOK {
170170
return nil, fmt.Errorf("error: %d: %s", resp.StatusCode, string(body))
171171
}
@@ -204,12 +204,8 @@ func (c *Client) DeleteTxtRRSet(domainName string, subName string) error {
204204
return fmt.Errorf("failed to call API: %w", err)
205205
}
206206

207-
body, err := ioutil.ReadAll(resp.Body)
208-
if err != nil {
209-
return fmt.Errorf("failed to read response body: %w", err)
210-
}
211-
212207
if resp.StatusCode != http.StatusNoContent {
208+
body, _ := ioutil.ReadAll(resp.Body)
213209
return fmt.Errorf("error: %d: %s", resp.StatusCode, string(body))
214210
}
215211

0 commit comments

Comments
 (0)