forked from TrueCloudLab/lego
Standardization of the definition of env vars. (#1082)
This commit is contained in:
parent
aeb20f4deb
commit
403070dd9b
129 changed files with 2212 additions and 1312 deletions
|
@ -14,12 +14,13 @@ import (
|
|||
const (
|
||||
// envNamespace is the prefix for ACME-DNS environment variables.
|
||||
envNamespace = "ACME_DNS_"
|
||||
// apiBaseEnvVar is the environment variable name for the ACME-DNS API address
|
||||
|
||||
// EnvAPIBase is the environment variable name for the ACME-DNS API address
|
||||
// (e.g. https://acmedns.your-domain.com).
|
||||
apiBaseEnvVar = envNamespace + "API_BASE"
|
||||
// storagePathEnvVar is the environment variable name for the ACME-DNS JSON account data file.
|
||||
EnvAPIBase = envNamespace + "API_BASE"
|
||||
// EnvStoragePath is the environment variable name for the ACME-DNS JSON account data file.
|
||||
// A per-domain account will be registered/persisted to this file and used for TXT updates.
|
||||
storagePathEnvVar = envNamespace + "STORAGE_PATH"
|
||||
EnvStoragePath = envNamespace + "STORAGE_PATH"
|
||||
)
|
||||
|
||||
// acmeDNSClient is an interface describing the goacmedns.Client functions the DNSProvider uses.
|
||||
|
@ -41,15 +42,15 @@ type DNSProvider struct {
|
|||
}
|
||||
|
||||
// NewDNSProvider creates an ACME-DNS provider using file based account storage.
|
||||
// Its configuration is loaded from the environment by reading apiBaseEnvVar and storagePathEnvVar.
|
||||
// Its configuration is loaded from the environment by reading EnvAPIBase and EnvStoragePath.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(apiBaseEnvVar, storagePathEnvVar)
|
||||
values, err := env.Get(EnvAPIBase, EnvStoragePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("acme-dns: %w", err)
|
||||
}
|
||||
|
||||
client := goacmedns.NewClient(values[apiBaseEnvVar])
|
||||
storage := goacmedns.NewFileStorage(values[storagePathEnvVar], 0600)
|
||||
client := goacmedns.NewClient(values[EnvAPIBase])
|
||||
storage := goacmedns.NewFileStorage(values[EnvStoragePath], 0600)
|
||||
return NewDNSProviderClient(client, storage)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,20 @@ import (
|
|||
|
||||
const defaultRegionID = "cn-hangzhou"
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "ALICLOUD_"
|
||||
|
||||
EnvAccessKey = envNamespace + "ACCESS_KEY"
|
||||
EnvSecretKey = envNamespace + "SECRET_KEY"
|
||||
EnvRegionID = envNamespace + "REGION_ID"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -31,10 +45,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("ALICLOUD_TTL", 600),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("ALICLOUD_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("ALICLOUD_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
HTTPTimeout: env.GetOrDefaultSecond("ALICLOUD_HTTP_TIMEOUT", 10*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 600),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,15 +61,15 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Alibaba Cloud DNS.
|
||||
// Credentials must be passed in the environment variables: ALICLOUD_ACCESS_KEY and ALICLOUD_SECRET_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("ALICLOUD_ACCESS_KEY", "ALICLOUD_SECRET_KEY")
|
||||
values, err := env.Get(EnvAccessKey, EnvSecretKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("alicloud: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["ALICLOUD_ACCESS_KEY"]
|
||||
config.SecretKey = values["ALICLOUD_SECRET_KEY"]
|
||||
config.RegionID = env.GetOrFile("ALICLOUD_REGION_ID")
|
||||
config.APIKey = values[EnvAccessKey]
|
||||
config.SecretKey = values[EnvSecretKey]
|
||||
config.RegionID = env.GetOrFile(EnvRegionID)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"ALICLOUD_ACCESS_KEY",
|
||||
"ALICLOUD_SECRET_KEY").
|
||||
WithDomain("ALICLOUD_DOMAIN")
|
||||
EnvAccessKey,
|
||||
EnvSecretKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"ALICLOUD_ACCESS_KEY": "123",
|
||||
"ALICLOUD_SECRET_KEY": "456",
|
||||
EnvAccessKey: "123",
|
||||
EnvSecretKey: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"ALICLOUD_ACCESS_KEY": "",
|
||||
"ALICLOUD_SECRET_KEY": "",
|
||||
EnvAccessKey: "",
|
||||
EnvSecretKey: "",
|
||||
},
|
||||
expected: "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY,ALICLOUD_SECRET_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing access key",
|
||||
envVars: map[string]string{
|
||||
"ALICLOUD_ACCESS_KEY": "",
|
||||
"ALICLOUD_SECRET_KEY": "456",
|
||||
EnvAccessKey: "",
|
||||
EnvSecretKey: "456",
|
||||
},
|
||||
expected: "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"ALICLOUD_ACCESS_KEY": "123",
|
||||
"ALICLOUD_SECRET_KEY": "",
|
||||
EnvAccessKey: "123",
|
||||
EnvSecretKey: "",
|
||||
},
|
||||
expected: "alicloud: some credentials information are missing: ALICLOUD_SECRET_KEY",
|
||||
},
|
||||
|
|
|
@ -14,6 +14,19 @@ import (
|
|||
|
||||
const defaultBaseURL = "https://api.auroradns.eu"
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "AURORA_"
|
||||
|
||||
EnvUserID = envNamespace + "USER_ID"
|
||||
EnvKey = envNamespace + "KEY"
|
||||
EnvEndpoint = envNamespace + "ENDPOINT"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -27,9 +40,9 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("AURORA_TTL", 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("AURORA_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("AURORA_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,15 +58,15 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// AURORA_USER_ID and AURORA_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("AURORA_USER_ID", "AURORA_KEY")
|
||||
values, err := env.Get(EnvUserID, EnvKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("aurora: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.BaseURL = env.GetOrFile("AURORA_ENDPOINT")
|
||||
config.UserID = values["AURORA_USER_ID"]
|
||||
config.Key = values["AURORA_KEY"]
|
||||
config.BaseURL = env.GetOrFile(EnvEndpoint)
|
||||
config.UserID = values[EnvUserID]
|
||||
config.Key = values[EnvKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -13,9 +13,8 @@ import (
|
|||
)
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"AURORA_USER_ID",
|
||||
"AURORA_KEY",
|
||||
)
|
||||
EnvUserID,
|
||||
EnvKey)
|
||||
|
||||
func setupTest() (*DNSProvider, *http.ServeMux, func()) {
|
||||
handler := http.NewServeMux()
|
||||
|
@ -43,31 +42,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"AURORA_USER_ID": "123",
|
||||
"AURORA_KEY": "456",
|
||||
EnvUserID: "123",
|
||||
EnvKey: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"AURORA_USER_ID": "",
|
||||
"AURORA_KEY": "",
|
||||
EnvUserID: "",
|
||||
EnvKey: "",
|
||||
},
|
||||
expected: "aurora: some credentials information are missing: AURORA_USER_ID,AURORA_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing user id",
|
||||
envVars: map[string]string{
|
||||
"AURORA_USER_ID": "",
|
||||
"AURORA_KEY": "456",
|
||||
EnvUserID: "",
|
||||
EnvKey: "456",
|
||||
},
|
||||
expected: "aurora: some credentials information are missing: AURORA_USER_ID",
|
||||
},
|
||||
{
|
||||
desc: "missing key",
|
||||
envVars: map[string]string{
|
||||
"AURORA_USER_ID": "123",
|
||||
"AURORA_KEY": "",
|
||||
EnvUserID: "123",
|
||||
EnvKey: "",
|
||||
},
|
||||
expected: "aurora: some credentials information are missing: AURORA_KEY",
|
||||
},
|
||||
|
|
|
@ -11,15 +11,19 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envAPIUser = "AUTODNS_API_USER"
|
||||
envAPIPassword = "AUTODNS_API_PASSWORD"
|
||||
envAPIEndpoint = "AUTODNS_ENDPOINT"
|
||||
envAPIEndpointContext = "AUTODNS_CONTEXT"
|
||||
envTTL = "AUTODNS_TTL"
|
||||
envPropagationTimeout = "AUTODNS_PROPAGATION_TIMEOUT"
|
||||
envPollingInterval = "AUTODNS_POLLING_INTERVAL"
|
||||
envHTTPTimeout = "AUTODNS_HTTP_TIMEOUT"
|
||||
envNamespace = "AUTODNS_"
|
||||
|
||||
EnvAPIUser = envNamespace + "API_USER"
|
||||
EnvAPIPassword = envNamespace + "API_PASSWORD"
|
||||
EnvAPIEndpoint = envNamespace + "ENDPOINT"
|
||||
EnvAPIEndpointContext = envNamespace + "CONTEXT"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -39,16 +43,16 @@ type Config struct {
|
|||
}
|
||||
|
||||
func NewDefaultConfig() *Config {
|
||||
endpoint, _ := url.Parse(env.GetOrDefaultString(envAPIEndpoint, defaultEndpoint))
|
||||
endpoint, _ := url.Parse(env.GetOrDefaultString(EnvAPIEndpoint, defaultEndpoint))
|
||||
|
||||
return &Config{
|
||||
Endpoint: endpoint,
|
||||
Context: env.GetOrDefaultInt(envAPIEndpointContext, defaultEndpointContext),
|
||||
TTL: env.GetOrDefaultInt(envTTL, defaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(envPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(envPollingInterval, 2*time.Second),
|
||||
Context: env.GetOrDefaultInt(EnvAPIEndpointContext, defaultEndpointContext),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond(envHTTPTimeout, 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -62,14 +66,14 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
|||
}
|
||||
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(envAPIUser, envAPIPassword)
|
||||
values, err := env.Get(EnvAPIUser, EnvAPIPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("autodns: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Username = values[envAPIUser]
|
||||
config.Password = values[envAPIPassword]
|
||||
config.Username = values[EnvAPIUser]
|
||||
config.Password = values[EnvAPIPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest(envAPIEndpoint, envAPIUser, envAPIPassword)
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
EnvAPIEndpoint,
|
||||
EnvAPIUser,
|
||||
EnvAPIPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -19,31 +25,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
envAPIUser: "123",
|
||||
envAPIPassword: "456",
|
||||
EnvAPIUser: "123",
|
||||
EnvAPIPassword: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
envAPIUser: "",
|
||||
envAPIPassword: "",
|
||||
EnvAPIUser: "",
|
||||
EnvAPIPassword: "",
|
||||
},
|
||||
expected: "autodns: some credentials information are missing: AUTODNS_API_USER,AUTODNS_API_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing user id",
|
||||
envVars: map[string]string{
|
||||
envAPIUser: "",
|
||||
envAPIPassword: "456",
|
||||
EnvAPIUser: "",
|
||||
EnvAPIPassword: "456",
|
||||
},
|
||||
expected: "autodns: some credentials information are missing: AUTODNS_API_USER",
|
||||
},
|
||||
{
|
||||
desc: "missing key",
|
||||
envVars: map[string]string{
|
||||
envAPIUser: "123",
|
||||
envAPIPassword: "",
|
||||
EnvAPIUser: "123",
|
||||
EnvAPIPassword: "",
|
||||
},
|
||||
expected: "autodns: some credentials information are missing: AUTODNS_API_PASSWORD",
|
||||
},
|
||||
|
|
|
@ -23,6 +23,22 @@ import (
|
|||
|
||||
const defaultMetadataEndpoint = "http://169.254.169.254"
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "AZURE_"
|
||||
|
||||
EnvMetadataEndpoint = envNamespace + "METADATA_ENDPOINT"
|
||||
EnvSubscriptionID = envNamespace + "SUBSCRIPTION_ID"
|
||||
EnvResourceGroup = envNamespace + "RESOURCE_GROUP"
|
||||
EnvTenantID = envNamespace + "TENANT_ID"
|
||||
EnvClientID = envNamespace + "CLIENT_ID"
|
||||
EnvClientSecret = envNamespace + "CLIENT_SECRET"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
// optional if using instance metadata service
|
||||
|
@ -44,10 +60,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("AZURE_TTL", 60),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("AZURE_PROPAGATION_TIMEOUT", 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("AZURE_POLLING_INTERVAL", 2*time.Second),
|
||||
MetadataEndpoint: env.GetOrFile("AZURE_METADATA_ENDPOINT"),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 60),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
MetadataEndpoint: env.GetOrFile(EnvMetadataEndpoint),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,8 +81,8 @@ type DNSProvider struct {
|
|||
// see: https://github.com/Azure/go-autorest/blob/v10.14.0/autorest/azure/auth/auth.go#L38-L42
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
config := NewDefaultConfig()
|
||||
config.SubscriptionID = env.GetOrFile("AZURE_SUBSCRIPTION_ID")
|
||||
config.ResourceGroup = env.GetOrFile("AZURE_RESOURCE_GROUP")
|
||||
config.SubscriptionID = env.GetOrFile(EnvSubscriptionID)
|
||||
config.ResourceGroup = env.GetOrFile(EnvResourceGroup)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -10,13 +10,15 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"AZURE_CLIENT_ID",
|
||||
"AZURE_CLIENT_SECRET",
|
||||
"AZURE_SUBSCRIPTION_ID",
|
||||
"AZURE_TENANT_ID",
|
||||
"AZURE_RESOURCE_GROUP").
|
||||
WithDomain("AZURE_DOMAIN")
|
||||
EnvClientID,
|
||||
EnvClientSecret,
|
||||
EnvSubscriptionID,
|
||||
EnvTenantID,
|
||||
EnvResourceGroup).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -27,21 +29,21 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"AZURE_CLIENT_ID": "A",
|
||||
"AZURE_CLIENT_SECRET": "B",
|
||||
"AZURE_TENANT_ID": "C",
|
||||
"AZURE_SUBSCRIPTION_ID": "D",
|
||||
"AZURE_RESOURCE_GROUP": "E",
|
||||
EnvClientID: "A",
|
||||
EnvClientSecret: "B",
|
||||
EnvTenantID: "C",
|
||||
EnvSubscriptionID: "D",
|
||||
EnvResourceGroup: "E",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing client ID",
|
||||
envVars: map[string]string{
|
||||
"AZURE_CLIENT_ID": "",
|
||||
"AZURE_CLIENT_SECRET": "B",
|
||||
"AZURE_TENANT_ID": "C",
|
||||
"AZURE_SUBSCRIPTION_ID": "D",
|
||||
"AZURE_RESOURCE_GROUP": "E",
|
||||
EnvClientID: "",
|
||||
EnvClientSecret: "B",
|
||||
EnvTenantID: "C",
|
||||
EnvSubscriptionID: "D",
|
||||
EnvResourceGroup: "E",
|
||||
},
|
||||
expected: "failed to get oauth token from client credentials: parameter 'clientID' cannot be empty",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,17 @@ import (
|
|||
"github.com/labbsr0x/bindman-dns-webhook/src/client"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "BINDMAN_"
|
||||
|
||||
EnvManagerAddress = envNamespace + "MANAGER_ADDRESS"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
PropagationTimeout time.Duration
|
||||
|
@ -23,10 +34,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("BINDMAN_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("BINDMAN_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("BINDMAN_HTTP_TIMEOUT", time.Minute),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, time.Minute),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -41,13 +52,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Bindman.
|
||||
// BINDMAN_MANAGER_ADDRESS should have the scheme, hostname, and port (if required) of the authoritative Bindman Manager server.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("BINDMAN_MANAGER_ADDRESS")
|
||||
values, err := env.Get(EnvManagerAddress)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bindman: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.BaseURL = values["BINDMAN_MANAGER_ADDRESS"]
|
||||
config.BaseURL = values[EnvManagerAddress]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("BINDMAN_MANAGER_ADDRESS").WithDomain("BINDMAN_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvManagerAddress).WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -23,20 +25,20 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"BINDMAN_MANAGER_ADDRESS": "http://localhost",
|
||||
EnvManagerAddress: "http://localhost",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing bindman manager address",
|
||||
envVars: map[string]string{
|
||||
"BINDMAN_MANAGER_ADDRESS": "",
|
||||
EnvManagerAddress: "",
|
||||
},
|
||||
expected: "bindman: some credentials information are missing: BINDMAN_MANAGER_ADDRESS",
|
||||
},
|
||||
{
|
||||
desc: "empty bindman manager address",
|
||||
envVars: map[string]string{
|
||||
"BINDMAN_MANAGER_ADDRESS": " ",
|
||||
EnvManagerAddress: " ",
|
||||
},
|
||||
expected: "bindman: managerAddress parameter must be a non-empty string",
|
||||
},
|
||||
|
|
|
@ -21,6 +21,22 @@ const (
|
|||
txtType = "TXTRecord"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "BLUECAT_"
|
||||
|
||||
EnvServerURL = envNamespace + "SERVER_URL"
|
||||
EnvUserName = envNamespace + "USER_NAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
EnvConfigName = envNamespace + "CONFIG_NAME"
|
||||
EnvDNSView = envNamespace + "DNS_VIEW"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -37,11 +53,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("BLUECAT_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("BLUECAT_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("BLUECAT_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("BLUECAT_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -59,17 +75,17 @@ type DNSProvider struct {
|
|||
// The REST endpoint will be appended.
|
||||
// In addition, the Configuration name and external DNS View Name must be passed in BLUECAT_CONFIG_NAME and BLUECAT_DNS_VIEW
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("BLUECAT_SERVER_URL", "BLUECAT_USER_NAME", "BLUECAT_PASSWORD", "BLUECAT_CONFIG_NAME", "BLUECAT_DNS_VIEW")
|
||||
values, err := env.Get(EnvServerURL, EnvUserName, EnvPassword, EnvConfigName, EnvDNSView)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bluecat: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.BaseURL = values["BLUECAT_SERVER_URL"]
|
||||
config.UserName = values["BLUECAT_USER_NAME"]
|
||||
config.Password = values["BLUECAT_PASSWORD"]
|
||||
config.ConfigName = values["BLUECAT_CONFIG_NAME"]
|
||||
config.DNSView = values["BLUECAT_DNS_VIEW"]
|
||||
config.BaseURL = values[EnvServerURL]
|
||||
config.UserName = values[EnvUserName]
|
||||
config.Password = values[EnvPassword]
|
||||
config.ConfigName = values[EnvConfigName]
|
||||
config.DNSView = values[EnvDNSView]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"BLUECAT_SERVER_URL",
|
||||
"BLUECAT_USER_NAME",
|
||||
"BLUECAT_PASSWORD",
|
||||
"BLUECAT_CONFIG_NAME",
|
||||
"BLUECAT_DNS_VIEW").
|
||||
WithDomain("BLUECAT_DOMAIN")
|
||||
EnvServerURL,
|
||||
EnvUserName,
|
||||
EnvPassword,
|
||||
EnvConfigName,
|
||||
EnvDNSView).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -25,76 +27,76 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "http://localhost",
|
||||
"BLUECAT_USER_NAME": "A",
|
||||
"BLUECAT_PASSWORD": "B",
|
||||
"BLUECAT_CONFIG_NAME": "C",
|
||||
"BLUECAT_DNS_VIEW": "D",
|
||||
EnvServerURL: "http://localhost",
|
||||
EnvUserName: "A",
|
||||
EnvPassword: "B",
|
||||
EnvConfigName: "C",
|
||||
EnvDNSView: "D",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "",
|
||||
"BLUECAT_USER_NAME": "",
|
||||
"BLUECAT_PASSWORD": "",
|
||||
"BLUECAT_CONFIG_NAME": "",
|
||||
"BLUECAT_DNS_VIEW": "",
|
||||
EnvServerURL: "",
|
||||
EnvUserName: "",
|
||||
EnvPassword: "",
|
||||
EnvConfigName: "",
|
||||
EnvDNSView: "",
|
||||
},
|
||||
expected: "bluecat: some credentials information are missing: BLUECAT_SERVER_URL,BLUECAT_USER_NAME,BLUECAT_PASSWORD,BLUECAT_CONFIG_NAME,BLUECAT_DNS_VIEW",
|
||||
},
|
||||
{
|
||||
desc: "missing server url",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "",
|
||||
"BLUECAT_USER_NAME": "A",
|
||||
"BLUECAT_PASSWORD": "B",
|
||||
"BLUECAT_CONFIG_NAME": "C",
|
||||
"BLUECAT_DNS_VIEW": "D",
|
||||
EnvServerURL: "",
|
||||
EnvUserName: "A",
|
||||
EnvPassword: "B",
|
||||
EnvConfigName: "C",
|
||||
EnvDNSView: "D",
|
||||
},
|
||||
expected: "bluecat: some credentials information are missing: BLUECAT_SERVER_URL",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "http://localhost",
|
||||
"BLUECAT_USER_NAME": "",
|
||||
"BLUECAT_PASSWORD": "B",
|
||||
"BLUECAT_CONFIG_NAME": "C",
|
||||
"BLUECAT_DNS_VIEW": "D",
|
||||
EnvServerURL: "http://localhost",
|
||||
EnvUserName: "",
|
||||
EnvPassword: "B",
|
||||
EnvConfigName: "C",
|
||||
EnvDNSView: "D",
|
||||
},
|
||||
expected: "bluecat: some credentials information are missing: BLUECAT_USER_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "http://localhost",
|
||||
"BLUECAT_USER_NAME": "A",
|
||||
"BLUECAT_PASSWORD": "",
|
||||
"BLUECAT_CONFIG_NAME": "C",
|
||||
"BLUECAT_DNS_VIEW": "D",
|
||||
EnvServerURL: "http://localhost",
|
||||
EnvUserName: "A",
|
||||
EnvPassword: "",
|
||||
EnvConfigName: "C",
|
||||
EnvDNSView: "D",
|
||||
},
|
||||
expected: "bluecat: some credentials information are missing: BLUECAT_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing config name",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "http://localhost",
|
||||
"BLUECAT_USER_NAME": "A",
|
||||
"BLUECAT_PASSWORD": "B",
|
||||
"BLUECAT_CONFIG_NAME": "",
|
||||
"BLUECAT_DNS_VIEW": "D",
|
||||
EnvServerURL: "http://localhost",
|
||||
EnvUserName: "A",
|
||||
EnvPassword: "B",
|
||||
EnvConfigName: "",
|
||||
EnvDNSView: "D",
|
||||
},
|
||||
expected: "bluecat: some credentials information are missing: BLUECAT_CONFIG_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing DNS view",
|
||||
envVars: map[string]string{
|
||||
"BLUECAT_SERVER_URL": "http://localhost",
|
||||
"BLUECAT_USER_NAME": "A",
|
||||
"BLUECAT_PASSWORD": "B",
|
||||
"BLUECAT_CONFIG_NAME": "C",
|
||||
"BLUECAT_DNS_VIEW": "",
|
||||
EnvServerURL: "http://localhost",
|
||||
EnvUserName: "A",
|
||||
EnvPassword: "B",
|
||||
EnvConfigName: "C",
|
||||
EnvDNSView: "",
|
||||
},
|
||||
expected: "bluecat: some credentials information are missing: BLUECAT_DNS_VIEW",
|
||||
},
|
||||
|
|
|
@ -12,13 +12,17 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envEndpoint = "CHECKDOMAIN_ENDPOINT"
|
||||
envToken = "CHECKDOMAIN_TOKEN"
|
||||
envTTL = "CHECKDOMAIN_TTL"
|
||||
envHTTPTimeout = "CHECKDOMAIN_HTTP_TIMEOUT"
|
||||
envPropagationTimeout = "CHECKDOMAIN_PROPAGATION_TIMEOUT"
|
||||
envPollingInterval = "CHECKDOMAIN_POLLING_INTERVAL"
|
||||
envNamespace = "CHECKDOMAIN_"
|
||||
|
||||
EnvEndpoint = envNamespace + "ENDPOINT"
|
||||
EnvToken = envNamespace + "TOKEN"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -39,11 +43,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt(envTTL, defaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(envPropagationTimeout, 5*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(envPollingInterval, 7*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 5*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 7*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond(envHTTPTimeout, 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -58,17 +62,17 @@ type DNSProvider struct {
|
|||
}
|
||||
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(envToken)
|
||||
values, err := env.Get(EnvToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("checkdomain: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Token = values[envToken]
|
||||
config.Token = values[EnvToken]
|
||||
|
||||
endpoint, err := url.Parse(env.GetOrDefaultString(envEndpoint, defaultEndpoint))
|
||||
endpoint, err := url.Parse(env.GetOrDefaultString(EnvEndpoint, defaultEndpoint))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("checkdomain: invalid %s: %w", envEndpoint, err)
|
||||
return nil, fmt.Errorf("checkdomain: invalid %s: %w", EnvEndpoint, err)
|
||||
}
|
||||
config.Endpoint = endpoint
|
||||
|
||||
|
|
|
@ -9,7 +9,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest(envEndpoint, envToken)
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
EnvEndpoint,
|
||||
EnvToken).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -20,7 +25,7 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
envToken: "dummy",
|
||||
EnvToken: "dummy",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -31,8 +36,8 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "invalid endpoint",
|
||||
envVars: map[string]string{
|
||||
envToken: "dummy",
|
||||
envEndpoint: ":",
|
||||
EnvToken: "dummy",
|
||||
EnvEndpoint: ":",
|
||||
},
|
||||
expected: `checkdomain: invalid CHECKDOMAIN_ENDPOINT: parse ":": missing protocol scheme`,
|
||||
},
|
||||
|
|
|
@ -12,6 +12,19 @@ import (
|
|||
"github.com/go-acme/lego/v3/providers/dns/cloudns/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "CLOUDNS_"
|
||||
|
||||
EnvAuthID = envNamespace + "AUTH_ID"
|
||||
EnvAuthPassword = envNamespace + "AUTH_PASSWORD"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
AuthID string
|
||||
|
@ -25,11 +38,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("CLOUDNS_PROPAGATION_TIMEOUT", 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond("CLOUDNS_POLLING_INTERVAL", 4*time.Second),
|
||||
TTL: env.GetOrDefaultInt("CLOUDNS_TTL", 60),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 60),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 4*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("CLOUDNS_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -44,14 +57,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// CLOUDNS_AUTH_ID and CLOUDNS_AUTH_PASSWORD.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("CLOUDNS_AUTH_ID", "CLOUDNS_AUTH_PASSWORD")
|
||||
values, err := env.Get(EnvAuthID, EnvAuthPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ClouDNS: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.AuthID = values["CLOUDNS_AUTH_ID"]
|
||||
config.AuthPassword = values["CLOUDNS_AUTH_PASSWORD"]
|
||||
config.AuthID = values[EnvAuthID]
|
||||
config.AuthPassword = values[EnvAuthPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"CLOUDNS_AUTH_ID",
|
||||
"CLOUDNS_AUTH_PASSWORD").
|
||||
WithDomain("CLOUDNS_DOMAIN")
|
||||
EnvAuthID,
|
||||
EnvAuthPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"CLOUDNS_AUTH_ID": "123",
|
||||
"CLOUDNS_AUTH_PASSWORD": "456",
|
||||
EnvAuthID: "123",
|
||||
EnvAuthPassword: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"CLOUDNS_AUTH_ID": "",
|
||||
"CLOUDNS_AUTH_PASSWORD": "",
|
||||
EnvAuthID: "",
|
||||
EnvAuthPassword: "",
|
||||
},
|
||||
expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_ID,CLOUDNS_AUTH_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing auth-id",
|
||||
envVars: map[string]string{
|
||||
"CLOUDNS_AUTH_ID": "",
|
||||
"CLOUDNS_AUTH_PASSWORD": "456",
|
||||
EnvAuthID: "",
|
||||
EnvAuthPassword: "456",
|
||||
},
|
||||
expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_ID",
|
||||
},
|
||||
{
|
||||
desc: "missing auth-password",
|
||||
envVars: map[string]string{
|
||||
"CLOUDNS_AUTH_ID": "123",
|
||||
"CLOUDNS_AUTH_PASSWORD": "",
|
||||
EnvAuthID: "123",
|
||||
EnvAuthPassword: "",
|
||||
},
|
||||
expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_PASSWORD",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,19 @@ import (
|
|||
"github.com/go-acme/lego/v3/providers/dns/cloudxns/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "CLOUDXNS_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvSecretKey = envNamespace + "SECRET_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -25,11 +38,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("CLOUDXNS_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("CLOUDXNS_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt("CLOUDXNS_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("CLOUDXNS_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -44,14 +57,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// CLOUDXNS_API_KEY and CLOUDXNS_SECRET_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("CLOUDXNS_API_KEY", "CLOUDXNS_SECRET_KEY")
|
||||
values, err := env.Get(EnvAPIKey, EnvSecretKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("CloudXNS: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["CLOUDXNS_API_KEY"]
|
||||
config.SecretKey = values["CLOUDXNS_SECRET_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.SecretKey = values[EnvSecretKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"CLOUDXNS_API_KEY",
|
||||
"CLOUDXNS_SECRET_KEY").
|
||||
WithDomain("CLOUDXNS_DOMAIN")
|
||||
EnvAPIKey,
|
||||
EnvSecretKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"CLOUDXNS_API_KEY": "123",
|
||||
"CLOUDXNS_SECRET_KEY": "456",
|
||||
EnvAPIKey: "123",
|
||||
EnvSecretKey: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"CLOUDXNS_API_KEY": "",
|
||||
"CLOUDXNS_SECRET_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
EnvSecretKey: "",
|
||||
},
|
||||
expected: "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY,CLOUDXNS_SECRET_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing API key",
|
||||
envVars: map[string]string{
|
||||
"CLOUDXNS_API_KEY": "",
|
||||
"CLOUDXNS_SECRET_KEY": "456",
|
||||
EnvAPIKey: "",
|
||||
EnvSecretKey: "456",
|
||||
},
|
||||
expected: "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"CLOUDXNS_API_KEY": "123",
|
||||
"CLOUDXNS_SECRET_KEY": "",
|
||||
EnvAPIKey: "123",
|
||||
EnvSecretKey: "",
|
||||
},
|
||||
expected: "CloudXNS: some credentials information are missing: CLOUDXNS_SECRET_KEY",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,21 @@ import (
|
|||
"github.com/go-acme/lego/v3/providers/dns/conoha/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "CONOHA_"
|
||||
|
||||
EnvRegion = envNamespace + "REGION"
|
||||
EnvTenantID = envNamespace + "TENANT_ID"
|
||||
EnvAPIUsername = envNamespace + "API_USERNAME"
|
||||
EnvAPIPassword = envNamespace + "API_PASSWORD"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Region string
|
||||
|
@ -27,12 +42,12 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
Region: env.GetOrDefaultString("CONOHA_REGION", "tyo1"),
|
||||
TTL: env.GetOrDefaultInt("CONOHA_TTL", 60),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("CONOHA_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("CONOHA_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
Region: env.GetOrDefaultString(EnvRegion, "tyo1"),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 60),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("CONOHA_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -46,15 +61,15 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for ConoHa DNS.
|
||||
// Credentials must be passed in the environment variables: CONOHA_TENANT_ID, CONOHA_API_USERNAME, CONOHA_API_PASSWORD
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("CONOHA_TENANT_ID", "CONOHA_API_USERNAME", "CONOHA_API_PASSWORD")
|
||||
values, err := env.Get(EnvTenantID, EnvAPIUsername, EnvAPIPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("conoha: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.TenantID = values["CONOHA_TENANT_ID"]
|
||||
config.Username = values["CONOHA_API_USERNAME"]
|
||||
config.Password = values["CONOHA_API_PASSWORD"]
|
||||
config.TenantID = values[EnvTenantID]
|
||||
config.Username = values[EnvAPIUsername]
|
||||
config.Password = values[EnvAPIPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"CONOHA_TENANT_ID",
|
||||
"CONOHA_API_USERNAME",
|
||||
"CONOHA_API_PASSWORD").
|
||||
WithDomain("CONOHA_DOMAIN")
|
||||
EnvTenantID,
|
||||
EnvAPIUsername,
|
||||
EnvAPIPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -23,45 +25,45 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "complete credentials, but login failed",
|
||||
envVars: map[string]string{
|
||||
"CONOHA_TENANT_ID": "tenant_id",
|
||||
"CONOHA_API_USERNAME": "api_username",
|
||||
"CONOHA_API_PASSWORD": "api_password",
|
||||
EnvTenantID: "tenant_id",
|
||||
EnvAPIUsername: "api_username",
|
||||
EnvAPIPassword: "api_password",
|
||||
},
|
||||
expected: `conoha: failed to create client: failed to login: HTTP request failed with status code 401: {"unauthorized":{"message":"Invalid user: api_username","code":401}}`,
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"CONOHA_TENANT_ID": "",
|
||||
"CONOHA_API_USERNAME": "",
|
||||
"CONOHA_API_PASSWORD": "",
|
||||
EnvTenantID: "",
|
||||
EnvAPIUsername: "",
|
||||
EnvAPIPassword: "",
|
||||
},
|
||||
expected: "conoha: some credentials information are missing: CONOHA_TENANT_ID,CONOHA_API_USERNAME,CONOHA_API_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing tenant id",
|
||||
envVars: map[string]string{
|
||||
"CONOHA_TENANT_ID": "",
|
||||
"CONOHA_API_USERNAME": "api_username",
|
||||
"CONOHA_API_PASSWORD": "api_password",
|
||||
EnvTenantID: "",
|
||||
EnvAPIUsername: "api_username",
|
||||
EnvAPIPassword: "api_password",
|
||||
},
|
||||
expected: "conoha: some credentials information are missing: CONOHA_TENANT_ID",
|
||||
},
|
||||
{
|
||||
desc: "missing api username",
|
||||
envVars: map[string]string{
|
||||
"CONOHA_TENANT_ID": "tenant_id",
|
||||
"CONOHA_API_USERNAME": "",
|
||||
"CONOHA_API_PASSWORD": "api_password",
|
||||
EnvTenantID: "tenant_id",
|
||||
EnvAPIUsername: "",
|
||||
EnvAPIPassword: "api_password",
|
||||
},
|
||||
expected: "conoha: some credentials information are missing: CONOHA_API_USERNAME",
|
||||
},
|
||||
{
|
||||
desc: "missing api password",
|
||||
envVars: map[string]string{
|
||||
"CONOHA_TENANT_ID": "tenant_id",
|
||||
"CONOHA_API_USERNAME": "api_username",
|
||||
"CONOHA_API_PASSWORD": "",
|
||||
EnvTenantID: "tenant_id",
|
||||
EnvAPIUsername: "api_username",
|
||||
EnvAPIPassword: "",
|
||||
},
|
||||
expected: "conoha: some credentials information are missing: CONOHA_API_PASSWORD",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,19 @@ import (
|
|||
"github.com/go-acme/lego/v3/providers/dns/constellix/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "CONSTELLIX_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvSecretKey = envNamespace + "SECRET_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -25,11 +38,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("CONSTELLIX_TTL", 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("CONSTELLIX_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("CONSTELLIX_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("CONSTELLIX_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -44,14 +57,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// CONSTELLIX_API_KEY and CONSTELLIX_SECRET_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("CONSTELLIX_API_KEY", "CONSTELLIX_SECRET_KEY")
|
||||
values, err := env.Get(EnvAPIKey, EnvSecretKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("constellix: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["CONSTELLIX_API_KEY"]
|
||||
config.SecretKey = values["CONSTELLIX_SECRET_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.SecretKey = values[EnvSecretKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"CONSTELLIX_API_KEY",
|
||||
"CONSTELLIX_SECRET_KEY").
|
||||
WithDomain("CONSTELLIX_DOMAIN")
|
||||
EnvAPIKey,
|
||||
EnvSecretKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"CONSTELLIX_API_KEY": "123",
|
||||
"CONSTELLIX_SECRET_KEY": "456",
|
||||
EnvAPIKey: "123",
|
||||
EnvSecretKey: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"CONSTELLIX_API_KEY": "",
|
||||
"CONSTELLIX_SECRET_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
EnvSecretKey: "",
|
||||
},
|
||||
expected: "constellix: some credentials information are missing: CONSTELLIX_API_KEY,CONSTELLIX_SECRET_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"CONSTELLIX_API_KEY": "",
|
||||
"CONSTELLIX_SECRET_KEY": "api_password",
|
||||
EnvAPIKey: "",
|
||||
EnvSecretKey: "api_password",
|
||||
},
|
||||
expected: "constellix: some credentials information are missing: CONSTELLIX_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"CONSTELLIX_API_KEY": "api_username",
|
||||
"CONSTELLIX_SECRET_KEY": "",
|
||||
EnvAPIKey: "api_username",
|
||||
EnvSecretKey: "",
|
||||
},
|
||||
expected: "constellix: some credentials information are missing: CONSTELLIX_SECRET_KEY",
|
||||
},
|
||||
|
|
|
@ -17,6 +17,24 @@ import (
|
|||
"github.com/gophercloud/gophercloud/openstack/dns/v2/zones"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DESIGNATE_"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
|
||||
envNamespaceClient = "OS_"
|
||||
|
||||
EnvAuthURL = envNamespaceClient + "AUTH_URL"
|
||||
EnvUsername = envNamespaceClient + "USERNAME"
|
||||
EnvPassword = envNamespaceClient + "PASSWORD"
|
||||
EnvTenantName = envNamespaceClient + "TENANT_NAME"
|
||||
EnvRegionName = envNamespaceClient + "REGION_NAME"
|
||||
EnvProjectID = envNamespaceClient + "PROJECT_ID"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
PropagationTimeout time.Duration
|
||||
|
@ -28,9 +46,9 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("DESIGNATE_TTL", 10),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DESIGNATE_PROPAGATION_TIMEOUT", 10*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("DESIGNATE_POLLING_INTERVAL", 10*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 10),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 10*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 10*time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +63,7 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, OS_TENANT_NAME, OS_REGION_NAME.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
_, err := env.Get("OS_AUTH_URL", "OS_USERNAME", "OS_PASSWORD", "OS_TENANT_NAME", "OS_REGION_NAME")
|
||||
_, err := env.Get(EnvAuthURL, EnvUsername, EnvPassword, EnvTenantName, EnvRegionName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("designate: %w", err)
|
||||
}
|
||||
|
|
|
@ -10,14 +10,16 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"OS_AUTH_URL",
|
||||
"OS_USERNAME",
|
||||
"OS_PASSWORD",
|
||||
"OS_TENANT_NAME",
|
||||
"OS_REGION_NAME",
|
||||
"OS_PROJECT_ID").
|
||||
WithDomain("DESIGNATE_DOMAIN")
|
||||
EnvAuthURL,
|
||||
EnvUsername,
|
||||
EnvPassword,
|
||||
EnvTenantName,
|
||||
EnvRegionName,
|
||||
EnvProjectID).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
server := getServer()
|
||||
|
@ -31,77 +33,77 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": server.URL + "/v2.0/",
|
||||
"OS_USERNAME": "B",
|
||||
"OS_PASSWORD": "C",
|
||||
"OS_REGION_NAME": "D",
|
||||
"OS_TENANT_NAME": "E",
|
||||
"OS_PROJECT_ID": "F",
|
||||
EnvAuthURL: server.URL + "/v2.0/",
|
||||
EnvUsername: "B",
|
||||
EnvPassword: "C",
|
||||
EnvRegionName: "D",
|
||||
EnvTenantName: "E",
|
||||
EnvProjectID: "F",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": "",
|
||||
"OS_USERNAME": "",
|
||||
"OS_PASSWORD": "",
|
||||
"OS_REGION_NAME": "",
|
||||
"OS_TENANT_NAME": "",
|
||||
EnvAuthURL: "",
|
||||
EnvUsername: "",
|
||||
EnvPassword: "",
|
||||
EnvRegionName: "",
|
||||
EnvTenantName: "",
|
||||
},
|
||||
expected: "designate: some credentials information are missing: OS_AUTH_URL,OS_USERNAME,OS_PASSWORD,OS_TENANT_NAME,OS_REGION_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing auth url",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": "",
|
||||
"OS_USERNAME": "B",
|
||||
"OS_PASSWORD": "C",
|
||||
"OS_REGION_NAME": "D",
|
||||
"OS_TENANT_NAME": "E",
|
||||
EnvAuthURL: "",
|
||||
EnvUsername: "B",
|
||||
EnvPassword: "C",
|
||||
EnvRegionName: "D",
|
||||
EnvTenantName: "E",
|
||||
},
|
||||
expected: "designate: some credentials information are missing: OS_AUTH_URL",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": server.URL + "/v2.0/",
|
||||
"OS_USERNAME": "",
|
||||
"OS_PASSWORD": "C",
|
||||
"OS_REGION_NAME": "D",
|
||||
"OS_TENANT_NAME": "E",
|
||||
EnvAuthURL: server.URL + "/v2.0/",
|
||||
EnvUsername: "",
|
||||
EnvPassword: "C",
|
||||
EnvRegionName: "D",
|
||||
EnvTenantName: "E",
|
||||
},
|
||||
expected: "designate: some credentials information are missing: OS_USERNAME",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": server.URL + "/v2.0/",
|
||||
"OS_USERNAME": "B",
|
||||
"OS_PASSWORD": "",
|
||||
"OS_REGION_NAME": "D",
|
||||
"OS_TENANT_NAME": "E",
|
||||
EnvAuthURL: server.URL + "/v2.0/",
|
||||
EnvUsername: "B",
|
||||
EnvPassword: "",
|
||||
EnvRegionName: "D",
|
||||
EnvTenantName: "E",
|
||||
},
|
||||
expected: "designate: some credentials information are missing: OS_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing region name",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": server.URL + "/v2.0/",
|
||||
"OS_USERNAME": "B",
|
||||
"OS_PASSWORD": "C",
|
||||
"OS_REGION_NAME": "",
|
||||
"OS_TENANT_NAME": "E",
|
||||
EnvAuthURL: server.URL + "/v2.0/",
|
||||
EnvUsername: "B",
|
||||
EnvPassword: "C",
|
||||
EnvRegionName: "",
|
||||
EnvTenantName: "E",
|
||||
},
|
||||
expected: "designate: some credentials information are missing: OS_REGION_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing tenant name",
|
||||
envVars: map[string]string{
|
||||
"OS_AUTH_URL": server.URL + "/v2.0/",
|
||||
"OS_USERNAME": "B",
|
||||
"OS_PASSWORD": "C",
|
||||
"OS_REGION_NAME": "D",
|
||||
"OS_TENANT_NAME": "",
|
||||
EnvAuthURL: server.URL + "/v2.0/",
|
||||
EnvUsername: "B",
|
||||
EnvPassword: "C",
|
||||
EnvRegionName: "D",
|
||||
EnvTenantName: "",
|
||||
},
|
||||
expected: "designate: some credentials information are missing: OS_TENANT_NAME",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,18 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DO_"
|
||||
|
||||
EnvAuthToken = envNamespace + "AUTH_TOKEN"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -26,11 +38,11 @@ type Config struct {
|
|||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
BaseURL: defaultBaseURL,
|
||||
TTL: env.GetOrDefaultInt("DO_TTL", 30),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DO_PROPAGATION_TIMEOUT", 60*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond("DO_POLLING_INTERVAL", 5*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 30),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DO_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +59,13 @@ type DNSProvider struct {
|
|||
// Ocean. Credentials must be passed in the environment variable:
|
||||
// DO_AUTH_TOKEN.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("DO_AUTH_TOKEN")
|
||||
values, err := env.Get(EnvAuthToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("digitalocean: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.AuthToken = values["DO_AUTH_TOKEN"]
|
||||
config.AuthToken = values[EnvAuthToken]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("DO_AUTH_TOKEN")
|
||||
var envTest = tester.NewEnvTest(EnvAuthToken)
|
||||
|
||||
func setupTest() (*DNSProvider, *http.ServeMux, func()) {
|
||||
handler := http.NewServeMux()
|
||||
|
@ -39,13 +39,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DO_AUTH_TOKEN": "123",
|
||||
EnvAuthToken: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"DO_AUTH_TOKEN": "",
|
||||
EnvAuthToken: "",
|
||||
},
|
||||
expected: "digitalocean: some credentials information are missing: DO_AUTH_TOKEN",
|
||||
},
|
||||
|
|
|
@ -15,6 +15,18 @@ import (
|
|||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DNSIMPLE_"
|
||||
|
||||
EnvOAuthToken = envNamespace + "OAUTH_TOKEN"
|
||||
EnvBaseURL = envNamespace + "BASE_URL"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
AccessToken string
|
||||
|
@ -27,9 +39,9 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("DNSIMPLE_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DNSIMPLE_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("DNSIMPLE_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,8 +57,8 @@ type DNSProvider struct {
|
|||
// See: https://developer.dnsimple.com/v2/#authentication
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
config := NewDefaultConfig()
|
||||
config.AccessToken = env.GetOrFile("DNSIMPLE_OAUTH_TOKEN")
|
||||
config.BaseURL = env.GetOrFile("DNSIMPLE_BASE_URL")
|
||||
config.AccessToken = env.GetOrFile(EnvOAuthToken)
|
||||
config.BaseURL = env.GetOrFile(EnvBaseURL)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -12,11 +12,13 @@ import (
|
|||
|
||||
const sandboxURL = "https://api.sandbox.fake.com"
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"DNSIMPLE_OAUTH_TOKEN",
|
||||
"DNSIMPLE_BASE_URL").
|
||||
WithDomain("DNSIMPLE_DOMAIN").
|
||||
WithLiveTestRequirements("DNSIMPLE_OAUTH_TOKEN", "DNSIMPLE_DOMAIN")
|
||||
EnvOAuthToken,
|
||||
EnvBaseURL).
|
||||
WithDomain(envDomain).
|
||||
WithLiveTestRequirements(EnvOAuthToken, envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -27,20 +29,20 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DNSIMPLE_OAUTH_TOKEN": "my_token",
|
||||
EnvOAuthToken: "my_token",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "success: base url",
|
||||
envVars: map[string]string{
|
||||
"DNSIMPLE_OAUTH_TOKEN": "my_token",
|
||||
"DNSIMPLE_BASE_URL": "https://api.dnsimple.test",
|
||||
EnvOAuthToken: "my_token",
|
||||
EnvBaseURL: "https://api.dnsimple.test",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing oauth token",
|
||||
envVars: map[string]string{
|
||||
"DNSIMPLE_OAUTH_TOKEN": "",
|
||||
EnvOAuthToken: "",
|
||||
},
|
||||
expected: "dnsimple: OAuth token is missing",
|
||||
},
|
||||
|
@ -61,7 +63,7 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
require.NotNil(t, p.config)
|
||||
require.NotNil(t, p.client)
|
||||
|
||||
baseURL := os.Getenv("DNSIMPLE_BASE_URL")
|
||||
baseURL := os.Getenv(EnvBaseURL)
|
||||
if baseURL != "" {
|
||||
assert.Equal(t, baseURL, p.client.BaseURL)
|
||||
}
|
||||
|
@ -126,8 +128,8 @@ func TestLivePresent(t *testing.T) {
|
|||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
if len(os.Getenv("DNSIMPLE_BASE_URL")) == 0 {
|
||||
os.Setenv("DNSIMPLE_BASE_URL", sandboxURL)
|
||||
if len(os.Getenv(EnvBaseURL)) == 0 {
|
||||
os.Setenv(EnvBaseURL, sandboxURL)
|
||||
}
|
||||
|
||||
provider, err := NewDNSProvider()
|
||||
|
@ -144,8 +146,8 @@ func TestLiveCleanUp(t *testing.T) {
|
|||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
if len(os.Getenv("DNSIMPLE_BASE_URL")) == 0 {
|
||||
os.Setenv("DNSIMPLE_BASE_URL", sandboxURL)
|
||||
if len(os.Getenv(EnvBaseURL)) == 0 {
|
||||
os.Setenv(EnvBaseURL, sandboxURL)
|
||||
}
|
||||
|
||||
provider, err := NewDNSProvider()
|
||||
|
|
|
@ -14,6 +14,20 @@ import (
|
|||
"github.com/go-acme/lego/v3/providers/dns/dnsmadeeasy/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DNSMADEEASY_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvAPISecret = envNamespace + "API_SECRET"
|
||||
EnvSandbox = envNamespace + "SANDBOX"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -29,11 +43,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("DNSMADEEASY_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DNSMADEEASY_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("DNSMADEEASY_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DNSMADEEASY_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
@ -52,15 +66,15 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// DNSMADEEASY_API_KEY and DNSMADEEASY_API_SECRET.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("DNSMADEEASY_API_KEY", "DNSMADEEASY_API_SECRET")
|
||||
values, err := env.Get(EnvAPIKey, EnvAPISecret)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dnsmadeeasy: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Sandbox = env.GetOrDefaultBool("DNSMADEEASY_SANDBOX", false)
|
||||
config.APIKey = values["DNSMADEEASY_API_KEY"]
|
||||
config.APISecret = values["DNSMADEEASY_API_SECRET"]
|
||||
config.Sandbox = env.GetOrDefaultBool(EnvSandbox, false)
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.APISecret = values[EnvAPISecret]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"DNSMADEEASY_API_KEY",
|
||||
"DNSMADEEASY_API_SECRET").
|
||||
WithDomain("DNSMADEEASY_DOMAIN")
|
||||
EnvAPIKey,
|
||||
EnvAPISecret).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
os.Setenv("DNSMADEEASY_SANDBOX", "true")
|
||||
os.Setenv(EnvSandbox, "true")
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
@ -24,31 +26,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DNSMADEEASY_API_KEY": "123",
|
||||
"DNSMADEEASY_API_SECRET": "456",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPISecret: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"DNSMADEEASY_API_KEY": "",
|
||||
"DNSMADEEASY_API_SECRET": "",
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_KEY,DNSMADEEASY_API_SECRET",
|
||||
},
|
||||
{
|
||||
desc: "missing access key",
|
||||
envVars: map[string]string{
|
||||
"DNSMADEEASY_API_KEY": "",
|
||||
"DNSMADEEASY_API_SECRET": "456",
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "456",
|
||||
},
|
||||
expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"DNSMADEEASY_API_KEY": "123",
|
||||
"DNSMADEEASY_API_SECRET": "",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_SECRET",
|
||||
},
|
||||
|
@ -76,7 +78,7 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewDNSProviderConfig(t *testing.T) {
|
||||
os.Setenv("DNSMADEEASY_SANDBOX", "true")
|
||||
os.Setenv(EnvSandbox, "true")
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
@ -130,7 +132,7 @@ func TestLivePresentAndCleanup(t *testing.T) {
|
|||
t.Skip("skipping live test")
|
||||
}
|
||||
|
||||
os.Setenv("DNSMADEEASY_SANDBOX", "true")
|
||||
os.Setenv(EnvSandbox, "true")
|
||||
|
||||
envTest.RestoreEnv()
|
||||
provider, err := NewDNSProvider()
|
||||
|
|
|
@ -14,6 +14,18 @@ import (
|
|||
"github.com/nrdcg/dnspod-go"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DNSPOD_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
LoginToken string
|
||||
|
@ -26,11 +38,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("DNSPOD_TTL", 600),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DNSPOD_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("DNSPOD_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 600),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DNSPOD_HTTP_TIMEOUT", 0),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -44,13 +56,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for dnspod.
|
||||
// Credentials must be passed in the environment variables: DNSPOD_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("DNSPOD_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dnspod: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.LoginToken = values["DNSPOD_API_KEY"]
|
||||
config.LoginToken = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("DNSPOD_API_KEY").
|
||||
WithDomain("DNSPOD_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -20,13 +22,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DNSPOD_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"DNSPOD_API_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "dnspod: some credentials information are missing: DNSPOD_API_KEY",
|
||||
},
|
||||
|
|
|
@ -11,6 +11,18 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DODE_"
|
||||
|
||||
EnvToken = envNamespace + "TOKEN"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Token string
|
||||
|
@ -23,11 +35,11 @@ type Config struct {
|
|||
// 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),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DODE_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -40,13 +52,13 @@ type DNSProvider struct {
|
|||
// 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")
|
||||
values, err := env.Get(EnvToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("do.de: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Token = values["DODE_TOKEN"]
|
||||
config.Token = values[EnvToken]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("DODE_TOKEN").
|
||||
WithDomain("DODE_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvToken).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -20,13 +22,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DODE_TOKEN": "123",
|
||||
EnvToken: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"DODE_TOKEN": "",
|
||||
EnvToken: "",
|
||||
},
|
||||
expected: "do.de: some credentials information are missing: DODE_TOKEN",
|
||||
},
|
||||
|
|
|
@ -13,6 +13,17 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DREAMHOST_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -26,10 +37,10 @@ type Config struct {
|
|||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
BaseURL: defaultBaseURL,
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DREAMHOST_PROPAGATION_TIMEOUT", 60*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("DREAMHOST_POLLING_INTERVAL", 1*time.Minute),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 1*time.Minute),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DREAMHOST_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -42,13 +53,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a new DNS provider using
|
||||
// environment variable DREAMHOST_API_KEY for adding and removing the DNS record.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("DREAMHOST_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dreamhost: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["DREAMHOST_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("DREAMHOST_API_KEY").
|
||||
WithDomain("DREAMHOST_TEST_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
const (
|
||||
fakeAPIKey = "asdf1234"
|
||||
|
@ -46,13 +48,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DREAMHOST_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing API key",
|
||||
envVars: map[string]string{
|
||||
"DREAMHOST_API_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "dreamhost: some credentials information are missing: DREAMHOST_API_KEY",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,18 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DUCKDNS_"
|
||||
|
||||
EnvToken = envNamespace + "TOKEN"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Token string
|
||||
|
@ -24,11 +36,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DUCKDNS_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("DUCKDNS_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
SequenceInterval: env.GetOrDefaultSecond("DUCKDNS_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DUCKDNS_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -41,13 +53,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a new DNS provider using
|
||||
// environment variable DUCKDNS_TOKEN for adding and removing the DNS record.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("DUCKDNS_TOKEN")
|
||||
values, err := env.Get(EnvToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("duckdns: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Token = values["DUCKDNS_TOKEN"]
|
||||
config.Token = values[EnvToken]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("DUCKDNS_TOKEN").
|
||||
WithDomain("DUCKDNS_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvToken).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -21,13 +23,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DUCKDNS_TOKEN": "123",
|
||||
EnvToken: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"DUCKDNS_TOKEN": "",
|
||||
EnvToken: "",
|
||||
},
|
||||
expected: "duckdns: some credentials information are missing: DUCKDNS_TOKEN",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,20 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "DYN_"
|
||||
|
||||
EnvCustomerName = envNamespace + "CUSTOMER_NAME"
|
||||
EnvUserName = envNamespace + "USER_NAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
CustomerName string
|
||||
|
@ -26,11 +40,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("DYN_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("DYN_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("DYN_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("DYN_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -46,15 +60,15 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// DYN_CUSTOMER_NAME, DYN_USER_NAME and DYN_PASSWORD.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("DYN_CUSTOMER_NAME", "DYN_USER_NAME", "DYN_PASSWORD")
|
||||
values, err := env.Get(EnvCustomerName, EnvUserName, EnvPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dyn: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.CustomerName = values["DYN_CUSTOMER_NAME"]
|
||||
config.UserName = values["DYN_USER_NAME"]
|
||||
config.Password = values["DYN_PASSWORD"]
|
||||
config.CustomerName = values[EnvCustomerName]
|
||||
config.UserName = values[EnvUserName]
|
||||
config.Password = values[EnvPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"DYN_CUSTOMER_NAME",
|
||||
"DYN_USER_NAME",
|
||||
"DYN_PASSWORD").
|
||||
WithDomain("DYN_DOMAIN")
|
||||
EnvCustomerName,
|
||||
EnvUserName,
|
||||
EnvPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -23,44 +25,44 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"DYN_CUSTOMER_NAME": "A",
|
||||
"DYN_USER_NAME": "B",
|
||||
"DYN_PASSWORD": "C",
|
||||
EnvCustomerName: "A",
|
||||
EnvUserName: "B",
|
||||
EnvPassword: "C",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"DYN_CUSTOMER_NAME": "",
|
||||
"DYN_USER_NAME": "",
|
||||
"DYN_PASSWORD": "",
|
||||
EnvCustomerName: "",
|
||||
EnvUserName: "",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "dyn: some credentials information are missing: DYN_CUSTOMER_NAME,DYN_USER_NAME,DYN_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing customer name",
|
||||
envVars: map[string]string{
|
||||
"DYN_CUSTOMER_NAME": "",
|
||||
"DYN_USER_NAME": "B",
|
||||
"DYN_PASSWORD": "C",
|
||||
EnvCustomerName: "",
|
||||
EnvUserName: "B",
|
||||
EnvPassword: "C",
|
||||
},
|
||||
expected: "dyn: some credentials information are missing: DYN_CUSTOMER_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
envVars: map[string]string{
|
||||
"DYN_CUSTOMER_NAME": "A",
|
||||
"DYN_USER_NAME": "",
|
||||
"DYN_PASSWORD": "C",
|
||||
EnvCustomerName: "A",
|
||||
EnvUserName: "",
|
||||
EnvPassword: "C",
|
||||
},
|
||||
expected: "dyn: some credentials information are missing: DYN_USER_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"DYN_CUSTOMER_NAME": "A",
|
||||
"DYN_USER_NAME": "B",
|
||||
"DYN_PASSWORD": "",
|
||||
EnvCustomerName: "A",
|
||||
EnvUserName: "B",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "dyn: some credentials information are missing: DYN_PASSWORD",
|
||||
},
|
||||
|
|
|
@ -123,7 +123,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||
NodeName: dns01.UnFqdn(strings.TrimSuffix(fqdn, dns.Fqdn(domain))),
|
||||
TextData: value,
|
||||
State: true,
|
||||
TTL: 300,
|
||||
TTL: d.config.TTL,
|
||||
}
|
||||
|
||||
err = d.client.AddNewRecord(rootDomain.ID, record)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "_DOMAIN"
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
EnvAPIKey).
|
||||
|
|
|
@ -16,6 +16,21 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "EASYDNS_"
|
||||
|
||||
EnvEndpoint = envNamespace + "ENDPOINT"
|
||||
EnvToken = envNamespace + "TOKEN"
|
||||
EnvKey = envNamespace + "KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Endpoint *url.URL
|
||||
|
@ -31,12 +46,12 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("EASYDNS_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
SequenceInterval: env.GetOrDefaultSecond("EASYDNS_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("EASYDNS_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt("EASYDNS_TTL", dns01.DefaultTTL),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("EASYDNS_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -52,19 +67,19 @@ type DNSProvider struct {
|
|||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
config := NewDefaultConfig()
|
||||
|
||||
endpoint, err := url.Parse(env.GetOrDefaultString("EASYDNS_ENDPOINT", defaultEndpoint))
|
||||
endpoint, err := url.Parse(env.GetOrDefaultString(EnvEndpoint, defaultEndpoint))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("easydns: %w", err)
|
||||
}
|
||||
config.Endpoint = endpoint
|
||||
|
||||
values, err := env.Get("EASYDNS_TOKEN", "EASYDNS_KEY")
|
||||
values, err := env.Get(EnvToken, EnvKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("easydns: %w", err)
|
||||
}
|
||||
|
||||
config.Token = values["EASYDNS_TOKEN"]
|
||||
config.Key = values["EASYDNS_KEY"]
|
||||
config.Token = values[EnvToken]
|
||||
config.Key = values[EnvKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -14,11 +14,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"EASYDNS_ENDPOINT",
|
||||
"EASYDNS_TOKEN",
|
||||
"EASYDNS_KEY").
|
||||
WithDomain("EASYDNS_DOMAIN")
|
||||
EnvEndpoint,
|
||||
EnvToken,
|
||||
EnvKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func setup() (*DNSProvider, *http.ServeMux, func()) {
|
||||
handler := http.NewServeMux()
|
||||
|
@ -51,21 +53,21 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"EASYDNS_TOKEN": "TOKEN",
|
||||
"EASYDNS_KEY": "SECRET",
|
||||
EnvToken: "TOKEN",
|
||||
EnvKey: "SECRET",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing token",
|
||||
envVars: map[string]string{
|
||||
"EASYDNS_KEY": "SECRET",
|
||||
EnvKey: "SECRET",
|
||||
},
|
||||
expected: "easydns: some credentials information are missing: EASYDNS_TOKEN",
|
||||
},
|
||||
{
|
||||
desc: "missing key",
|
||||
envVars: map[string]string{
|
||||
"EASYDNS_TOKEN": "TOKEN",
|
||||
EnvToken: "TOKEN",
|
||||
},
|
||||
expected: "easydns: some credentials information are missing: EASYDNS_KEY",
|
||||
},
|
||||
|
|
|
@ -13,6 +13,17 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "EXEC_"
|
||||
|
||||
EnvPath = envNamespace + "PATH"
|
||||
EnvMode = envNamespace + "MODE"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config Provider configuration.
|
||||
type Config struct {
|
||||
Program string
|
||||
|
@ -24,8 +35,8 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("EXEC_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("EXEC_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,14 +49,14 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a new DNS provider which runs the program in the
|
||||
// environment variable EXEC_PATH for adding and removing the DNS record.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("EXEC_PATH")
|
||||
values, err := env.Get(EnvPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("exec: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Program = values["EXEC_PATH"]
|
||||
config.Mode = os.Getenv("EXEC_MODE")
|
||||
config.Program = values[EnvPath]
|
||||
config.Mode = os.Getenv(EnvMode)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,20 @@ import (
|
|||
|
||||
const defaultBaseURL = "https://api.exoscale.com/dns"
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "EXOSCALE_"
|
||||
|
||||
EnvAPISecret = envNamespace + "API_SECRET"
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvEndpoint = envNamespace + "ENDPOINT"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -29,11 +43,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("EXOSCALE_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("EXOSCALE_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("EXOSCALE_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("EXOSCALE_HTTP_TIMEOUT", 0),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -47,15 +61,15 @@ type DNSProvider struct {
|
|||
// NewDNSProvider Credentials must be passed in the environment variables:
|
||||
// EXOSCALE_API_KEY, EXOSCALE_API_SECRET, EXOSCALE_ENDPOINT.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("EXOSCALE_API_KEY", "EXOSCALE_API_SECRET")
|
||||
values, err := env.Get(EnvAPIKey, EnvAPISecret)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("exoscale: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["EXOSCALE_API_KEY"]
|
||||
config.APISecret = values["EXOSCALE_API_SECRET"]
|
||||
config.Endpoint = env.GetOrFile("EXOSCALE_ENDPOINT")
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.APISecret = values[EnvAPISecret]
|
||||
config.Endpoint = env.GetOrFile(EnvEndpoint)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -9,10 +9,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"EXOSCALE_API_SECRET",
|
||||
"EXOSCALE_API_KEY").
|
||||
WithDomain("EXOSCALE_DOMAIN")
|
||||
EnvAPISecret,
|
||||
EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -23,31 +25,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"EXOSCALE_API_KEY": "123",
|
||||
"EXOSCALE_API_SECRET": "456",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPISecret: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"EXOSCALE_API_KEY": "",
|
||||
"EXOSCALE_API_SECRET": "",
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "exoscale: some credentials information are missing: EXOSCALE_API_KEY,EXOSCALE_API_SECRET",
|
||||
},
|
||||
{
|
||||
desc: "missing access key",
|
||||
envVars: map[string]string{
|
||||
"EXOSCALE_API_KEY": "",
|
||||
"EXOSCALE_API_SECRET": "456",
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "456",
|
||||
},
|
||||
expected: "exoscale: some credentials information are missing: EXOSCALE_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"EXOSCALE_API_KEY": "123",
|
||||
"EXOSCALE_API_SECRET": "",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "exoscale: some credentials information are missing: EXOSCALE_API_SECRET",
|
||||
},
|
||||
|
|
|
@ -13,6 +13,20 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "AKAMAI_"
|
||||
|
||||
EnvHost = envNamespace + "HOST"
|
||||
EnvClientToken = envNamespace + "CLIENT_TOKEN"
|
||||
EnvClientSecret = envNamespace + "CLIENT_SECRET"
|
||||
EnvAccessToken = envNamespace + "ACCESS_TOKEN"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
edgegrid.Config
|
||||
|
@ -24,9 +38,9 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("AKAMAI_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("AKAMAI_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt("AKAMAI_TTL", dns01.DefaultTTL),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,17 +52,17 @@ type DNSProvider struct {
|
|||
// NewDNSProvider uses the supplied environment variables to return a DNSProvider instance:
|
||||
// AKAMAI_HOST, AKAMAI_CLIENT_TOKEN, AKAMAI_CLIENT_SECRET, AKAMAI_ACCESS_TOKEN
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("AKAMAI_HOST", "AKAMAI_CLIENT_TOKEN", "AKAMAI_CLIENT_SECRET", "AKAMAI_ACCESS_TOKEN")
|
||||
values, err := env.Get(EnvHost, EnvClientToken, EnvClientSecret, EnvAccessToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fastdns: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Config = edgegrid.Config{
|
||||
Host: values["AKAMAI_HOST"],
|
||||
ClientToken: values["AKAMAI_CLIENT_TOKEN"],
|
||||
ClientSecret: values["AKAMAI_CLIENT_SECRET"],
|
||||
AccessToken: values["AKAMAI_ACCESS_TOKEN"],
|
||||
Host: values[EnvHost],
|
||||
ClientToken: values[EnvClientToken],
|
||||
ClientSecret: values[EnvClientSecret],
|
||||
AccessToken: values[EnvAccessToken],
|
||||
MaxBody: 131072,
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,14 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "TEST_DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"AKAMAI_HOST",
|
||||
"AKAMAI_CLIENT_TOKEN",
|
||||
"AKAMAI_CLIENT_SECRET",
|
||||
"AKAMAI_ACCESS_TOKEN").
|
||||
WithDomain("AKAMAI_TEST_DOMAIN")
|
||||
EnvHost,
|
||||
EnvClientToken,
|
||||
EnvClientSecret,
|
||||
EnvAccessToken).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -25,59 +27,59 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"AKAMAI_HOST": "A",
|
||||
"AKAMAI_CLIENT_TOKEN": "B",
|
||||
"AKAMAI_CLIENT_SECRET": "C",
|
||||
"AKAMAI_ACCESS_TOKEN": "D",
|
||||
EnvHost: "A",
|
||||
EnvClientToken: "B",
|
||||
EnvClientSecret: "C",
|
||||
EnvAccessToken: "D",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"AKAMAI_HOST": "",
|
||||
"AKAMAI_CLIENT_TOKEN": "",
|
||||
"AKAMAI_CLIENT_SECRET": "",
|
||||
"AKAMAI_ACCESS_TOKEN": "",
|
||||
EnvHost: "",
|
||||
EnvClientToken: "",
|
||||
EnvClientSecret: "",
|
||||
EnvAccessToken: "",
|
||||
},
|
||||
expected: "fastdns: some credentials information are missing: AKAMAI_HOST,AKAMAI_CLIENT_TOKEN,AKAMAI_CLIENT_SECRET,AKAMAI_ACCESS_TOKEN",
|
||||
},
|
||||
{
|
||||
desc: "missing host",
|
||||
envVars: map[string]string{
|
||||
"AKAMAI_HOST": "",
|
||||
"AKAMAI_CLIENT_TOKEN": "B",
|
||||
"AKAMAI_CLIENT_SECRET": "C",
|
||||
"AKAMAI_ACCESS_TOKEN": "D",
|
||||
EnvHost: "",
|
||||
EnvClientToken: "B",
|
||||
EnvClientSecret: "C",
|
||||
EnvAccessToken: "D",
|
||||
},
|
||||
expected: "fastdns: some credentials information are missing: AKAMAI_HOST",
|
||||
},
|
||||
{
|
||||
desc: "missing client token",
|
||||
envVars: map[string]string{
|
||||
"AKAMAI_HOST": "A",
|
||||
"AKAMAI_CLIENT_TOKEN": "",
|
||||
"AKAMAI_CLIENT_SECRET": "C",
|
||||
"AKAMAI_ACCESS_TOKEN": "D",
|
||||
EnvHost: "A",
|
||||
EnvClientToken: "",
|
||||
EnvClientSecret: "C",
|
||||
EnvAccessToken: "D",
|
||||
},
|
||||
expected: "fastdns: some credentials information are missing: AKAMAI_CLIENT_TOKEN",
|
||||
},
|
||||
{
|
||||
desc: "missing client secret",
|
||||
envVars: map[string]string{
|
||||
"AKAMAI_HOST": "A",
|
||||
"AKAMAI_CLIENT_TOKEN": "B",
|
||||
"AKAMAI_CLIENT_SECRET": "",
|
||||
"AKAMAI_ACCESS_TOKEN": "D",
|
||||
EnvHost: "A",
|
||||
EnvClientToken: "B",
|
||||
EnvClientSecret: "",
|
||||
EnvAccessToken: "D",
|
||||
},
|
||||
expected: "fastdns: some credentials information are missing: AKAMAI_CLIENT_SECRET",
|
||||
},
|
||||
{
|
||||
desc: "missing access token",
|
||||
envVars: map[string]string{
|
||||
"AKAMAI_HOST": "A",
|
||||
"AKAMAI_CLIENT_TOKEN": "B",
|
||||
"AKAMAI_CLIENT_SECRET": "C",
|
||||
"AKAMAI_ACCESS_TOKEN": "",
|
||||
EnvHost: "A",
|
||||
EnvClientToken: "B",
|
||||
EnvClientSecret: "C",
|
||||
EnvAccessToken: "",
|
||||
},
|
||||
expected: "fastdns: some credentials information are missing: AKAMAI_ACCESS_TOKEN",
|
||||
},
|
||||
|
|
|
@ -22,6 +22,18 @@ const (
|
|||
minTTL = 300
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "GANDI_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -35,11 +47,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("GANDI_TTL", minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("GANDI_PROPAGATION_TIMEOUT", 40*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("GANDI_POLLING_INTERVAL", 60*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 40*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 60*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("GANDI_HTTP_TIMEOUT", 60*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -66,13 +78,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Gandi.
|
||||
// Credentials must be passed in the environment variable: GANDI_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("GANDI_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gandi: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["GANDI_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("GANDI_API_KEY")
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -24,13 +24,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"GANDI_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"GANDI_API_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "gandi: some credentials information are missing: GANDI_API_KEY",
|
||||
},
|
||||
|
|
|
@ -21,6 +21,18 @@ const (
|
|||
minTTL = 300
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "GANDIV5_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// inProgressInfo contains information about an in-progress challenge
|
||||
type inProgressInfo struct {
|
||||
fieldName string
|
||||
|
@ -40,11 +52,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("GANDIV5_TTL", minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("GANDIV5_PROPAGATION_TIMEOUT", 20*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("GANDIV5_POLLING_INTERVAL", 20*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 20*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 20*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("GANDIV5_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -63,13 +75,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Gandi.
|
||||
// Credentials must be passed in the environment variable: GANDIV5_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("GANDIV5_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gandi: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["GANDIV5_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("GANDIV5_API_KEY")
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -24,13 +24,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"GANDIV5_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"GANDIV5_API_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "gandi: some credentials information are missing: GANDIV5_API_KEY",
|
||||
},
|
||||
|
|
|
@ -26,6 +26,19 @@ const (
|
|||
changeStatusDone = "done"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "GCE_"
|
||||
|
||||
EnvServiceAccount = envNamespace + "SERVICE_ACCOUNT"
|
||||
EnvProject = envNamespace + "PROJECT"
|
||||
EnvDebug = envNamespace + "DEBUG"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Debug bool
|
||||
|
@ -39,10 +52,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
Debug: env.GetOrDefaultBool("GCE_DEBUG", false),
|
||||
TTL: env.GetOrDefaultInt("GCE_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("GCE_PROPAGATION_TIMEOUT", 180*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond("GCE_POLLING_INTERVAL", 5*time.Second),
|
||||
Debug: env.GetOrDefaultBool(EnvDebug, false),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 180*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,12 +72,12 @@ type DNSProvider struct {
|
|||
// or by specifying the keyfile location: GCE_SERVICE_ACCOUNT_FILE
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
// Use a service account file if specified via environment variable.
|
||||
if saKey := env.GetOrFile("GCE_SERVICE_ACCOUNT"); len(saKey) > 0 {
|
||||
if saKey := env.GetOrFile(EnvServiceAccount); len(saKey) > 0 {
|
||||
return NewDNSProviderServiceAccountKey([]byte(saKey))
|
||||
}
|
||||
|
||||
// Use default credentials.
|
||||
project := env.GetOrDefaultString("GCE_PROJECT", autodetectProjectID())
|
||||
project := env.GetOrDefaultString(EnvProject, autodetectProjectID())
|
||||
return NewDNSProviderCredentials(project)
|
||||
}
|
||||
|
||||
|
@ -96,7 +109,7 @@ func NewDNSProviderServiceAccountKey(saKey []byte) (*DNSProvider, error) {
|
|||
|
||||
// If GCE_PROJECT is non-empty it overrides the project in the service
|
||||
// account file.
|
||||
project := env.GetOrDefaultString("GCE_PROJECT", "")
|
||||
project := env.GetOrDefaultString(EnvProject, "")
|
||||
if project == "" {
|
||||
// read project id from service account file
|
||||
var datJSON struct {
|
||||
|
|
|
@ -16,13 +16,22 @@ import (
|
|||
"google.golang.org/api/dns/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
envServiceAccountFile = envNamespace + "SERVICE_ACCOUNT_FILE"
|
||||
envMetadataHost = envNamespace + "METADATA_HOST"
|
||||
|
||||
envGoogleApplicationCredentials = "GOOGLE_APPLICATION_CREDENTIALS"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"GCE_PROJECT",
|
||||
"GCE_SERVICE_ACCOUNT_FILE",
|
||||
"GOOGLE_APPLICATION_CREDENTIALS",
|
||||
"GCE_METADATA_HOST",
|
||||
"GCE_SERVICE_ACCOUNT").
|
||||
WithDomain("GCE_DOMAIN").
|
||||
EnvProject,
|
||||
envServiceAccountFile,
|
||||
envGoogleApplicationCredentials,
|
||||
envMetadataHost,
|
||||
EnvServiceAccount).
|
||||
WithDomain(envDomain).
|
||||
WithLiveTestExtra(func() bool {
|
||||
_, err := google.DefaultClient(context.Background(), dns.NdevClouddnsReadwriteScope)
|
||||
return err == nil
|
||||
|
@ -37,36 +46,36 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "invalid credentials",
|
||||
envVars: map[string]string{
|
||||
"GCE_PROJECT": "123",
|
||||
"GCE_SERVICE_ACCOUNT_FILE": "",
|
||||
EnvProject: "123",
|
||||
envServiceAccountFile: "",
|
||||
// as Travis run on GCE, we have to alter env
|
||||
"GOOGLE_APPLICATION_CREDENTIALS": "not-a-secret-file",
|
||||
"GCE_METADATA_HOST": "http://lego.wtf", // defined here to avoid the client cache.
|
||||
envGoogleApplicationCredentials: "not-a-secret-file",
|
||||
envMetadataHost: "http://lego.wtf", // defined here to avoid the client cache.
|
||||
},
|
||||
expected: "googlecloud: unable to get Google Cloud client: google: error getting credentials using GOOGLE_APPLICATION_CREDENTIALS environment variable: open not-a-secret-file: no such file or directory",
|
||||
},
|
||||
{
|
||||
desc: "missing project",
|
||||
envVars: map[string]string{
|
||||
"GCE_PROJECT": "",
|
||||
"GCE_SERVICE_ACCOUNT_FILE": "",
|
||||
EnvProject: "",
|
||||
envServiceAccountFile: "",
|
||||
// as Travis run on GCE, we have to alter env
|
||||
"GCE_METADATA_HOST": "http://lego.wtf",
|
||||
envMetadataHost: "http://lego.wtf",
|
||||
},
|
||||
expected: "googlecloud: project name missing",
|
||||
},
|
||||
{
|
||||
desc: "success key file",
|
||||
envVars: map[string]string{
|
||||
"GCE_PROJECT": "",
|
||||
"GCE_SERVICE_ACCOUNT_FILE": "fixtures/gce_account_service_file.json",
|
||||
EnvProject: "",
|
||||
envServiceAccountFile: "fixtures/gce_account_service_file.json",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "success key",
|
||||
envVars: map[string]string{
|
||||
"GCE_PROJECT": "",
|
||||
"GCE_SERVICE_ACCOUNT": `{"project_id": "A","type": "service_account","client_email": "foo@bar.com","private_key_id": "pki","private_key": "pk","token_uri": "/token","client_secret": "secret","client_id": "C","refresh_token": "D"}`,
|
||||
EnvProject: "",
|
||||
EnvServiceAccount: `{"project_id": "A","type": "service_account","client_email": "foo@bar.com","private_key_id": "pki","private_key": "pk","token_uri": "/token","client_secret": "secret","client_id": "C","refresh_token": "D"}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -381,7 +390,7 @@ func TestLivePresent(t *testing.T) {
|
|||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
provider, err := NewDNSProviderCredentials(envTest.GetValue("GCE_PROJECT"))
|
||||
provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = provider.Present(envTest.GetDomain(), "", "123d==")
|
||||
|
@ -395,7 +404,7 @@ func TestLivePresentMultiple(t *testing.T) {
|
|||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
provider, err := NewDNSProviderCredentials(envTest.GetValue("GCE_PROJECT"))
|
||||
provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check that we're able to create multiple entries
|
||||
|
@ -413,7 +422,7 @@ func TestLiveCleanUp(t *testing.T) {
|
|||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
provider, err := NewDNSProviderCredentials(envTest.GetValue("GCE_PROJECT"))
|
||||
provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
|
|
@ -19,6 +19,19 @@ const (
|
|||
minTTL = 60
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "GLESYS_"
|
||||
|
||||
EnvAPIUser = envNamespace + "API_USER"
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIUser string
|
||||
|
@ -32,11 +45,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("GLESYS_TTL", minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("GLESYS_PROPAGATION_TIMEOUT", 20*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("GLESYS_POLLING_INTERVAL", 20*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 20*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 20*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("GLESYS_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -54,14 +67,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// GLESYS_API_USER and GLESYS_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("GLESYS_API_USER", "GLESYS_API_KEY")
|
||||
values, err := env.Get(EnvAPIUser, EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("glesys: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIUser = values["GLESYS_API_USER"]
|
||||
config.APIKey = values["GLESYS_API_KEY"]
|
||||
config.APIUser = values[EnvAPIUser]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"GLESYS_API_USER",
|
||||
"GLESYS_API_KEY").
|
||||
WithDomain("GLESYS_DOMAIN")
|
||||
EnvAPIUser,
|
||||
EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -21,31 +23,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"GLESYS_API_USER": "A",
|
||||
"GLESYS_API_KEY": "B",
|
||||
EnvAPIUser: "A",
|
||||
EnvAPIKey: "B",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"GLESYS_API_USER": "",
|
||||
"GLESYS_API_KEY": "",
|
||||
EnvAPIUser: "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "glesys: some credentials information are missing: GLESYS_API_USER,GLESYS_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing api user",
|
||||
envVars: map[string]string{
|
||||
"GLESYS_API_USER": "",
|
||||
"GLESYS_API_KEY": "B",
|
||||
EnvAPIUser: "",
|
||||
EnvAPIKey: "B",
|
||||
},
|
||||
expected: "glesys: some credentials information are missing: GLESYS_API_USER",
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"GLESYS_API_USER": "A",
|
||||
"GLESYS_API_KEY": "",
|
||||
EnvAPIUser: "A",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "glesys: some credentials information are missing: GLESYS_API_KEY",
|
||||
},
|
||||
|
|
|
@ -18,6 +18,20 @@ const (
|
|||
minTTL = 600
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "GODADDY_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvAPISecret = envNamespace + "API_SECRET"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -32,12 +46,12 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("GODADDY_TTL", minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("GODADDY_PROPAGATION_TIMEOUT", 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond("GODADDY_POLLING_INTERVAL", 2*time.Second),
|
||||
SequenceInterval: env.GetOrDefaultSecond("GODADDY_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("GODADDY_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +65,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// GODADDY_API_KEY and GODADDY_API_SECRET.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("GODADDY_API_KEY", "GODADDY_API_SECRET")
|
||||
values, err := env.Get(EnvAPIKey, EnvAPISecret)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("godaddy: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["GODADDY_API_KEY"]
|
||||
config.APISecret = values["GODADDY_API_SECRET"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.APISecret = values[EnvAPISecret]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"GODADDY_API_KEY",
|
||||
"GODADDY_API_SECRET").
|
||||
WithDomain("GODADDY_DOMAIN")
|
||||
EnvAPIKey,
|
||||
EnvAPISecret).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -21,31 +23,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"GODADDY_API_KEY": "123",
|
||||
"GODADDY_API_SECRET": "456",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPISecret: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"GODADDY_API_KEY": "",
|
||||
"GODADDY_API_SECRET": "",
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "godaddy: some credentials information are missing: GODADDY_API_KEY,GODADDY_API_SECRET",
|
||||
},
|
||||
{
|
||||
desc: "missing access key",
|
||||
envVars: map[string]string{
|
||||
"GODADDY_API_KEY": "",
|
||||
"GODADDY_API_SECRET": "456",
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "456",
|
||||
},
|
||||
expected: "godaddy: some credentials information are missing: GODADDY_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"GODADDY_API_KEY": "123",
|
||||
"GODADDY_API_SECRET": "",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "godaddy: some credentials information are missing: GODADDY_API_SECRET",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,19 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "HOSTINGDE_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvZoneName = envNamespace + "ZONE_NAME"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -25,11 +38,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("HOSTINGDE_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("HOSTINGDE_PROPAGATION_TIMEOUT", 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("HOSTINGDE_POLLING_INTERVAL", 2*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("HOSTINGDE_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -45,14 +58,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// HOSTINGDE_ZONE_NAME and HOSTINGDE_API_KEY
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("HOSTINGDE_API_KEY", "HOSTINGDE_ZONE_NAME")
|
||||
values, err := env.Get(EnvAPIKey, EnvZoneName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("hostingde: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["HOSTINGDE_API_KEY"]
|
||||
config.ZoneName = values["HOSTINGDE_ZONE_NAME"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.ZoneName = values[EnvZoneName]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"HOSTINGDE_API_KEY",
|
||||
"HOSTINGDE_ZONE_NAME").
|
||||
WithDomain("HOSTINGDE_DOMAIN")
|
||||
EnvAPIKey,
|
||||
EnvZoneName).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"HOSTINGDE_API_KEY": "123",
|
||||
"HOSTINGDE_ZONE_NAME": "456",
|
||||
EnvAPIKey: "123",
|
||||
EnvZoneName: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"HOSTINGDE_API_KEY": "",
|
||||
"HOSTINGDE_ZONE_NAME": "",
|
||||
EnvAPIKey: "",
|
||||
EnvZoneName: "",
|
||||
},
|
||||
expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY,HOSTINGDE_ZONE_NAME",
|
||||
},
|
||||
{
|
||||
desc: "missing access key",
|
||||
envVars: map[string]string{
|
||||
"HOSTINGDE_API_KEY": "",
|
||||
"HOSTINGDE_ZONE_NAME": "456",
|
||||
EnvAPIKey: "",
|
||||
EnvZoneName: "456",
|
||||
},
|
||||
expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing zone name",
|
||||
envVars: map[string]string{
|
||||
"HOSTINGDE_API_KEY": "123",
|
||||
"HOSTINGDE_ZONE_NAME": "",
|
||||
EnvAPIKey: "123",
|
||||
EnvZoneName: "",
|
||||
},
|
||||
expected: "hostingde: some credentials information are missing: HOSTINGDE_ZONE_NAME",
|
||||
},
|
||||
|
|
|
@ -16,6 +16,20 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "HTTPREQ_"
|
||||
|
||||
EnvEndpoint = envNamespace + "ENDPOINT"
|
||||
EnvMode = envNamespace + "MODE"
|
||||
EnvUsername = envNamespace + "USERNAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
type message struct {
|
||||
FQDN string `json:"fqdn"`
|
||||
Value string `json:"value"`
|
||||
|
@ -41,10 +55,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("HTTPREQ_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("HTTPREQ_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("HTTPREQ_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -56,20 +70,20 @@ type DNSProvider struct {
|
|||
|
||||
// NewDNSProvider returns a DNSProvider instance.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("HTTPREQ_ENDPOINT")
|
||||
values, err := env.Get(EnvEndpoint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("httpreq: %w", err)
|
||||
}
|
||||
|
||||
endpoint, err := url.Parse(values["HTTPREQ_ENDPOINT"])
|
||||
endpoint, err := url.Parse(values[EnvEndpoint])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("httpreq: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Mode = env.GetOrFile("HTTPREQ_MODE")
|
||||
config.Username = env.GetOrFile("HTTPREQ_USERNAME")
|
||||
config.Password = env.GetOrFile("HTTPREQ_PASSWORD")
|
||||
config.Mode = env.GetOrFile(EnvMode)
|
||||
config.Username = env.GetOrFile(EnvUsername)
|
||||
config.Password = env.GetOrFile(EnvPassword)
|
||||
config.Endpoint = endpoint
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("HTTPREQ_ENDPOINT", "HTTPREQ_MODE", "HTTPREQ_USERNAME", "HTTPREQ_PASSWORD")
|
||||
var envTest = tester.NewEnvTest(EnvEndpoint, EnvMode, EnvUsername, EnvPassword)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -24,20 +24,20 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"HTTPREQ_ENDPOINT": "http://localhost:8090",
|
||||
EnvEndpoint: "http://localhost:8090",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "invalid URL",
|
||||
envVars: map[string]string{
|
||||
"HTTPREQ_ENDPOINT": ":",
|
||||
EnvEndpoint: ":",
|
||||
},
|
||||
expected: `httpreq: parse ":": missing protocol scheme`,
|
||||
},
|
||||
{
|
||||
desc: "missing endpoint",
|
||||
envVars: map[string]string{
|
||||
"HTTPREQ_ENDPOINT": "",
|
||||
EnvEndpoint: "",
|
||||
},
|
||||
expected: "httpreq: some credentials information are missing: HTTPREQ_ENDPOINT",
|
||||
},
|
||||
|
|
|
@ -14,6 +14,19 @@ import (
|
|||
"github.com/iij/doapi/protocol"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "IIJ_"
|
||||
|
||||
EnvAPIAccessKey = envNamespace + "API_ACCESS_KEY"
|
||||
EnvAPISecretKey = envNamespace + "API_SECRET_KEY"
|
||||
EnvDoServiceCode = envNamespace + "DO_SERVICE_CODE"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
AccessKey string
|
||||
|
@ -27,9 +40,9 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("IIJ_TTL", 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("IIJ_PROPAGATION_TIMEOUT", 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("IIJ_POLLING_INTERVAL", 4*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 4*time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,15 +54,15 @@ type DNSProvider struct {
|
|||
|
||||
// NewDNSProvider returns a DNSProvider instance configured for IIJ DO
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("IIJ_API_ACCESS_KEY", "IIJ_API_SECRET_KEY", "IIJ_DO_SERVICE_CODE")
|
||||
values, err := env.Get(EnvAPIAccessKey, EnvAPISecretKey, EnvDoServiceCode)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("iij: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.AccessKey = values["IIJ_API_ACCESS_KEY"]
|
||||
config.SecretKey = values["IIJ_API_SECRET_KEY"]
|
||||
config.DoServiceCode = values["IIJ_DO_SERVICE_CODE"]
|
||||
config.AccessKey = values[EnvAPIAccessKey]
|
||||
config.SecretKey = values[EnvAPISecretKey]
|
||||
config.DoServiceCode = values[EnvDoServiceCode]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "TESTDOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"IIJ_API_ACCESS_KEY",
|
||||
"IIJ_API_SECRET_KEY",
|
||||
"IIJ_DO_SERVICE_CODE").
|
||||
WithDomain("IIJ_API_TESTDOMAIN")
|
||||
EnvAPIAccessKey,
|
||||
EnvAPISecretKey,
|
||||
EnvDoServiceCode).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -23,44 +25,44 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"IIJ_API_ACCESS_KEY": "A",
|
||||
"IIJ_API_SECRET_KEY": "B",
|
||||
"IIJ_DO_SERVICE_CODE": "C",
|
||||
EnvAPIAccessKey: "A",
|
||||
EnvAPISecretKey: "B",
|
||||
EnvDoServiceCode: "C",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"IIJ_API_ACCESS_KEY": "",
|
||||
"IIJ_API_SECRET_KEY": "",
|
||||
"IIJ_DO_SERVICE_CODE": "",
|
||||
EnvAPIAccessKey: "",
|
||||
EnvAPISecretKey: "",
|
||||
EnvDoServiceCode: "",
|
||||
},
|
||||
expected: "iij: some credentials information are missing: IIJ_API_ACCESS_KEY,IIJ_API_SECRET_KEY,IIJ_DO_SERVICE_CODE",
|
||||
},
|
||||
{
|
||||
desc: "missing api access key",
|
||||
envVars: map[string]string{
|
||||
"IIJ_API_ACCESS_KEY": "",
|
||||
"IIJ_API_SECRET_KEY": "B",
|
||||
"IIJ_DO_SERVICE_CODE": "C",
|
||||
EnvAPIAccessKey: "",
|
||||
EnvAPISecretKey: "B",
|
||||
EnvDoServiceCode: "C",
|
||||
},
|
||||
expected: "iij: some credentials information are missing: IIJ_API_ACCESS_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"IIJ_API_ACCESS_KEY": "A",
|
||||
"IIJ_API_SECRET_KEY": "",
|
||||
"IIJ_DO_SERVICE_CODE": "C",
|
||||
EnvAPIAccessKey: "A",
|
||||
EnvAPISecretKey: "",
|
||||
EnvDoServiceCode: "C",
|
||||
},
|
||||
expected: "iij: some credentials information are missing: IIJ_API_SECRET_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing do service code",
|
||||
envVars: map[string]string{
|
||||
"IIJ_API_ACCESS_KEY": "A",
|
||||
"IIJ_API_SECRET_KEY": "B",
|
||||
"IIJ_DO_SERVICE_CODE": "",
|
||||
EnvAPIAccessKey: "A",
|
||||
EnvAPISecretKey: "B",
|
||||
EnvDoServiceCode: "",
|
||||
},
|
||||
expected: "iij: some credentials information are missing: IIJ_DO_SERVICE_CODE",
|
||||
},
|
||||
|
|
|
@ -12,6 +12,19 @@ import (
|
|||
"github.com/nrdcg/goinwx"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "INWX_"
|
||||
|
||||
EnvUsername = envNamespace + "USERNAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
EnvSandbox = envNamespace + "SANDBOX"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Username string
|
||||
|
@ -25,10 +38,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("INWX_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("INWX_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt("INWX_TTL", 300),
|
||||
Sandbox: env.GetOrDefaultBool("INWX_SANDBOX", false),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
Sandbox: env.GetOrDefaultBool(EnvSandbox, false),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,14 +55,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// INWX_USERNAME and INWX_PASSWORD.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("INWX_USERNAME", "INWX_PASSWORD")
|
||||
values, err := env.Get(EnvUsername, EnvPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("inwx: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Username = values["INWX_USERNAME"]
|
||||
config.Password = values["INWX_PASSWORD"]
|
||||
config.Username = values[EnvUsername]
|
||||
config.Password = values[EnvPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -7,13 +7,15 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"INWX_USERNAME",
|
||||
"INWX_PASSWORD",
|
||||
"INWX_SANDBOX",
|
||||
"INWX_TTL").
|
||||
WithDomain("INWX_DOMAIN").
|
||||
WithLiveTestRequirements("INWX_USERNAME", "INWX_PASSWORD", "INWX_DOMAIN")
|
||||
EnvUsername,
|
||||
EnvPassword,
|
||||
EnvSandbox,
|
||||
EnvTTL).
|
||||
WithDomain(envDomain).
|
||||
WithLiveTestRequirements(EnvUsername, EnvPassword, envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -24,31 +26,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"INWX_USERNAME": "123",
|
||||
"INWX_PASSWORD": "456",
|
||||
EnvUsername: "123",
|
||||
EnvPassword: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"INWX_USERNAME": "",
|
||||
"INWX_PASSWORD": "",
|
||||
EnvUsername: "",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "inwx: some credentials information are missing: INWX_USERNAME,INWX_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"INWX_USERNAME": "",
|
||||
"INWX_PASSWORD": "456",
|
||||
EnvUsername: "",
|
||||
EnvPassword: "456",
|
||||
},
|
||||
expected: "inwx: some credentials information are missing: INWX_USERNAME",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
envVars: map[string]string{
|
||||
"INWX_USERNAME": "123",
|
||||
"INWX_PASSWORD": "",
|
||||
EnvUsername: "123",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "inwx: some credentials information are missing: INWX_PASSWORD",
|
||||
},
|
||||
|
@ -120,8 +122,8 @@ func TestLivePresentAndCleanup(t *testing.T) {
|
|||
|
||||
envTest.RestoreEnv()
|
||||
envTest.Apply(map[string]string{
|
||||
"INWX_SANDBOX": "true",
|
||||
"INWX_TTL": "3600", // In sandbox mode, the minimum allowed TTL is 3600
|
||||
EnvSandbox: "true",
|
||||
EnvTTL: "3600", // In sandbox mode, the minimum allowed TTL is 3600
|
||||
})
|
||||
defer envTest.RestoreEnv()
|
||||
|
||||
|
|
|
@ -13,6 +13,21 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "JOKER_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvUsername = envNamespace + "USERNAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
EnvDebug = envNamespace + "DEBUG"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider.
|
||||
type Config struct {
|
||||
Debug bool
|
||||
|
@ -31,12 +46,12 @@ type Config struct {
|
|||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
BaseURL: defaultBaseURL,
|
||||
Debug: env.GetOrDefaultBool("JOKER_DEBUG", false),
|
||||
TTL: env.GetOrDefaultInt("JOKER_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("JOKER_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("JOKER_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
Debug: env.GetOrDefaultBool(EnvDebug, false),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("JOKER_HTTP_TIMEOUT", 60*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -50,19 +65,19 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Joker DMAPI.
|
||||
// Credentials must be passed in the environment variable JOKER_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("JOKER_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
var errU error
|
||||
values, errU = env.Get("JOKER_USERNAME", "JOKER_PASSWORD")
|
||||
values, errU = env.Get(EnvUsername, EnvPassword)
|
||||
if errU != nil {
|
||||
return nil, fmt.Errorf("joker: %v or %v", errU, err)
|
||||
}
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["JOKER_API_KEY"]
|
||||
config.Username = values["JOKER_USERNAME"]
|
||||
config.Password = values["JOKER_PASSWORD"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.Username = values[EnvUsername]
|
||||
config.Password = values[EnvPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("JOKER_API_KEY", "JOKER_USERNAME", "JOKER_PASSWORD").
|
||||
WithDomain("JOKER_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey, EnvUsername, EnvPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -21,40 +23,40 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success API key",
|
||||
envVars: map[string]string{
|
||||
"JOKER_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "success username password",
|
||||
envVars: map[string]string{
|
||||
"JOKER_USERNAME": "123",
|
||||
"JOKER_PASSWORD": "123",
|
||||
EnvUsername: "123",
|
||||
EnvPassword: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"JOKER_API_KEY": "",
|
||||
"JOKER_USERNAME": "",
|
||||
"JOKER_PASSWORD": "",
|
||||
EnvAPIKey: "",
|
||||
EnvUsername: "",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "joker: some credentials information are missing: JOKER_USERNAME,JOKER_PASSWORD or some credentials information are missing: JOKER_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
envVars: map[string]string{
|
||||
"JOKER_API_KEY": "",
|
||||
"JOKER_USERNAME": "123",
|
||||
"JOKER_PASSWORD": "",
|
||||
EnvAPIKey: "",
|
||||
EnvUsername: "123",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "joker: some credentials information are missing: JOKER_PASSWORD or some credentials information are missing: JOKER_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"JOKER_API_KEY": "",
|
||||
"JOKER_USERNAME": "",
|
||||
"JOKER_PASSWORD": "123",
|
||||
EnvAPIKey: "",
|
||||
EnvUsername: "",
|
||||
EnvPassword: "123",
|
||||
},
|
||||
expected: "joker: some credentials information are missing: JOKER_USERNAME or some credentials information are missing: JOKER_API_KEY",
|
||||
},
|
||||
|
|
|
@ -20,6 +20,17 @@ const (
|
|||
maxRetries = 5
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "LIGHTSAIL_"
|
||||
|
||||
EnvRegion = envNamespace + "LIGHTSAIL_REGION"
|
||||
EnvDNSZone = "DNS_ZONE"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// customRetryer implements the client.Retryer interface by composing the DefaultRetryer.
|
||||
// It controls the logic for retrying recoverable request errors (e.g. when rate limits are exceeded).
|
||||
type customRetryer struct {
|
||||
|
@ -52,10 +63,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
DNSZone: env.GetOrFile("DNS_ZONE"),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("LIGHTSAIL_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("LIGHTSAIL_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
Region: env.GetOrDefaultString("LIGHTSAIL_REGION", "us-east-1"),
|
||||
DNSZone: env.GetOrFile(EnvDNSZone),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
Region: env.GetOrDefaultString(EnvRegion, "us-east-1"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,13 +13,22 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
envAwsNamespace = "AWS_"
|
||||
|
||||
envAwsAccessKeyID = envAwsNamespace + "ACCESS_KEY_ID"
|
||||
envAwsSecretAccessKey = envAwsNamespace + "SECRET_ACCESS_KEY"
|
||||
envAwsRegion = envAwsNamespace + "REGION"
|
||||
envAwsHostedZoneID = envAwsNamespace + "HOSTED_ZONE_ID"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"AWS_ACCESS_KEY_ID",
|
||||
"AWS_SECRET_ACCESS_KEY",
|
||||
"AWS_REGION",
|
||||
"AWS_HOSTED_ZONE_ID").
|
||||
WithDomain("DNS_ZONE").
|
||||
WithLiveTestRequirements("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "DNS_ZONE")
|
||||
envAwsAccessKeyID,
|
||||
envAwsSecretAccessKey,
|
||||
envAwsRegion,
|
||||
envAwsHostedZoneID).
|
||||
WithDomain(EnvDNSZone).
|
||||
WithLiveTestRequirements(envAwsAccessKeyID, envAwsSecretAccessKey, EnvDNSZone)
|
||||
|
||||
func makeProvider(ts *httptest.Server) (*DNSProvider, error) {
|
||||
config := &aws.Config{
|
||||
|
@ -44,9 +53,9 @@ func TestCredentialsFromEnv(t *testing.T) {
|
|||
defer envTest.RestoreEnv()
|
||||
envTest.ClearEnv()
|
||||
|
||||
os.Setenv("AWS_ACCESS_KEY_ID", "123")
|
||||
os.Setenv("AWS_SECRET_ACCESS_KEY", "123")
|
||||
os.Setenv("AWS_REGION", "us-east-1")
|
||||
os.Setenv(envAwsAccessKeyID, "123")
|
||||
os.Setenv(envAwsSecretAccessKey, "123")
|
||||
os.Setenv(envAwsRegion, "us-east-1")
|
||||
|
||||
config := &aws.Config{
|
||||
CredentialsChainVerboseErrors: aws.Bool(true),
|
||||
|
|
|
@ -18,6 +18,16 @@ const (
|
|||
dnsUpdateFudgeSecs = 120
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "LINODE_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -28,8 +38,8 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second),
|
||||
TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,13 +57,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Linode.
|
||||
// Credentials must be passed in the environment variable: LINODE_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("LINODE_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("linode: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["LINODE_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ type (
|
|||
MockResponseMap map[string]MockResponse
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("LINODE_API_KEY")
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey)
|
||||
|
||||
func newMockServer(responses MockResponseMap) *httptest.Server {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -77,13 +77,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"LINODE_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"LINODE_API_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "linode: some credentials information are missing: LINODE_API_KEY",
|
||||
},
|
||||
|
@ -147,7 +147,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
|
|||
|
||||
func TestDNSProvider_Present(t *testing.T) {
|
||||
defer envTest.RestoreEnv()
|
||||
os.Setenv("LINODE_API_KEY", "testing")
|
||||
os.Setenv(EnvAPIKey, "testing")
|
||||
|
||||
p, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
@ -234,7 +234,7 @@ func TestDNSProvider_Present(t *testing.T) {
|
|||
|
||||
func TestDNSProvider_CleanUp(t *testing.T) {
|
||||
defer envTest.RestoreEnv()
|
||||
os.Setenv("LINODE_API_KEY", "testing")
|
||||
os.Setenv(EnvAPIKey, "testing")
|
||||
|
||||
p, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -22,6 +22,18 @@ const (
|
|||
dnsUpdateFudgeSecs = 120
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "LINODE_"
|
||||
|
||||
EnvToken = envNamespace + "TOKEN"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Token string
|
||||
|
@ -34,10 +46,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("LINODE_PROPAGATION_TIMEOUT", 0),
|
||||
PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second),
|
||||
TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL),
|
||||
HTTPTimeout: env.GetOrDefaultSecond("LINODE_HTTP_TIMEOUT", 0),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 0),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
|
||||
HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 0),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,13 +67,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for Linode.
|
||||
// Credentials must be passed in the environment variable: LINODE_TOKEN.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("LINODE_TOKEN")
|
||||
values, err := env.Get(EnvToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("linodev4: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Token = values["LINODE_TOKEN"]
|
||||
config.Token = values[EnvToken]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -15,11 +15,9 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type (
|
||||
MockResponseMap map[string]interface{}
|
||||
)
|
||||
type MockResponseMap map[string]interface{}
|
||||
|
||||
var envTest = tester.NewEnvTest("LINODE_TOKEN")
|
||||
var envTest = tester.NewEnvTest(EnvToken)
|
||||
|
||||
func newMockServer(responses MockResponseMap) *httptest.Server {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -68,13 +66,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"LINODE_TOKEN": "123",
|
||||
EnvToken: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"LINODE_TOKEN": "",
|
||||
EnvToken: "",
|
||||
},
|
||||
expected: "linodev4: some credentials information are missing: LINODE_TOKEN",
|
||||
},
|
||||
|
@ -138,7 +136,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
|
|||
|
||||
func TestDNSProvider_Present(t *testing.T) {
|
||||
defer envTest.RestoreEnv()
|
||||
os.Setenv("LINODE_TOKEN", "testing")
|
||||
os.Setenv(EnvToken, "testing")
|
||||
|
||||
p, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
@ -227,7 +225,7 @@ func TestDNSProvider_Present(t *testing.T) {
|
|||
|
||||
func TestDNSProvider_CleanUp(t *testing.T) {
|
||||
defer envTest.RestoreEnv()
|
||||
os.Setenv("LINODE_TOKEN", "testing")
|
||||
os.Setenv(EnvToken, "testing")
|
||||
|
||||
p, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -16,6 +16,21 @@ import (
|
|||
|
||||
const defaultBaseURL = "https://api.stormondemand.com"
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "LIQUID_WEB_"
|
||||
|
||||
EnvURL = envNamespace + "URL"
|
||||
EnvUsername = envNamespace + "USERNAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
EnvZone = envNamespace + "ZONE"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -32,10 +47,10 @@ type Config struct {
|
|||
func NewDefaultConfig() *Config {
|
||||
config := &Config{
|
||||
BaseURL: defaultBaseURL,
|
||||
TTL: env.GetOrDefaultInt("LIQUID_WEB_TTL", 300),
|
||||
PollingInterval: env.GetOrDefaultSecond("LIQUID_WEB_POLLING_INTERVAL", 2*time.Second),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("LIQUID_WEB_PROPAGATION_TIMEOUT", 2*time.Minute),
|
||||
HTTPTimeout: env.GetOrDefaultSecond("LIQUID_WEB_HTTP_TIMEOUT", 1*time.Minute),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, 300),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 1*time.Minute),
|
||||
}
|
||||
|
||||
return config
|
||||
|
@ -52,16 +67,16 @@ type DNSProvider struct {
|
|||
|
||||
// NewDNSProvider returns a DNSProvider instance configured for Liquid Web.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("LIQUID_WEB_USERNAME", "LIQUID_WEB_PASSWORD", "LIQUID_WEB_ZONE")
|
||||
values, err := env.Get(EnvUsername, EnvPassword, EnvZone)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("liquidweb: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.BaseURL = env.GetOrFile("LIQUID_WEB_URL")
|
||||
config.Username = values["LIQUID_WEB_USERNAME"]
|
||||
config.Password = values["LIQUID_WEB_PASSWORD"]
|
||||
config.Zone = values["LIQUID_WEB_ZONE"]
|
||||
config.BaseURL = env.GetOrFile(EnvURL)
|
||||
config.Username = values[EnvUsername]
|
||||
config.Password = values[EnvPassword]
|
||||
config.Zone = values[EnvZone]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -13,12 +13,14 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"LIQUID_WEB_URL",
|
||||
"LIQUID_WEB_USERNAME",
|
||||
"LIQUID_WEB_PASSWORD",
|
||||
"LIQUID_WEB_ZONE").
|
||||
WithDomain("LIQUID_WEB_DOMAIN")
|
||||
EnvURL,
|
||||
EnvUsername,
|
||||
EnvPassword,
|
||||
EnvZone).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func setupTest() (*DNSProvider, *http.ServeMux, func()) {
|
||||
handler := http.NewServeMux()
|
||||
|
@ -47,10 +49,10 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"LIQUID_WEB_URL": "https://storm.com",
|
||||
"LIQUID_WEB_USERNAME": "blars",
|
||||
"LIQUID_WEB_PASSWORD": "tacoman",
|
||||
"LIQUID_WEB_ZONE": "blars.com",
|
||||
EnvURL: "https://storm.com",
|
||||
EnvUsername: "blars",
|
||||
EnvPassword: "tacoman",
|
||||
EnvZone: "blars.com",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -61,23 +63,23 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"LIQUID_WEB_PASSWORD": "tacoman",
|
||||
"LIQUID_WEB_ZONE": "blars.com",
|
||||
EnvPassword: "tacoman",
|
||||
EnvZone: "blars.com",
|
||||
},
|
||||
expected: "liquidweb: some credentials information are missing: LIQUID_WEB_USERNAME",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
envVars: map[string]string{
|
||||
"LIQUID_WEB_USERNAME": "blars",
|
||||
"LIQUID_WEB_ZONE": "blars.com",
|
||||
EnvUsername: "blars",
|
||||
EnvZone: "blars.com",
|
||||
}, expected: "liquidweb: some credentials information are missing: LIQUID_WEB_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing zone",
|
||||
envVars: map[string]string{
|
||||
"LIQUID_WEB_USERNAME": "blars",
|
||||
"LIQUID_WEB_PASSWORD": "tacoman",
|
||||
EnvUsername: "blars",
|
||||
EnvPassword: "tacoman",
|
||||
}, expected: "liquidweb: some credentials information are missing: LIQUID_WEB_ZONE",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -13,6 +13,18 @@ import (
|
|||
|
||||
const defaultBaseURL = "https://www.mydns.jp/directedit.html"
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "MYDNSJP_"
|
||||
|
||||
EnvMasterID = envNamespace + "MASTER_ID"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
MasterID string
|
||||
|
@ -25,10 +37,10 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("MYDNSJP_PROPAGATION_TIMEOUT", 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("MYDNSJP_POLLING_INTERVAL", 2*time.Second),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("MYDNSJP_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -41,14 +53,14 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for MyDNS.jp.
|
||||
// Credentials must be passed in the environment variables: MYDNSJP_MASTER_ID and MYDNSJP_PASSWORD.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("MYDNSJP_MASTER_ID", "MYDNSJP_PASSWORD")
|
||||
values, err := env.Get(EnvMasterID, EnvPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mydnsjp: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.MasterID = values["MYDNSJP_MASTER_ID"]
|
||||
config.Password = values["MYDNSJP_PASSWORD"]
|
||||
config.MasterID = values[EnvMasterID]
|
||||
config.Password = values[EnvPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("MYDNSJP_MASTER_ID", "MYDNSJP_PASSWORD").
|
||||
WithDomain("MYDNSJP_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvMasterID, EnvPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -21,31 +23,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"MYDNSJP_MASTER_ID": "test@example.com",
|
||||
"MYDNSJP_PASSWORD": "123",
|
||||
EnvMasterID: "test@example.com",
|
||||
EnvPassword: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"MYDNSJP_MASTER_ID": "",
|
||||
"MYDNSJP_PASSWORD": "",
|
||||
EnvMasterID: "",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "mydnsjp: some credentials information are missing: MYDNSJP_MASTER_ID,MYDNSJP_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing email",
|
||||
envVars: map[string]string{
|
||||
"MYDNSJP_MASTER_ID": "",
|
||||
"MYDNSJP_PASSWORD": "key",
|
||||
EnvMasterID: "",
|
||||
EnvPassword: "key",
|
||||
},
|
||||
expected: "mydnsjp: some credentials information are missing: MYDNSJP_MASTER_ID",
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"MYDNSJP_MASTER_ID": "awesome@possum.com",
|
||||
"MYDNSJP_PASSWORD": "",
|
||||
EnvMasterID: "awesome@possum.com",
|
||||
EnvPassword: "",
|
||||
},
|
||||
expected: "mydnsjp: some credentials information are missing: MYDNSJP_PASSWORD",
|
||||
},
|
||||
|
|
|
@ -35,6 +35,22 @@ const (
|
|||
getIPURL = "https://dynamicdns.park-your-domain.com/getip"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "NAMECHEAP_"
|
||||
|
||||
EnvAPIUser = envNamespace + "API_USER"
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvSandbox = envNamespace + "SANDBOX"
|
||||
EnvDebug = envNamespace + "DEBUG"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// A challenge represents all the data needed to specify a dns-01 challenge
|
||||
// to lets-encrypt.
|
||||
type challenge struct {
|
||||
|
@ -63,18 +79,18 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
baseURL := defaultBaseURL
|
||||
if env.GetOrDefaultBool("NAMECHEAP_SANDBOX", false) {
|
||||
if env.GetOrDefaultBool(EnvSandbox, false) {
|
||||
baseURL = sandboxBaseURL
|
||||
}
|
||||
|
||||
return &Config{
|
||||
BaseURL: baseURL,
|
||||
Debug: env.GetOrDefaultBool("NAMECHEAP_DEBUG", false),
|
||||
TTL: env.GetOrDefaultInt("NAMECHEAP_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("NAMECHEAP_PROPAGATION_TIMEOUT", 60*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("NAMECHEAP_POLLING_INTERVAL", 15*time.Second),
|
||||
Debug: env.GetOrDefaultBool(EnvDebug, false),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("NAMECHEAP_HTTP_TIMEOUT", 60*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -89,14 +105,14 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// NAMECHEAP_API_USER and NAMECHEAP_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("NAMECHEAP_API_USER", "NAMECHEAP_API_KEY")
|
||||
values, err := env.Get(EnvAPIUser, EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("namecheap: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIUser = values["NAMECHEAP_API_USER"]
|
||||
config.APIKey = values["NAMECHEAP_API_KEY"]
|
||||
config.APIUser = values[EnvAPIUser]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,20 @@ import (
|
|||
// according to https://www.name.com/api-docs/DNS#CreateRecord
|
||||
const minTTL = 300
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "NAMECOM_"
|
||||
|
||||
EnvUsername = envNamespace + "USERNAME"
|
||||
EnvAPIToken = envNamespace + "API_TOKEN"
|
||||
EnvServer = envNamespace + "SERVER"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Username string
|
||||
|
@ -30,11 +44,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("NAMECOM_TTL", minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("NAMECOM_PROPAGATION_TIMEOUT", 15*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond("NAMECOM_POLLING_INTERVAL", 20*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 15*time.Minute),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 20*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("NAMECOM_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -49,15 +63,15 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// NAMECOM_USERNAME and NAMECOM_API_TOKEN
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("NAMECOM_USERNAME", "NAMECOM_API_TOKEN")
|
||||
values, err := env.Get(EnvUsername, EnvAPIToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("namedotcom: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Username = values["NAMECOM_USERNAME"]
|
||||
config.APIToken = values["NAMECOM_API_TOKEN"]
|
||||
config.Server = env.GetOrFile("NAMECOM_SERVER")
|
||||
config.Username = values[EnvUsername]
|
||||
config.APIToken = values[EnvAPIToken]
|
||||
config.Server = env.GetOrFile(EnvServer)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"NAMECOM_USERNAME",
|
||||
"NAMECOM_API_TOKEN").
|
||||
WithDomain("NAMEDOTCOM_DOMAIN")
|
||||
EnvUsername,
|
||||
EnvAPIToken).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"NAMECOM_USERNAME": "A",
|
||||
"NAMECOM_API_TOKEN": "B",
|
||||
EnvUsername: "A",
|
||||
EnvAPIToken: "B",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"NAMECOM_USERNAME": "",
|
||||
"NAMECOM_API_TOKEN": "",
|
||||
EnvUsername: "",
|
||||
EnvAPIToken: "",
|
||||
},
|
||||
expected: "namedotcom: some credentials information are missing: NAMECOM_USERNAME,NAMECOM_API_TOKEN",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
envVars: map[string]string{
|
||||
"NAMECOM_USERNAME": "",
|
||||
"NAMECOM_API_TOKEN": "B",
|
||||
EnvUsername: "",
|
||||
EnvAPIToken: "B",
|
||||
},
|
||||
expected: "namedotcom: some credentials information are missing: NAMECOM_USERNAME",
|
||||
},
|
||||
{
|
||||
desc: "missing api token",
|
||||
envVars: map[string]string{
|
||||
"NAMECOM_USERNAME": "A",
|
||||
"NAMECOM_API_TOKEN": "",
|
||||
EnvUsername: "A",
|
||||
EnvAPIToken: "",
|
||||
},
|
||||
expected: "namedotcom: some credentials information are missing: NAMECOM_API_TOKEN",
|
||||
},
|
||||
|
|
|
@ -17,6 +17,17 @@ const (
|
|||
maxTTL = 2592000
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "NAMESILO_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -28,9 +39,9 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond("NAMESILO_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("NAMESILO_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt("NAMESILO_TTL", defaultTTL),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,13 +56,13 @@ type DNSProvider struct {
|
|||
//
|
||||
// See: https://www.namesilo.com/api_reference.php
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("NAMESILO_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("namesilo: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["NAMESILO_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"NAMESILO_TTL",
|
||||
"NAMESILO_API_KEY").
|
||||
WithDomain("NAMESILO_DOMAIN")
|
||||
EnvTTL,
|
||||
EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,7 +24,7 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"NAMESILO_API_KEY": "A",
|
||||
EnvAPIKey: "A",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -33,8 +35,8 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "unsupported TTL",
|
||||
envVars: map[string]string{
|
||||
"NAMESILO_API_KEY": "A",
|
||||
"NAMESILO_TTL": "180",
|
||||
EnvAPIKey: "A",
|
||||
EnvTTL: "180",
|
||||
},
|
||||
expected: "namesilo: TTL should be in [3600, 2592000]",
|
||||
},
|
||||
|
|
|
@ -15,6 +15,20 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "NETCUP_"
|
||||
|
||||
EnvCustomerNumber = envNamespace + "CUSTOMER_NUMBER"
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvAPIPassword = envNamespace + "API_PASSWORD"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
Key string
|
||||
|
@ -29,11 +43,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("NETCUP_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("NETCUP_PROPAGATION_TIMEOUT", 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond("NETCUP_POLLING_INTERVAL", 5*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("NETCUP_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -48,15 +62,15 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// NETCUP_CUSTOMER_NUMBER, NETCUP_API_KEY, NETCUP_API_PASSWORD
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("NETCUP_CUSTOMER_NUMBER", "NETCUP_API_KEY", "NETCUP_API_PASSWORD")
|
||||
values, err := env.Get(EnvCustomerNumber, EnvAPIKey, EnvAPIPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("netcup: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Customer = values["NETCUP_CUSTOMER_NUMBER"]
|
||||
config.Key = values["NETCUP_API_KEY"]
|
||||
config.Password = values["NETCUP_API_PASSWORD"]
|
||||
config.Customer = values[EnvCustomerNumber]
|
||||
config.Key = values[EnvAPIKey]
|
||||
config.Password = values[EnvAPIPassword]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -9,11 +9,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"NETCUP_CUSTOMER_NUMBER",
|
||||
"NETCUP_API_KEY",
|
||||
"NETCUP_API_PASSWORD").
|
||||
WithDomain("NETCUP_DOMAIN")
|
||||
EnvCustomerNumber,
|
||||
EnvAPIKey,
|
||||
EnvAPIPassword).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -24,44 +26,44 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"NETCUP_CUSTOMER_NUMBER": "A",
|
||||
"NETCUP_API_KEY": "B",
|
||||
"NETCUP_API_PASSWORD": "C",
|
||||
EnvCustomerNumber: "A",
|
||||
EnvAPIKey: "B",
|
||||
EnvAPIPassword: "C",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"NETCUP_CUSTOMER_NUMBER": "",
|
||||
"NETCUP_API_KEY": "",
|
||||
"NETCUP_API_PASSWORD": "",
|
||||
EnvCustomerNumber: "",
|
||||
EnvAPIKey: "",
|
||||
EnvAPIPassword: "",
|
||||
},
|
||||
expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER,NETCUP_API_KEY,NETCUP_API_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing customer number",
|
||||
envVars: map[string]string{
|
||||
"NETCUP_CUSTOMER_NUMBER": "",
|
||||
"NETCUP_API_KEY": "B",
|
||||
"NETCUP_API_PASSWORD": "C",
|
||||
EnvCustomerNumber: "",
|
||||
EnvAPIKey: "B",
|
||||
EnvAPIPassword: "C",
|
||||
},
|
||||
expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER",
|
||||
},
|
||||
{
|
||||
desc: "missing API key",
|
||||
envVars: map[string]string{
|
||||
"NETCUP_CUSTOMER_NUMBER": "A",
|
||||
"NETCUP_API_KEY": "",
|
||||
"NETCUP_API_PASSWORD": "C",
|
||||
EnvCustomerNumber: "A",
|
||||
EnvAPIKey: "",
|
||||
EnvAPIPassword: "C",
|
||||
},
|
||||
expected: "netcup: some credentials information are missing: NETCUP_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing api password",
|
||||
envVars: map[string]string{
|
||||
"NETCUP_CUSTOMER_NUMBER": "A",
|
||||
"NETCUP_API_KEY": "B",
|
||||
"NETCUP_API_PASSWORD": "",
|
||||
EnvCustomerNumber: "A",
|
||||
EnvAPIKey: "B",
|
||||
EnvAPIPassword: "",
|
||||
},
|
||||
expected: "netcup: some credentials information are missing: NETCUP_API_PASSWORD",
|
||||
},
|
||||
|
|
|
@ -14,6 +14,20 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/wait"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "NIFCLOUD_"
|
||||
|
||||
EnvAccessKeyID = envNamespace + "ACCESS_KEY_ID"
|
||||
EnvSecretAccessKey = envNamespace + "SECRET_ACCESS_KEY"
|
||||
EnvDNSEndpoint = envNamespace + "DNS_ENDPOINT"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
|
@ -28,11 +42,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("NIFCLOUD_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("NIFCLOUD_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("NIFCLOUD_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("NIFCLOUD_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -47,15 +61,15 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables:
|
||||
// NIFCLOUD_ACCESS_KEY_ID and NIFCLOUD_SECRET_ACCESS_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("NIFCLOUD_ACCESS_KEY_ID", "NIFCLOUD_SECRET_ACCESS_KEY")
|
||||
values, err := env.Get(EnvAccessKeyID, EnvSecretAccessKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("nifcloud: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.BaseURL = env.GetOrFile("NIFCLOUD_DNS_ENDPOINT")
|
||||
config.AccessKey = values["NIFCLOUD_ACCESS_KEY_ID"]
|
||||
config.SecretKey = values["NIFCLOUD_SECRET_ACCESS_KEY"]
|
||||
config.BaseURL = env.GetOrFile(EnvDNSEndpoint)
|
||||
config.AccessKey = values[EnvAccessKeyID]
|
||||
config.SecretKey = values[EnvSecretAccessKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"NIFCLOUD_ACCESS_KEY_ID",
|
||||
"NIFCLOUD_SECRET_ACCESS_KEY").
|
||||
WithDomain("NIFCLOUD_DOMAIN")
|
||||
EnvAccessKeyID,
|
||||
EnvSecretAccessKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"NIFCLOUD_ACCESS_KEY_ID": "123",
|
||||
"NIFCLOUD_SECRET_ACCESS_KEY": "456",
|
||||
EnvAccessKeyID: "123",
|
||||
EnvSecretAccessKey: "456",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"NIFCLOUD_ACCESS_KEY_ID": "",
|
||||
"NIFCLOUD_SECRET_ACCESS_KEY": "",
|
||||
EnvAccessKeyID: "",
|
||||
EnvSecretAccessKey: "",
|
||||
},
|
||||
expected: "nifcloud: some credentials information are missing: NIFCLOUD_ACCESS_KEY_ID,NIFCLOUD_SECRET_ACCESS_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing access key",
|
||||
envVars: map[string]string{
|
||||
"NIFCLOUD_ACCESS_KEY_ID": "",
|
||||
"NIFCLOUD_SECRET_ACCESS_KEY": "456",
|
||||
EnvAccessKeyID: "",
|
||||
EnvSecretAccessKey: "456",
|
||||
},
|
||||
expected: "nifcloud: some credentials information are missing: NIFCLOUD_ACCESS_KEY_ID",
|
||||
},
|
||||
{
|
||||
desc: "missing secret key",
|
||||
envVars: map[string]string{
|
||||
"NIFCLOUD_ACCESS_KEY_ID": "123",
|
||||
"NIFCLOUD_SECRET_ACCESS_KEY": "",
|
||||
EnvAccessKeyID: "123",
|
||||
EnvSecretAccessKey: "",
|
||||
},
|
||||
expected: "nifcloud: some credentials information are missing: NIFCLOUD_SECRET_ACCESS_KEY",
|
||||
},
|
||||
|
|
|
@ -15,6 +15,18 @@ import (
|
|||
"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "NS1_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -27,11 +39,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("NS1_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("NS1_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("NS1_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("NS1_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -45,13 +57,13 @@ type DNSProvider struct {
|
|||
// NewDNSProvider returns a DNSProvider instance configured for NS1.
|
||||
// Credentials must be passed in the environment variables: NS1_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("NS1_API_KEY")
|
||||
values, err := env.Get(EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ns1: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values["NS1_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var envTest = tester.NewEnvTest("NS1_API_KEY").
|
||||
WithDomain("NS1_DOMAIN")
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -21,13 +23,13 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"NS1_API_KEY": "123",
|
||||
EnvAPIKey: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"NS1_API_KEY": "",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "ns1: some credentials information are missing: NS1_API_KEY",
|
||||
},
|
||||
|
|
|
@ -11,15 +11,6 @@ import (
|
|||
"github.com/oracle/oci-go-sdk/common"
|
||||
)
|
||||
|
||||
const (
|
||||
ociPrivkey = "OCI_PRIVKEY"
|
||||
ociPrivkeyPass = "OCI_PRIVKEY_PASS"
|
||||
ociTenancyOCID = "OCI_TENANCY_OCID"
|
||||
ociUserOCID = "OCI_USER_OCID"
|
||||
ociPubkeyFingerprint = "OCI_PUBKEY_FINGERPRINT"
|
||||
ociRegion = "OCI_REGION"
|
||||
)
|
||||
|
||||
type configProvider struct {
|
||||
values map[string]string
|
||||
privateKeyPassphrase string
|
||||
|
@ -28,12 +19,12 @@ type configProvider struct {
|
|||
func newConfigProvider(values map[string]string) *configProvider {
|
||||
return &configProvider{
|
||||
values: values,
|
||||
privateKeyPassphrase: env.GetOrFile(ociPrivkeyPass),
|
||||
privateKeyPassphrase: env.GetOrFile(EnvPrivKeyPass),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *configProvider) PrivateRSAKey() (*rsa.PrivateKey, error) {
|
||||
privateKey, err := getPrivateKey(ociPrivkey)
|
||||
privateKey, err := getPrivateKey(envPrivKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -61,19 +52,19 @@ func (p *configProvider) KeyID() (string, error) {
|
|||
}
|
||||
|
||||
func (p *configProvider) TenancyOCID() (value string, err error) {
|
||||
return p.values[ociTenancyOCID], nil
|
||||
return p.values[EnvTenancyOCID], nil
|
||||
}
|
||||
|
||||
func (p *configProvider) UserOCID() (string, error) {
|
||||
return p.values[ociUserOCID], nil
|
||||
return p.values[EnvUserOCID], nil
|
||||
}
|
||||
|
||||
func (p *configProvider) KeyFingerprint() (string, error) {
|
||||
return p.values[ociPubkeyFingerprint], nil
|
||||
return p.values[EnvPubKeyFingerprint], nil
|
||||
}
|
||||
|
||||
func (p *configProvider) Region() (string, error) {
|
||||
return p.values[ociRegion], nil
|
||||
return p.values[EnvRegion], nil
|
||||
}
|
||||
|
||||
func getPrivateKey(envVar string) ([]byte, error) {
|
||||
|
|
|
@ -13,6 +13,25 @@ import (
|
|||
"github.com/oracle/oci-go-sdk/dns"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "OCI_"
|
||||
|
||||
EnvCompartmentOCID = envNamespace + "COMPARTMENT_OCID"
|
||||
envPrivKey = envNamespace + "PRIVKEY"
|
||||
EnvPrivKeyFile = envPrivKey + "_FILE"
|
||||
EnvPrivKeyPass = envPrivKey + "_PASS"
|
||||
EnvTenancyOCID = envNamespace + "TENANCY_OCID"
|
||||
EnvUserOCID = envNamespace + "USER_OCID"
|
||||
EnvPubKeyFingerprint = envNamespace + "PUBKEY_FINGERPRINT"
|
||||
EnvRegion = envNamespace + "REGION"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
CompartmentID string
|
||||
|
@ -26,11 +45,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("OCI_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("OCI_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("OCI_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("OCI_HTTP_TIMEOUT", 60*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 60*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -43,13 +62,13 @@ type DNSProvider struct {
|
|||
|
||||
// NewDNSProvider returns a DNSProvider instance configured for OracleCloud.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(ociPrivkey, ociTenancyOCID, ociUserOCID, ociPubkeyFingerprint, ociRegion, "OCI_COMPARTMENT_OCID")
|
||||
values, err := env.Get(envPrivKey, EnvTenancyOCID, EnvUserOCID, EnvPubKeyFingerprint, EnvRegion, EnvCompartmentOCID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oraclecloud: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.CompartmentID = values["OCI_COMPARTMENT_OCID"]
|
||||
config.CompartmentID = values[EnvCompartmentOCID]
|
||||
config.OCIConfigProvider = newConfigProvider(values)
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
|
|
|
@ -16,16 +16,18 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
ociPrivkey,
|
||||
ociPrivkey+"_FILE",
|
||||
ociPrivkeyPass,
|
||||
ociTenancyOCID,
|
||||
ociUserOCID,
|
||||
ociPubkeyFingerprint,
|
||||
ociRegion,
|
||||
"OCI_COMPARTMENT_OCID").
|
||||
WithDomain("ORACLECLOUD_DOMAIN")
|
||||
envPrivKey,
|
||||
EnvPrivKeyFile,
|
||||
EnvPrivKeyPass,
|
||||
EnvTenancyOCID,
|
||||
EnvUserOCID,
|
||||
EnvPubKeyFingerprint,
|
||||
EnvRegion,
|
||||
EnvCompartmentOCID).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -36,25 +38,25 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret1"),
|
||||
ociPrivkeyPass: "secret1",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret1"),
|
||||
EnvPrivKeyPass: "secret1",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "success file",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey + "_FILE": mustGeneratePrivateKeyFile("secret1"),
|
||||
ociPrivkeyPass: "secret1",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
EnvPrivKeyFile: mustGeneratePrivateKeyFile("secret1"),
|
||||
EnvPrivKeyPass: "secret1",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -65,104 +67,104 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "missing CompartmentID",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_COMPARTMENT_OCID",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_PRIVKEY",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: "",
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: "",
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_PRIVKEY",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_PRIVKEY_PASS",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: can not create client, bad configuration: x509: decryption password incorrect",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_TENANCY_OCID",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_TENANCY_OCID",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_USER_OCID",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_USER_OCID",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_PUBKEY_FINGERPRINT",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "",
|
||||
ociRegion: "us-phoenix-1",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "",
|
||||
EnvRegion: "us-phoenix-1",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_PUBKEY_FINGERPRINT",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_REGION",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_REGION",
|
||||
},
|
||||
{
|
||||
desc: "missing OCI_REGION",
|
||||
envVars: map[string]string{
|
||||
ociPrivkey: mustGeneratePrivateKey("secret"),
|
||||
ociPrivkeyPass: "secret",
|
||||
ociTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
ociUserOCID: "ocid1.user.oc1..secret",
|
||||
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
ociRegion: "",
|
||||
"OCI_COMPARTMENT_OCID": "123",
|
||||
envPrivKey: mustGeneratePrivateKey("secret"),
|
||||
EnvPrivKeyPass: "secret",
|
||||
EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
|
||||
EnvUserOCID: "ocid1.user.oc1..secret",
|
||||
EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
|
||||
EnvRegion: "",
|
||||
EnvCompartmentOCID: "123",
|
||||
},
|
||||
expected: "oraclecloud: some credentials information are missing: OCI_REGION",
|
||||
},
|
||||
|
@ -171,7 +173,7 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
defer func() {
|
||||
privKeyFile := os.Getenv(ociPrivkey + "_FILE")
|
||||
privKeyFile := os.Getenv(EnvPrivKeyFile)
|
||||
if privKeyFile != "" {
|
||||
_ = os.Remove(privKeyFile)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,22 @@ const defaultIdentityEndpoint = "https://iam.eu-de.otc.t-systems.com:443/v3/auth
|
|||
// minTTL 300 is otc minimum value for ttl
|
||||
const minTTL = 300
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "OTC_"
|
||||
|
||||
EnvDomainName = envNamespace + "DOMAIN_NAME"
|
||||
EnvUserName = envNamespace + "USER_NAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
EnvProjectName = envNamespace + "PROJECT_NAME"
|
||||
EnvIdentityEndpoint = envNamespace + "IDENTITY_ENDPOINT"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
IdentityEndpoint string
|
||||
|
@ -33,12 +49,12 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
IdentityEndpoint: env.GetOrDefaultString("OTC_IDENTITY_ENDPOINT", defaultIdentityEndpoint),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("OTC_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("OTC_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt("OTC_TTL", minTTL),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
IdentityEndpoint: env.GetOrDefaultString(EnvIdentityEndpoint, defaultIdentityEndpoint),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("OTC_HTTP_TIMEOUT", 10*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: (&net.Dialer{
|
||||
|
@ -70,16 +86,16 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variables: OTC_USER_NAME,
|
||||
// OTC_DOMAIN_NAME, OTC_PASSWORD OTC_PROJECT_NAME and OTC_IDENTITY_ENDPOINT.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("OTC_DOMAIN_NAME", "OTC_USER_NAME", "OTC_PASSWORD", "OTC_PROJECT_NAME")
|
||||
values, err := env.Get(EnvDomainName, EnvUserName, EnvPassword, EnvProjectName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("otc: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.DomainName = values["OTC_DOMAIN_NAME"]
|
||||
config.UserName = values["OTC_USER_NAME"]
|
||||
config.Password = values["OTC_PASSWORD"]
|
||||
config.ProjectName = values["OTC_PROJECT_NAME"]
|
||||
config.DomainName = values[EnvDomainName]
|
||||
config.UserName = values[EnvUserName]
|
||||
config.Password = values[EnvPassword]
|
||||
config.ProjectName = values[EnvProjectName]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ func (s *OTCSuite) SetupTest() {
|
|||
s.Mock = NewDNSServerMock(s.T())
|
||||
s.Mock.HandleAuthSuccessfully()
|
||||
s.envTest = tester.NewEnvTest(
|
||||
"OTC_DOMAIN_NAME",
|
||||
"OTC_USER_NAME",
|
||||
"OTC_PASSWORD",
|
||||
"OTC_PROJECT_NAME",
|
||||
"OTC_IDENTITY_ENDPOINT",
|
||||
EnvDomainName,
|
||||
EnvUserName,
|
||||
EnvPassword,
|
||||
EnvProjectName,
|
||||
EnvIdentityEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,11 @@ func (s *OTCSuite) TestLoginEnv() {
|
|||
s.envTest.ClearEnv()
|
||||
|
||||
s.envTest.Apply(map[string]string{
|
||||
"OTC_DOMAIN_NAME": "unittest1",
|
||||
"OTC_USER_NAME": "unittest2",
|
||||
"OTC_PASSWORD": "unittest3",
|
||||
"OTC_PROJECT_NAME": "unittest4",
|
||||
"OTC_IDENTITY_ENDPOINT": "unittest5",
|
||||
EnvDomainName: "unittest1",
|
||||
EnvUserName: "unittest2",
|
||||
EnvPassword: "unittest3",
|
||||
EnvProjectName: "unittest4",
|
||||
EnvIdentityEndpoint: "unittest5",
|
||||
})
|
||||
|
||||
provider, err := NewDNSProvider()
|
||||
|
@ -78,7 +78,7 @@ func (s *OTCSuite) TestLoginEnv() {
|
|||
s.Equal(provider.config.ProjectName, "unittest4")
|
||||
s.Equal(provider.config.IdentityEndpoint, "unittest5")
|
||||
|
||||
os.Setenv("OTC_IDENTITY_ENDPOINT", "")
|
||||
os.Setenv(EnvIdentityEndpoint, "")
|
||||
|
||||
provider, err = NewDNSProvider()
|
||||
s.Require().NoError(err)
|
||||
|
|
|
@ -17,6 +17,21 @@ import (
|
|||
// OVH API reference: https://eu.api.ovh.com/
|
||||
// Create a Token: https://eu.api.ovh.com/createToken/
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "OVH_"
|
||||
|
||||
EnvEndpoint = envNamespace + "ENDPOINT"
|
||||
EnvApplicationKey = envNamespace + "APPLICATION_KEY"
|
||||
EnvApplicationSecret = envNamespace + "APPLICATION_SECRET"
|
||||
EnvConsumerKey = envNamespace + "CONSUMER_KEY"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Record a DNS record
|
||||
type Record struct {
|
||||
ID int64 `json:"id,omitempty"`
|
||||
|
@ -42,11 +57,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("OVH_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("OVH_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond("OVH_POLLING_INTERVAL", dns01.DefaultPollingInterval),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("OVH_HTTP_TIMEOUT", ovh.DefaultTimeout),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, ovh.DefaultTimeout),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -67,16 +82,16 @@ type DNSProvider struct {
|
|||
// OVH_APPLICATION_SECRET
|
||||
// OVH_CONSUMER_KEY
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("OVH_ENDPOINT", "OVH_APPLICATION_KEY", "OVH_APPLICATION_SECRET", "OVH_CONSUMER_KEY")
|
||||
values, err := env.Get(EnvEndpoint, EnvApplicationKey, EnvApplicationSecret, EnvConsumerKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ovh: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIEndpoint = values["OVH_ENDPOINT"]
|
||||
config.ApplicationKey = values["OVH_APPLICATION_KEY"]
|
||||
config.ApplicationSecret = values["OVH_APPLICATION_SECRET"]
|
||||
config.ConsumerKey = values["OVH_CONSUMER_KEY"]
|
||||
config.APIEndpoint = values[EnvEndpoint]
|
||||
config.ApplicationKey = values[EnvApplicationKey]
|
||||
config.ApplicationSecret = values[EnvApplicationSecret]
|
||||
config.ConsumerKey = values[EnvConsumerKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,12 +8,14 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"OVH_ENDPOINT",
|
||||
"OVH_APPLICATION_KEY",
|
||||
"OVH_APPLICATION_SECRET",
|
||||
"OVH_CONSUMER_KEY").
|
||||
WithDomain("OVH_DOMAIN")
|
||||
EnvEndpoint,
|
||||
EnvApplicationKey,
|
||||
EnvApplicationSecret,
|
||||
EnvConsumerKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -24,69 +26,69 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "ovh-eu",
|
||||
"OVH_APPLICATION_KEY": "B",
|
||||
"OVH_APPLICATION_SECRET": "C",
|
||||
"OVH_CONSUMER_KEY": "D",
|
||||
EnvEndpoint: "ovh-eu",
|
||||
EnvApplicationKey: "B",
|
||||
EnvApplicationSecret: "C",
|
||||
EnvConsumerKey: "D",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "",
|
||||
"OVH_APPLICATION_KEY": "",
|
||||
"OVH_APPLICATION_SECRET": "",
|
||||
"OVH_CONSUMER_KEY": "",
|
||||
EnvEndpoint: "",
|
||||
EnvApplicationKey: "",
|
||||
EnvApplicationSecret: "",
|
||||
EnvConsumerKey: "",
|
||||
},
|
||||
expected: "ovh: some credentials information are missing: OVH_ENDPOINT,OVH_APPLICATION_KEY,OVH_APPLICATION_SECRET,OVH_CONSUMER_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing endpoint",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "",
|
||||
"OVH_APPLICATION_KEY": "B",
|
||||
"OVH_APPLICATION_SECRET": "C",
|
||||
"OVH_CONSUMER_KEY": "D",
|
||||
EnvEndpoint: "",
|
||||
EnvApplicationKey: "B",
|
||||
EnvApplicationSecret: "C",
|
||||
EnvConsumerKey: "D",
|
||||
},
|
||||
expected: "ovh: some credentials information are missing: OVH_ENDPOINT",
|
||||
},
|
||||
{
|
||||
desc: "missing invalid endpoint",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "foobar",
|
||||
"OVH_APPLICATION_KEY": "B",
|
||||
"OVH_APPLICATION_SECRET": "C",
|
||||
"OVH_CONSUMER_KEY": "D",
|
||||
EnvEndpoint: "foobar",
|
||||
EnvApplicationKey: "B",
|
||||
EnvApplicationSecret: "C",
|
||||
EnvConsumerKey: "D",
|
||||
},
|
||||
expected: "ovh: unknown endpoint 'foobar', consider checking 'Endpoints' list of using an URL",
|
||||
},
|
||||
{
|
||||
desc: "missing application key",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "ovh-eu",
|
||||
"OVH_APPLICATION_KEY": "",
|
||||
"OVH_APPLICATION_SECRET": "C",
|
||||
"OVH_CONSUMER_KEY": "D",
|
||||
EnvEndpoint: "ovh-eu",
|
||||
EnvApplicationKey: "",
|
||||
EnvApplicationSecret: "C",
|
||||
EnvConsumerKey: "D",
|
||||
},
|
||||
expected: "ovh: some credentials information are missing: OVH_APPLICATION_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing application secret",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "ovh-eu",
|
||||
"OVH_APPLICATION_KEY": "B",
|
||||
"OVH_APPLICATION_SECRET": "",
|
||||
"OVH_CONSUMER_KEY": "D",
|
||||
EnvEndpoint: "ovh-eu",
|
||||
EnvApplicationKey: "B",
|
||||
EnvApplicationSecret: "",
|
||||
EnvConsumerKey: "D",
|
||||
},
|
||||
expected: "ovh: some credentials information are missing: OVH_APPLICATION_SECRET",
|
||||
},
|
||||
{
|
||||
desc: "missing consumer key",
|
||||
envVars: map[string]string{
|
||||
"OVH_ENDPOINT": "ovh-eu",
|
||||
"OVH_APPLICATION_KEY": "B",
|
||||
"OVH_APPLICATION_SECRET": "C",
|
||||
"OVH_CONSUMER_KEY": "",
|
||||
EnvEndpoint: "ovh-eu",
|
||||
EnvApplicationKey: "B",
|
||||
EnvApplicationSecret: "C",
|
||||
EnvConsumerKey: "",
|
||||
},
|
||||
expected: "ovh: some credentials information are missing: OVH_CONSUMER_KEY",
|
||||
},
|
||||
|
|
|
@ -15,6 +15,19 @@ import (
|
|||
"github.com/go-acme/lego/v3/platform/config/env"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "PDNS_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvAPIURL = envNamespace + "API_URL"
|
||||
|
||||
EnvTTL = envNamespace + "TTL"
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider
|
||||
type Config struct {
|
||||
APIKey string
|
||||
|
@ -28,11 +41,11 @@ type Config struct {
|
|||
// NewDefaultConfig returns a default configuration for the DNSProvider
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
TTL: env.GetOrDefaultInt("PDNS_TTL", dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond("PDNS_PROPAGATION_TIMEOUT", 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond("PDNS_POLLING_INTERVAL", 2*time.Second),
|
||||
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: env.GetOrDefaultSecond("PDNS_HTTP_TIMEOUT", 30*time.Second),
|
||||
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -47,19 +60,19 @@ type DNSProvider struct {
|
|||
// Credentials must be passed in the environment variable:
|
||||
// PDNS_API_URL and PDNS_API_KEY.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get("PDNS_API_KEY", "PDNS_API_URL")
|
||||
values, err := env.Get(EnvAPIKey, EnvAPIURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pdns: %w", err)
|
||||
}
|
||||
|
||||
hostURL, err := url.Parse(values["PDNS_API_URL"])
|
||||
hostURL, err := url.Parse(values[EnvAPIURL])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pdns: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Host = hostURL
|
||||
config.APIKey = values["PDNS_API_KEY"]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
"PDNS_API_URL",
|
||||
"PDNS_API_KEY").
|
||||
WithDomain("PDNS_DOMAIN")
|
||||
EnvAPIURL,
|
||||
EnvAPIKey).
|
||||
WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
|
|||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
"PDNS_API_KEY": "123",
|
||||
"PDNS_API_URL": "http://example.com",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPIURL: "http://example.com",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{
|
||||
"PDNS_API_KEY": "",
|
||||
"PDNS_API_URL": "",
|
||||
EnvAPIKey: "",
|
||||
EnvAPIURL: "",
|
||||
},
|
||||
expected: "pdns: some credentials information are missing: PDNS_API_KEY,PDNS_API_URL",
|
||||
},
|
||||
{
|
||||
desc: "missing api key",
|
||||
envVars: map[string]string{
|
||||
"PDNS_API_KEY": "",
|
||||
"PDNS_API_URL": "http://example.com",
|
||||
EnvAPIKey: "",
|
||||
EnvAPIURL: "http://example.com",
|
||||
},
|
||||
expected: "pdns: some credentials information are missing: PDNS_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing API URL",
|
||||
envVars: map[string]string{
|
||||
"PDNS_API_KEY": "123",
|
||||
"PDNS_API_URL": "",
|
||||
EnvAPIKey: "123",
|
||||
EnvAPIURL: "",
|
||||
},
|
||||
expected: "pdns: some credentials information are missing: PDNS_API_URL",
|
||||
},
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue