2020-10-08 14:52:50 +00:00
|
|
|
// Package joker implements a DNS provider for solving the DNS-01 challenge using joker.com.
|
2019-04-28 12:33:50 +00:00
|
|
|
package joker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2020-10-08 14:52:50 +00:00
|
|
|
"os"
|
2019-04-28 12:33:50 +00:00
|
|
|
"time"
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
"github.com/go-acme/lego/v4/challenge"
|
2020-09-02 01:20:01 +00:00
|
|
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
|
|
|
"github.com/go-acme/lego/v4/platform/config/env"
|
2019-04-28 12:33:50 +00:00
|
|
|
)
|
|
|
|
|
2020-03-11 22:51:10 +00:00
|
|
|
// Environment variables names.
|
|
|
|
const (
|
|
|
|
envNamespace = "JOKER_"
|
|
|
|
|
|
|
|
EnvAPIKey = envNamespace + "API_KEY"
|
|
|
|
EnvUsername = envNamespace + "USERNAME"
|
|
|
|
EnvPassword = envNamespace + "PASSWORD"
|
|
|
|
EnvDebug = envNamespace + "DEBUG"
|
2020-10-08 14:52:50 +00:00
|
|
|
EnvMode = envNamespace + "API_MODE"
|
2020-03-11 22:51:10 +00:00
|
|
|
|
|
|
|
EnvTTL = envNamespace + "TTL"
|
|
|
|
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
|
|
|
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
2020-10-08 14:52:50 +00:00
|
|
|
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
|
|
|
)
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
const (
|
|
|
|
modeDMAPI = "DMAPI"
|
|
|
|
modeSVC = "SVC"
|
|
|
|
)
|
|
|
|
|
2019-04-28 12:33:50 +00:00
|
|
|
// Config is used to configure the creation of the DNSProvider.
|
|
|
|
type Config struct {
|
|
|
|
Debug bool
|
|
|
|
APIKey string
|
2019-07-17 00:39:17 +00:00
|
|
|
Username string
|
|
|
|
Password string
|
2020-10-08 14:52:50 +00:00
|
|
|
APIMode string
|
2019-04-28 12:33:50 +00:00
|
|
|
PropagationTimeout time.Duration
|
|
|
|
PollingInterval time.Duration
|
2020-10-08 14:52:50 +00:00
|
|
|
SequenceInterval time.Duration
|
2019-04-28 12:33:50 +00:00
|
|
|
TTL int
|
|
|
|
HTTPClient *http.Client
|
|
|
|
}
|
|
|
|
|
2020-05-08 17:35:25 +00:00
|
|
|
// NewDefaultConfig returns a default configuration for the DNSProvider.
|
2019-04-28 12:33:50 +00:00
|
|
|
func NewDefaultConfig() *Config {
|
|
|
|
return &Config{
|
2020-10-08 14:52:50 +00:00
|
|
|
APIMode: env.GetOrDefaultString(EnvMode, modeDMAPI),
|
2020-03-11 22:51:10 +00:00
|
|
|
Debug: env.GetOrDefaultBool(EnvDebug, false),
|
|
|
|
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
2020-10-08 14:52:50 +00:00
|
|
|
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
2020-03-11 22:51:10 +00:00
|
|
|
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
2020-10-08 14:52:50 +00:00
|
|
|
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
|
2019-04-28 12:33:50 +00:00
|
|
|
HTTPClient: &http.Client{
|
2020-03-11 22:51:10 +00:00
|
|
|
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
|
2019-04-28 12:33:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
// NewDNSProvider returns a DNSProvider instance configured for Joker.
|
2019-04-28 12:33:50 +00:00
|
|
|
// Credentials must be passed in the environment variable JOKER_API_KEY.
|
2020-10-08 14:52:50 +00:00
|
|
|
func NewDNSProvider() (challenge.ProviderTimeout, error) {
|
|
|
|
if os.Getenv(EnvMode) == modeSVC {
|
|
|
|
return newSvcProvider()
|
2019-04-28 12:33:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
return newDmapiProvider()
|
2019-04-28 12:33:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
// NewDNSProviderConfig return a DNSProvider instance configured for Joker.
|
|
|
|
func NewDNSProviderConfig(config *Config) (challenge.ProviderTimeout, error) {
|
|
|
|
if config.APIMode == modeSVC {
|
|
|
|
return newSvcProviderConfig(config)
|
2019-04-28 12:33:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
return newDmapiProviderConfig(config)
|
2019-04-28 12:33:50 +00:00
|
|
|
}
|