forked from TrueCloudLab/lego
DuckDNS: fix TXT record update url (#601)
This commit is contained in:
parent
dd85f25cb3
commit
6edbd1572e
1 changed files with 21 additions and 31 deletions
|
@ -30,26 +30,32 @@ func NewDNSProvider() (*DNSProvider, error) {
|
||||||
|
|
||||||
// NewDNSProviderCredentials uses the supplied credentials to return a
|
// NewDNSProviderCredentials uses the supplied credentials to return a
|
||||||
// DNSProvider instance configured for http://duckdns.org .
|
// DNSProvider instance configured for http://duckdns.org .
|
||||||
func NewDNSProviderCredentials(duckdnsToken string) (*DNSProvider, error) {
|
func NewDNSProviderCredentials(token string) (*DNSProvider, error) {
|
||||||
if duckdnsToken == "" {
|
if token == "" {
|
||||||
return nil, errors.New("DuckDNS: credentials missing")
|
return nil, errors.New("DuckDNS: credentials missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &DNSProvider{token: duckdnsToken}, nil
|
return &DNSProvider{token: token}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeDuckdnsURL creates a url to clear the set or unset the TXT record.
|
// Present creates a TXT record to fulfil the dns-01 challenge.
|
||||||
// txt == "" will clear the TXT record.
|
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
||||||
func makeDuckdnsURL(domain, token, txt string) string {
|
_, txtRecord, _ := acme.DNS01Record(domain, keyAuth)
|
||||||
requestBase := fmt.Sprintf("https://www.duckdns.org/update?domains=%s&token=%s", domain, token)
|
return updateTxtRecord(domain, d.token, txtRecord, false)
|
||||||
if txt == "" {
|
|
||||||
return requestBase + "&clear=true"
|
|
||||||
}
|
|
||||||
return requestBase + "&txt=" + txt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func issueDuckdnsRequest(url string) error {
|
// CleanUp clears DuckDNS TXT record
|
||||||
response, err := acme.HTTPClient.Get(url)
|
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
||||||
|
return updateTxtRecord(domain, d.token, "", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateTxtRecord Update the domains TXT record
|
||||||
|
// To update the TXT record we just need to make one simple get request.
|
||||||
|
// In DuckDNS you only have one TXT record shared with the domain and all sub domains.
|
||||||
|
func updateTxtRecord(domain, token, txt string, clear bool) error {
|
||||||
|
u := fmt.Sprintf("https://www.duckdns.org/update?domains=%s&token=%s&clear=%t&txt=%s", domain, token, clear, txt)
|
||||||
|
|
||||||
|
response, err := acme.HTTPClient.Get(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -59,26 +65,10 @@ func issueDuckdnsRequest(url string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
body := string(bodyBytes)
|
body := string(bodyBytes)
|
||||||
if body != "OK" {
|
if body != "OK" {
|
||||||
return fmt.Errorf("Request to change TXT record for duckdns returned the following result (%s) this does not match expectation (OK) used url [%s]", body, url)
|
return fmt.Errorf("request to change TXT record for DuckDNS returned the following result (%s) this does not match expectation (OK) used url [%s]", body, u)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present creates a TXT record to fulfil the dns-01 challenge.
|
|
||||||
// In duckdns you only have one TXT record shared with
|
|
||||||
// the domain and all sub domains.
|
|
||||||
//
|
|
||||||
// To update the TXT record we just need to make one simple get request.
|
|
||||||
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|
||||||
_, txtRecord, _ := acme.DNS01Record(domain, keyAuth)
|
|
||||||
url := makeDuckdnsURL(domain, d.token, txtRecord)
|
|
||||||
return issueDuckdnsRequest(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CleanUp clears duckdns TXT record
|
|
||||||
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|
||||||
url := makeDuckdnsURL(domain, d.token, "")
|
|
||||||
return issueDuckdnsRequest(url)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue