joker.go raw
1 // Package joker implements a DNS provider for solving the DNS-01 challenge using joker.com.
2 package joker
3
4 import (
5 "net/http"
6 "os"
7 "time"
8
9 "github.com/go-acme/lego/v4/challenge"
10 "github.com/go-acme/lego/v4/challenge/dns01"
11 "github.com/go-acme/lego/v4/platform/config/env"
12 )
13
14 // Environment variables names.
15 const (
16 envNamespace = "JOKER_"
17
18 EnvAPIKey = envNamespace + "API_KEY"
19 EnvUsername = envNamespace + "USERNAME"
20 EnvPassword = envNamespace + "PASSWORD"
21 EnvDebug = envNamespace + "DEBUG"
22 EnvMode = envNamespace + "API_MODE"
23
24 EnvTTL = envNamespace + "TTL"
25 EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
26 EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
27 EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
28 EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
29 )
30
31 const (
32 modeDMAPI = "DMAPI"
33 modeSVC = "SVC"
34 )
35
36 // Config is used to configure the creation of the DNSProvider.
37 type Config struct {
38 Debug bool
39 APIKey string
40 Username string
41 Password string
42 APIMode string
43 PropagationTimeout time.Duration
44 PollingInterval time.Duration
45 SequenceInterval time.Duration
46 TTL int
47 HTTPClient *http.Client
48 }
49
50 // NewDefaultConfig returns a default configuration for the DNSProvider.
51 func NewDefaultConfig() *Config {
52 return &Config{
53 APIMode: env.GetOrDefaultString(EnvMode, modeDMAPI),
54 Debug: env.GetOrDefaultBool(EnvDebug, false),
55 TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
56 PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
57 PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
58 SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
59 HTTPClient: &http.Client{
60 Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
61 },
62 }
63 }
64
65 // NewDNSProvider returns a DNSProvider instance configured for Joker.
66 // Credentials must be passed in the environment variable JOKER_API_KEY.
67 func NewDNSProvider() (challenge.ProviderTimeout, error) {
68 if os.Getenv(EnvMode) == modeSVC {
69 return newSvcProvider()
70 }
71
72 return newDmapiProvider()
73 }
74
75 // NewDNSProviderConfig return a DNSProvider instance configured for Joker.
76 func NewDNSProviderConfig(config *Config) (challenge.ProviderTimeout, error) {
77 if config.APIMode == modeSVC {
78 return newSvcProviderConfig(config)
79 }
80
81 return newDmapiProviderConfig(config)
82 }
83