forked from go-acme/lego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
57 lines (46 loc) · 1.25 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dode
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"github.com/fibbs/lego/v4/challenge/dns01"
)
type apiResponse struct {
Domain string
Success bool
}
// updateTxtRecord Update the domains TXT record
// To update the TXT record we just need to make one simple get request.
func (d *DNSProvider) updateTxtRecord(fqdn, token, txt string, clear bool) error {
u, _ := url.Parse("https://www.do.de/api/letsencrypt")
query := u.Query()
query.Set("token", token)
query.Set("domain", dns01.UnFqdn(fqdn))
// api call differs per set/delete
if clear {
query.Set("action", "delete")
} else {
query.Set("value", txt)
}
u.RawQuery = query.Encode()
response, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
var r apiResponse
err = json.Unmarshal(bodyBytes, &r)
if err != nil {
return fmt.Errorf("request to change TXT record for do.de returned the following invalid json (%s); used url [%s]", string(bodyBytes), u)
}
body := string(bodyBytes)
if !r.Success {
return fmt.Errorf("request to change TXT record for do.de returned the following error result (%s); used url [%s]", body, u)
}
return nil
}