lego/providers/dns/joker/joker.go

83 lines
2.5 KiB
Go
Raw Normal View History

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
)
// 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"
EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
2020-10-08 14:52:50 +00:00
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
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
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),
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),
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{
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
}