forked from hairyhenderson/dnsproviders
/
rfc2136.go
55 lines (50 loc) · 1.62 KB
/
rfc2136.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
// Package rfc2136 adapts the lego RFC 2136 dynamic update DNS
// provider for Caddy. Importing this package plugs it in.
package rfc2136
import (
"errors"
"time"
"github.com/mholt/caddy/caddytls"
"github.com/xenolf/lego/providers/dns/rfc2136"
)
func init() {
caddytls.RegisterDNSProvider("rfc2136", NewDNSProvider)
}
// NewDNSProvider returns a new RFC 2136 DNS challenge provider.
// The credentials are interpreted as follows:
//
// len(0): use credentials from environment
// len(4): credentials[0] = nameserver
// credentials[1] = TSIG algorithm
// credentials[2] = TSIG key
// credentials[3] = TSIG secret
// DNS propagation timeout uses default from github.com/xenolf/lego/providers/dns/rfc2136 (60s)
// len(5): credentials[0] = nameserver
// credentials[1] = TSIG algorithm
// credentials[2] = TSIG key
// credentials[3] = TSIG secret
// credentials[4] = DNS propagation timeout
func NewDNSProvider(credentials ...string) (caddytls.ChallengeProvider, error) {
var timeout time.Duration
switch len(credentials) {
case 0:
return rfc2136.NewDNSProvider()
case 5:
var err error
timeout, err = time.ParseDuration(credentials[4])
if err != nil {
return nil, errors.New("invalid DNS propagation timeout")
}
fallthrough
case 4:
config := rfc2136.NewDefaultConfig()
config.Nameserver = credentials[0]
config.TSIGAlgorithm = credentials[1]
config.TSIGKey = credentials[2]
config.TSIGSecret = credentials[3]
config.PropagationTimeout = timeout
return rfc2136.NewDNSProviderConfig(config)
default:
return nil, errors.New("invalid credentials length")
}
}