1
0
Fork 0

fix: update lego.

This commit is contained in:
Ludovic Fernandez 2019-03-27 11:18:04 +01:00 committed by Traefiker Bot
parent b893374dc1
commit c17de070fb
432 changed files with 182 additions and 259514 deletions

View file

@ -5,10 +5,10 @@ package sender
const (
// ourUserAgent is the User-Agent of this underlying library package.
ourUserAgent = "xenolf-acme/2.3.0"
ourUserAgent = "xenolf-acme/2.4.0"
// ourUserAgentComment is part of the UA comment linked to the version status of this underlying library package.
// values: detach|release
// NOTE: Update this with each tagged release.
ourUserAgentComment = "detach"
ourUserAgentComment = "release"
)

View file

@ -19,6 +19,7 @@ import (
"github.com/go-acme/lego/providers/dns/dnsimple"
"github.com/go-acme/lego/providers/dns/dnsmadeeasy"
"github.com/go-acme/lego/providers/dns/dnspod"
"github.com/go-acme/lego/providers/dns/dode"
"github.com/go-acme/lego/providers/dns/dreamhost"
"github.com/go-acme/lego/providers/dns/duckdns"
"github.com/go-acme/lego/providers/dns/dyn"
@ -91,6 +92,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
return dnsmadeeasy.NewDNSProvider()
case "dnspod":
return dnspod.NewDNSProvider()
case "dode":
return dode.NewDNSProvider()
case "dreamhost":
return dreamhost.NewDNSProvider()
case "duckdns":

View file

@ -0,0 +1,57 @@
package dode
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"github.com/go-acme/lego/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
}

View file

@ -0,0 +1,89 @@
// Package dode implements a DNS provider for solving the DNS-01 challenge using do.de.
package dode
import (
"errors"
"fmt"
"net/http"
"time"
"github.com/go-acme/lego/challenge/dns01"
"github.com/go-acme/lego/platform/config/env"
)
// Config is used to configure the creation of the DNSProvider
type Config struct {
Token string
PropagationTimeout time.Duration
PollingInterval time.Duration
SequenceInterval time.Duration
HTTPClient *http.Client
}
// NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config {
return &Config{
PropagationTimeout: env.GetOrDefaultSecond("DODE_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DODE_POLLING_INTERVAL", dns01.DefaultPollingInterval),
SequenceInterval: env.GetOrDefaultSecond("DODE_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout),
HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond("DODE_HTTP_TIMEOUT", 30*time.Second),
},
}
}
// DNSProvider adds and removes the record for the DNS challenge
type DNSProvider struct {
config *Config
}
// NewDNSProvider returns a new DNS provider using
// environment variable DODE_TOKEN for adding and removing the DNS record.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DODE_TOKEN")
if err != nil {
return nil, fmt.Errorf("do.de: %v", err)
}
config := NewDefaultConfig()
config.Token = values["DODE_TOKEN"]
return NewDNSProviderConfig(config)
}
// NewDNSProviderConfig return a DNSProvider instance configured for do.de.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("do.de: the configuration of the DNS provider is nil")
}
if config.Token == "" {
return nil, errors.New("do.de: credentials missing")
}
return &DNSProvider{config: config}, nil
}
// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, txtRecord := dns01.GetRecord(domain, keyAuth)
return d.updateTxtRecord(fqdn, d.config.Token, txtRecord, false)
}
// CleanUp clears TXT record
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
return d.updateTxtRecord(fqdn, d.config.Token, "", true)
}
// Timeout returns the timeout and interval to use when checking for DNS propagation.
// Adjusting here to cope with spikes in propagation times.
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}
// Sequential All DNS challenges for this provider will be resolved sequentially.
// Returns the interval between each iteration.
func (d *DNSProvider) Sequential() time.Duration {
return d.config.SequenceInterval
}

View file

@ -91,7 +91,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
zonesFind := ZoneConfigsFindRequest{
Filter: Filter{
Field: "zoneName",
Value: domain,
Value: d.config.ZoneName,
},
Limit: 1,
Page: 1,
@ -151,7 +151,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
zonesFind := ZoneConfigsFindRequest{
Filter: Filter{
Field: "zoneName",
Value: domain,
Value: d.config.ZoneName,
},
Limit: 1,
Page: 1,

View file

@ -127,7 +127,7 @@ func (d *DNSProvider) findTxtRecord(fqdn string) (*rrSet, error) {
}
}
return nil, fmt.Errorf("no existing record found for %s", fqdn)
return nil, nil
}
func (d *DNSProvider) getAPIVersion() (int, error) {

View file

@ -121,6 +121,19 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
TTL: d.config.TTL,
}
// Look for existing records.
existingRrSet, err := d.findTxtRecord(fqdn)
if err != nil {
return fmt.Errorf("pdns: %v", err)
}
// merge the existing and new records
var records []Record
if existingRrSet != nil {
records = existingRrSet.Records
}
records = append(records, rec)
rrsets := rrSets{
RRSets: []rrSet{
{
@ -129,7 +142,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Type: "TXT",
Kind: "Master",
TTL: d.config.TTL,
Records: []Record{rec},
Records: records,
},
},
}
@ -159,6 +172,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
if err != nil {
return fmt.Errorf("pdns: %v", err)
}
if set == nil {
return fmt.Errorf("pdns: no existing record found for %s", fqdn)
}
rrsets := rrSets{
RRSets: []rrSet{