Standardization of the definition of env vars. (#1082)

This commit is contained in:
Ludovic Fernandez 2020-03-11 23:51:10 +01:00 committed by GitHub
parent aeb20f4deb
commit 403070dd9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
129 changed files with 2212 additions and 1312 deletions

View file

@ -14,12 +14,13 @@ import (
const ( const (
// envNamespace is the prefix for ACME-DNS environment variables. // envNamespace is the prefix for ACME-DNS environment variables.
envNamespace = "ACME_DNS_" 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). // (e.g. https://acmedns.your-domain.com).
apiBaseEnvVar = envNamespace + "API_BASE" EnvAPIBase = envNamespace + "API_BASE"
// storagePathEnvVar is the environment variable name for the ACME-DNS JSON account data file. // 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. // 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. // 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. // 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) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(apiBaseEnvVar, storagePathEnvVar) values, err := env.Get(EnvAPIBase, EnvStoragePath)
if err != nil { if err != nil {
return nil, fmt.Errorf("acme-dns: %w", err) return nil, fmt.Errorf("acme-dns: %w", err)
} }
client := goacmedns.NewClient(values[apiBaseEnvVar]) client := goacmedns.NewClient(values[EnvAPIBase])
storage := goacmedns.NewFileStorage(values[storagePathEnvVar], 0600) storage := goacmedns.NewFileStorage(values[EnvStoragePath], 0600)
return NewDNSProviderClient(client, storage) return NewDNSProviderClient(client, storage)
} }

View file

@ -17,6 +17,20 @@ import (
const defaultRegionID = "cn-hangzhou" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -31,10 +45,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("ALICLOUD_TTL", 600), TTL: env.GetOrDefaultInt(EnvTTL, 600),
PropagationTimeout: env.GetOrDefaultSecond("ALICLOUD_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("ALICLOUD_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPTimeout: env.GetOrDefaultSecond("ALICLOUD_HTTP_TIMEOUT", 10*time.Second), HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
} }
} }
@ -47,15 +61,15 @@ type DNSProvider struct {
// NewDNSProvider returns a DNSProvider instance configured for Alibaba Cloud DNS. // 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. // Credentials must be passed in the environment variables: ALICLOUD_ACCESS_KEY and ALICLOUD_SECRET_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("ALICLOUD_ACCESS_KEY", "ALICLOUD_SECRET_KEY") values, err := env.Get(EnvAccessKey, EnvSecretKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("alicloud: %w", err) return nil, fmt.Errorf("alicloud: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["ALICLOUD_ACCESS_KEY"] config.APIKey = values[EnvAccessKey]
config.SecretKey = values["ALICLOUD_SECRET_KEY"] config.SecretKey = values[EnvSecretKey]
config.RegionID = env.GetOrFile("ALICLOUD_REGION_ID") config.RegionID = env.GetOrFile(EnvRegionID)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"ALICLOUD_ACCESS_KEY", EnvAccessKey,
"ALICLOUD_SECRET_KEY"). EnvSecretKey).
WithDomain("ALICLOUD_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"ALICLOUD_ACCESS_KEY": "123", EnvAccessKey: "123",
"ALICLOUD_SECRET_KEY": "456", EnvSecretKey: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"ALICLOUD_ACCESS_KEY": "", EnvAccessKey: "",
"ALICLOUD_SECRET_KEY": "", EnvSecretKey: "",
}, },
expected: "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY,ALICLOUD_SECRET_KEY", expected: "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY,ALICLOUD_SECRET_KEY",
}, },
{ {
desc: "missing access key", desc: "missing access key",
envVars: map[string]string{ envVars: map[string]string{
"ALICLOUD_ACCESS_KEY": "", EnvAccessKey: "",
"ALICLOUD_SECRET_KEY": "456", EnvSecretKey: "456",
}, },
expected: "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY", expected: "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"ALICLOUD_ACCESS_KEY": "123", EnvAccessKey: "123",
"ALICLOUD_SECRET_KEY": "", EnvSecretKey: "",
}, },
expected: "alicloud: some credentials information are missing: ALICLOUD_SECRET_KEY", expected: "alicloud: some credentials information are missing: ALICLOUD_SECRET_KEY",
}, },

View file

@ -14,6 +14,19 @@ import (
const defaultBaseURL = "https://api.auroradns.eu" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -27,9 +40,9 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("AURORA_TTL", 300), TTL: env.GetOrDefaultInt(EnvTTL, 300),
PropagationTimeout: env.GetOrDefaultSecond("AURORA_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("AURORA_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
} }
} }
@ -45,15 +58,15 @@ type DNSProvider struct {
// Credentials must be passed in the environment variables: // Credentials must be passed in the environment variables:
// AURORA_USER_ID and AURORA_KEY. // AURORA_USER_ID and AURORA_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("AURORA_USER_ID", "AURORA_KEY") values, err := env.Get(EnvUserID, EnvKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("aurora: %w", err) return nil, fmt.Errorf("aurora: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.BaseURL = env.GetOrFile("AURORA_ENDPOINT") config.BaseURL = env.GetOrFile(EnvEndpoint)
config.UserID = values["AURORA_USER_ID"] config.UserID = values[EnvUserID]
config.Key = values["AURORA_KEY"] config.Key = values[EnvKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -13,9 +13,8 @@ import (
) )
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"AURORA_USER_ID", EnvUserID,
"AURORA_KEY", EnvKey)
)
func setupTest() (*DNSProvider, *http.ServeMux, func()) { func setupTest() (*DNSProvider, *http.ServeMux, func()) {
handler := http.NewServeMux() handler := http.NewServeMux()
@ -43,31 +42,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"AURORA_USER_ID": "123", EnvUserID: "123",
"AURORA_KEY": "456", EnvKey: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"AURORA_USER_ID": "", EnvUserID: "",
"AURORA_KEY": "", EnvKey: "",
}, },
expected: "aurora: some credentials information are missing: AURORA_USER_ID,AURORA_KEY", expected: "aurora: some credentials information are missing: AURORA_USER_ID,AURORA_KEY",
}, },
{ {
desc: "missing user id", desc: "missing user id",
envVars: map[string]string{ envVars: map[string]string{
"AURORA_USER_ID": "", EnvUserID: "",
"AURORA_KEY": "456", EnvKey: "456",
}, },
expected: "aurora: some credentials information are missing: AURORA_USER_ID", expected: "aurora: some credentials information are missing: AURORA_USER_ID",
}, },
{ {
desc: "missing key", desc: "missing key",
envVars: map[string]string{ envVars: map[string]string{
"AURORA_USER_ID": "123", EnvUserID: "123",
"AURORA_KEY": "", EnvKey: "",
}, },
expected: "aurora: some credentials information are missing: AURORA_KEY", expected: "aurora: some credentials information are missing: AURORA_KEY",
}, },

View file

@ -11,15 +11,19 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "github.com/go-acme/lego/v3/platform/config/env"
) )
// Environment variables names.
const ( const (
envAPIUser = "AUTODNS_API_USER" envNamespace = "AUTODNS_"
envAPIPassword = "AUTODNS_API_PASSWORD"
envAPIEndpoint = "AUTODNS_ENDPOINT" EnvAPIUser = envNamespace + "API_USER"
envAPIEndpointContext = "AUTODNS_CONTEXT" EnvAPIPassword = envNamespace + "API_PASSWORD"
envTTL = "AUTODNS_TTL" EnvAPIEndpoint = envNamespace + "ENDPOINT"
envPropagationTimeout = "AUTODNS_PROPAGATION_TIMEOUT" EnvAPIEndpointContext = envNamespace + "CONTEXT"
envPollingInterval = "AUTODNS_POLLING_INTERVAL"
envHTTPTimeout = "AUTODNS_HTTP_TIMEOUT" EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
) )
const ( const (
@ -39,16 +43,16 @@ type Config struct {
} }
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
endpoint, _ := url.Parse(env.GetOrDefaultString(envAPIEndpoint, defaultEndpoint)) endpoint, _ := url.Parse(env.GetOrDefaultString(EnvAPIEndpoint, defaultEndpoint))
return &Config{ return &Config{
Endpoint: endpoint, Endpoint: endpoint,
Context: env.GetOrDefaultInt(envAPIEndpointContext, defaultEndpointContext), Context: env.GetOrDefaultInt(EnvAPIEndpointContext, defaultEndpointContext),
TTL: env.GetOrDefaultInt(envTTL, defaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(envPropagationTimeout, 2*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond(envPollingInterval, 2*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
HTTPClient: &http.Client{ 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) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(envAPIUser, envAPIPassword) values, err := env.Get(EnvAPIUser, EnvAPIPassword)
if err != nil { if err != nil {
return nil, fmt.Errorf("autodns: %w", err) return nil, fmt.Errorf("autodns: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Username = values[envAPIUser] config.Username = values[EnvAPIUser]
config.Password = values[envAPIPassword] config.Password = values[EnvAPIPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,7 +8,13 @@ import (
"github.com/stretchr/testify/require" "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) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -19,31 +25,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
envAPIUser: "123", EnvAPIUser: "123",
envAPIPassword: "456", EnvAPIPassword: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
envAPIUser: "", EnvAPIUser: "",
envAPIPassword: "", EnvAPIPassword: "",
}, },
expected: "autodns: some credentials information are missing: AUTODNS_API_USER,AUTODNS_API_PASSWORD", expected: "autodns: some credentials information are missing: AUTODNS_API_USER,AUTODNS_API_PASSWORD",
}, },
{ {
desc: "missing user id", desc: "missing user id",
envVars: map[string]string{ envVars: map[string]string{
envAPIUser: "", EnvAPIUser: "",
envAPIPassword: "456", EnvAPIPassword: "456",
}, },
expected: "autodns: some credentials information are missing: AUTODNS_API_USER", expected: "autodns: some credentials information are missing: AUTODNS_API_USER",
}, },
{ {
desc: "missing key", desc: "missing key",
envVars: map[string]string{ envVars: map[string]string{
envAPIUser: "123", EnvAPIUser: "123",
envAPIPassword: "", EnvAPIPassword: "",
}, },
expected: "autodns: some credentials information are missing: AUTODNS_API_PASSWORD", expected: "autodns: some credentials information are missing: AUTODNS_API_PASSWORD",
}, },

View file

@ -23,6 +23,22 @@ import (
const defaultMetadataEndpoint = "http://169.254.169.254" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
// optional if using instance metadata service // optional if using instance metadata service
@ -44,10 +60,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("AZURE_TTL", 60), TTL: env.GetOrDefaultInt(EnvTTL, 60),
PropagationTimeout: env.GetOrDefaultSecond("AZURE_PROPAGATION_TIMEOUT", 2*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond("AZURE_POLLING_INTERVAL", 2*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
MetadataEndpoint: env.GetOrFile("AZURE_METADATA_ENDPOINT"), 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 // see: https://github.com/Azure/go-autorest/blob/v10.14.0/autorest/azure/auth/auth.go#L38-L42
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
config := NewDefaultConfig() config := NewDefaultConfig()
config.SubscriptionID = env.GetOrFile("AZURE_SUBSCRIPTION_ID") config.SubscriptionID = env.GetOrFile(EnvSubscriptionID)
config.ResourceGroup = env.GetOrFile("AZURE_RESOURCE_GROUP") config.ResourceGroup = env.GetOrFile(EnvResourceGroup)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -10,13 +10,15 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"AZURE_CLIENT_ID", EnvClientID,
"AZURE_CLIENT_SECRET", EnvClientSecret,
"AZURE_SUBSCRIPTION_ID", EnvSubscriptionID,
"AZURE_TENANT_ID", EnvTenantID,
"AZURE_RESOURCE_GROUP"). EnvResourceGroup).
WithDomain("AZURE_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -27,21 +29,21 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"AZURE_CLIENT_ID": "A", EnvClientID: "A",
"AZURE_CLIENT_SECRET": "B", EnvClientSecret: "B",
"AZURE_TENANT_ID": "C", EnvTenantID: "C",
"AZURE_SUBSCRIPTION_ID": "D", EnvSubscriptionID: "D",
"AZURE_RESOURCE_GROUP": "E", EnvResourceGroup: "E",
}, },
}, },
{ {
desc: "missing client ID", desc: "missing client ID",
envVars: map[string]string{ envVars: map[string]string{
"AZURE_CLIENT_ID": "", EnvClientID: "",
"AZURE_CLIENT_SECRET": "B", EnvClientSecret: "B",
"AZURE_TENANT_ID": "C", EnvTenantID: "C",
"AZURE_SUBSCRIPTION_ID": "D", EnvSubscriptionID: "D",
"AZURE_RESOURCE_GROUP": "E", EnvResourceGroup: "E",
}, },
expected: "failed to get oauth token from client credentials: parameter 'clientID' cannot be empty", expected: "failed to get oauth token from client credentials: parameter 'clientID' cannot be empty",
}, },

View file

@ -12,6 +12,17 @@ import (
"github.com/labbsr0x/bindman-dns-webhook/src/client" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
PropagationTimeout time.Duration PropagationTimeout time.Duration
@ -23,10 +34,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("BINDMAN_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("BINDMAN_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // 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. // BINDMAN_MANAGER_ADDRESS should have the scheme, hostname, and port (if required) of the authoritative Bindman Manager server.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("BINDMAN_MANAGER_ADDRESS") values, err := env.Get(EnvManagerAddress)
if err != nil { if err != nil {
return nil, fmt.Errorf("bindman: %w", err) return nil, fmt.Errorf("bindman: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.BaseURL = values["BINDMAN_MANAGER_ADDRESS"] config.BaseURL = values[EnvManagerAddress]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -12,7 +12,9 @@ import (
"github.com/stretchr/testify/require" "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) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -23,20 +25,20 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"BINDMAN_MANAGER_ADDRESS": "http://localhost", EnvManagerAddress: "http://localhost",
}, },
}, },
{ {
desc: "missing bindman manager address", desc: "missing bindman manager address",
envVars: map[string]string{ envVars: map[string]string{
"BINDMAN_MANAGER_ADDRESS": "", EnvManagerAddress: "",
}, },
expected: "bindman: some credentials information are missing: BINDMAN_MANAGER_ADDRESS", expected: "bindman: some credentials information are missing: BINDMAN_MANAGER_ADDRESS",
}, },
{ {
desc: "empty bindman manager address", desc: "empty bindman manager address",
envVars: map[string]string{ envVars: map[string]string{
"BINDMAN_MANAGER_ADDRESS": " ", EnvManagerAddress: " ",
}, },
expected: "bindman: managerAddress parameter must be a non-empty string", expected: "bindman: managerAddress parameter must be a non-empty string",
}, },

View file

@ -21,6 +21,22 @@ const (
txtType = "TXTRecord" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -37,11 +53,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("BLUECAT_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("BLUECAT_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("BLUECAT_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // 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 // 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) { 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 { if err != nil {
return nil, fmt.Errorf("bluecat: %w", err) return nil, fmt.Errorf("bluecat: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.BaseURL = values["BLUECAT_SERVER_URL"] config.BaseURL = values[EnvServerURL]
config.UserName = values["BLUECAT_USER_NAME"] config.UserName = values[EnvUserName]
config.Password = values["BLUECAT_PASSWORD"] config.Password = values[EnvPassword]
config.ConfigName = values["BLUECAT_CONFIG_NAME"] config.ConfigName = values[EnvConfigName]
config.DNSView = values["BLUECAT_DNS_VIEW"] config.DNSView = values[EnvDNSView]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,13 +8,15 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"BLUECAT_SERVER_URL", EnvServerURL,
"BLUECAT_USER_NAME", EnvUserName,
"BLUECAT_PASSWORD", EnvPassword,
"BLUECAT_CONFIG_NAME", EnvConfigName,
"BLUECAT_DNS_VIEW"). EnvDNSView).
WithDomain("BLUECAT_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -25,76 +27,76 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "http://localhost", EnvServerURL: "http://localhost",
"BLUECAT_USER_NAME": "A", EnvUserName: "A",
"BLUECAT_PASSWORD": "B", EnvPassword: "B",
"BLUECAT_CONFIG_NAME": "C", EnvConfigName: "C",
"BLUECAT_DNS_VIEW": "D", EnvDNSView: "D",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "", EnvServerURL: "",
"BLUECAT_USER_NAME": "", EnvUserName: "",
"BLUECAT_PASSWORD": "", EnvPassword: "",
"BLUECAT_CONFIG_NAME": "", EnvConfigName: "",
"BLUECAT_DNS_VIEW": "", EnvDNSView: "",
}, },
expected: "bluecat: some credentials information are missing: BLUECAT_SERVER_URL,BLUECAT_USER_NAME,BLUECAT_PASSWORD,BLUECAT_CONFIG_NAME,BLUECAT_DNS_VIEW", 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", desc: "missing server url",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "", EnvServerURL: "",
"BLUECAT_USER_NAME": "A", EnvUserName: "A",
"BLUECAT_PASSWORD": "B", EnvPassword: "B",
"BLUECAT_CONFIG_NAME": "C", EnvConfigName: "C",
"BLUECAT_DNS_VIEW": "D", EnvDNSView: "D",
}, },
expected: "bluecat: some credentials information are missing: BLUECAT_SERVER_URL", expected: "bluecat: some credentials information are missing: BLUECAT_SERVER_URL",
}, },
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "http://localhost", EnvServerURL: "http://localhost",
"BLUECAT_USER_NAME": "", EnvUserName: "",
"BLUECAT_PASSWORD": "B", EnvPassword: "B",
"BLUECAT_CONFIG_NAME": "C", EnvConfigName: "C",
"BLUECAT_DNS_VIEW": "D", EnvDNSView: "D",
}, },
expected: "bluecat: some credentials information are missing: BLUECAT_USER_NAME", expected: "bluecat: some credentials information are missing: BLUECAT_USER_NAME",
}, },
{ {
desc: "missing password", desc: "missing password",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "http://localhost", EnvServerURL: "http://localhost",
"BLUECAT_USER_NAME": "A", EnvUserName: "A",
"BLUECAT_PASSWORD": "", EnvPassword: "",
"BLUECAT_CONFIG_NAME": "C", EnvConfigName: "C",
"BLUECAT_DNS_VIEW": "D", EnvDNSView: "D",
}, },
expected: "bluecat: some credentials information are missing: BLUECAT_PASSWORD", expected: "bluecat: some credentials information are missing: BLUECAT_PASSWORD",
}, },
{ {
desc: "missing config name", desc: "missing config name",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "http://localhost", EnvServerURL: "http://localhost",
"BLUECAT_USER_NAME": "A", EnvUserName: "A",
"BLUECAT_PASSWORD": "B", EnvPassword: "B",
"BLUECAT_CONFIG_NAME": "", EnvConfigName: "",
"BLUECAT_DNS_VIEW": "D", EnvDNSView: "D",
}, },
expected: "bluecat: some credentials information are missing: BLUECAT_CONFIG_NAME", expected: "bluecat: some credentials information are missing: BLUECAT_CONFIG_NAME",
}, },
{ {
desc: "missing DNS view", desc: "missing DNS view",
envVars: map[string]string{ envVars: map[string]string{
"BLUECAT_SERVER_URL": "http://localhost", EnvServerURL: "http://localhost",
"BLUECAT_USER_NAME": "A", EnvUserName: "A",
"BLUECAT_PASSWORD": "B", EnvPassword: "B",
"BLUECAT_CONFIG_NAME": "C", EnvConfigName: "C",
"BLUECAT_DNS_VIEW": "", EnvDNSView: "",
}, },
expected: "bluecat: some credentials information are missing: BLUECAT_DNS_VIEW", expected: "bluecat: some credentials information are missing: BLUECAT_DNS_VIEW",
}, },

View file

@ -12,13 +12,17 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "github.com/go-acme/lego/v3/platform/config/env"
) )
// Environment variables names.
const ( const (
envEndpoint = "CHECKDOMAIN_ENDPOINT" envNamespace = "CHECKDOMAIN_"
envToken = "CHECKDOMAIN_TOKEN"
envTTL = "CHECKDOMAIN_TTL" EnvEndpoint = envNamespace + "ENDPOINT"
envHTTPTimeout = "CHECKDOMAIN_HTTP_TIMEOUT" EnvToken = envNamespace + "TOKEN"
envPropagationTimeout = "CHECKDOMAIN_PROPAGATION_TIMEOUT"
envPollingInterval = "CHECKDOMAIN_POLLING_INTERVAL" EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
) )
const ( const (
@ -39,11 +43,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt(envTTL, defaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(envPropagationTimeout, 5*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 5*time.Minute),
PollingInterval: env.GetOrDefaultSecond(envPollingInterval, 7*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 7*time.Second),
HTTPClient: &http.Client{ 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) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(envToken) values, err := env.Get(EnvToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("checkdomain: %w", err) return nil, fmt.Errorf("checkdomain: %w", err)
} }
config := NewDefaultConfig() 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 { 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 config.Endpoint = endpoint

View file

@ -9,7 +9,12 @@ import (
"github.com/stretchr/testify/require" "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) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -20,7 +25,7 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
envToken: "dummy", EnvToken: "dummy",
}, },
}, },
{ {
@ -31,8 +36,8 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "invalid endpoint", desc: "invalid endpoint",
envVars: map[string]string{ envVars: map[string]string{
envToken: "dummy", EnvToken: "dummy",
envEndpoint: ":", EnvEndpoint: ":",
}, },
expected: `checkdomain: invalid CHECKDOMAIN_ENDPOINT: parse ":": missing protocol scheme`, expected: `checkdomain: invalid CHECKDOMAIN_ENDPOINT: parse ":": missing protocol scheme`,
}, },

View file

@ -12,6 +12,19 @@ import (
"github.com/go-acme/lego/v3/providers/dns/cloudns/internal" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
AuthID string AuthID string
@ -25,11 +38,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("CLOUDNS_PROPAGATION_TIMEOUT", 120*time.Second), TTL: env.GetOrDefaultInt(EnvTTL, 60),
PollingInterval: env.GetOrDefaultSecond("CLOUDNS_POLLING_INTERVAL", 4*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
TTL: env.GetOrDefaultInt("CLOUDNS_TTL", 60), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 4*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// CLOUDNS_AUTH_ID and CLOUDNS_AUTH_PASSWORD. // CLOUDNS_AUTH_ID and CLOUDNS_AUTH_PASSWORD.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("CLOUDNS_AUTH_ID", "CLOUDNS_AUTH_PASSWORD") values, err := env.Get(EnvAuthID, EnvAuthPassword)
if err != nil { if err != nil {
return nil, fmt.Errorf("ClouDNS: %w", err) return nil, fmt.Errorf("ClouDNS: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.AuthID = values["CLOUDNS_AUTH_ID"] config.AuthID = values[EnvAuthID]
config.AuthPassword = values["CLOUDNS_AUTH_PASSWORD"] config.AuthPassword = values[EnvAuthPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"CLOUDNS_AUTH_ID", EnvAuthID,
"CLOUDNS_AUTH_PASSWORD"). EnvAuthPassword).
WithDomain("CLOUDNS_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDNS_AUTH_ID": "123", EnvAuthID: "123",
"CLOUDNS_AUTH_PASSWORD": "456", EnvAuthPassword: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDNS_AUTH_ID": "", EnvAuthID: "",
"CLOUDNS_AUTH_PASSWORD": "", EnvAuthPassword: "",
}, },
expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_ID,CLOUDNS_AUTH_PASSWORD", expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_ID,CLOUDNS_AUTH_PASSWORD",
}, },
{ {
desc: "missing auth-id", desc: "missing auth-id",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDNS_AUTH_ID": "", EnvAuthID: "",
"CLOUDNS_AUTH_PASSWORD": "456", EnvAuthPassword: "456",
}, },
expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_ID", expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_ID",
}, },
{ {
desc: "missing auth-password", desc: "missing auth-password",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDNS_AUTH_ID": "123", EnvAuthID: "123",
"CLOUDNS_AUTH_PASSWORD": "", EnvAuthPassword: "",
}, },
expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_PASSWORD", expected: "ClouDNS: some credentials information are missing: CLOUDNS_AUTH_PASSWORD",
}, },

View file

@ -12,6 +12,19 @@ import (
"github.com/go-acme/lego/v3/providers/dns/cloudxns/internal" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -25,11 +38,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("CLOUDXNS_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("CLOUDXNS_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
TTL: env.GetOrDefaultInt("CLOUDXNS_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// CLOUDXNS_API_KEY and CLOUDXNS_SECRET_KEY. // CLOUDXNS_API_KEY and CLOUDXNS_SECRET_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("CLOUDXNS_API_KEY", "CLOUDXNS_SECRET_KEY") values, err := env.Get(EnvAPIKey, EnvSecretKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("CloudXNS: %w", err) return nil, fmt.Errorf("CloudXNS: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["CLOUDXNS_API_KEY"] config.APIKey = values[EnvAPIKey]
config.SecretKey = values["CLOUDXNS_SECRET_KEY"] config.SecretKey = values[EnvSecretKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"CLOUDXNS_API_KEY", EnvAPIKey,
"CLOUDXNS_SECRET_KEY"). EnvSecretKey).
WithDomain("CLOUDXNS_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDXNS_API_KEY": "123", EnvAPIKey: "123",
"CLOUDXNS_SECRET_KEY": "456", EnvSecretKey: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDXNS_API_KEY": "", EnvAPIKey: "",
"CLOUDXNS_SECRET_KEY": "", EnvSecretKey: "",
}, },
expected: "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY,CLOUDXNS_SECRET_KEY", expected: "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY,CLOUDXNS_SECRET_KEY",
}, },
{ {
desc: "missing API key", desc: "missing API key",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDXNS_API_KEY": "", EnvAPIKey: "",
"CLOUDXNS_SECRET_KEY": "456", EnvSecretKey: "456",
}, },
expected: "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY", expected: "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"CLOUDXNS_API_KEY": "123", EnvAPIKey: "123",
"CLOUDXNS_SECRET_KEY": "", EnvSecretKey: "",
}, },
expected: "CloudXNS: some credentials information are missing: CLOUDXNS_SECRET_KEY", expected: "CloudXNS: some credentials information are missing: CLOUDXNS_SECRET_KEY",
}, },

View file

@ -12,6 +12,21 @@ import (
"github.com/go-acme/lego/v3/providers/dns/conoha/internal" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Region string Region string
@ -27,12 +42,12 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
Region: env.GetOrDefaultString("CONOHA_REGION", "tyo1"), Region: env.GetOrDefaultString(EnvRegion, "tyo1"),
TTL: env.GetOrDefaultInt("CONOHA_TTL", 60), TTL: env.GetOrDefaultInt(EnvTTL, 60),
PropagationTimeout: env.GetOrDefaultSecond("CONOHA_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("CONOHA_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // 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 // Credentials must be passed in the environment variables: CONOHA_TENANT_ID, CONOHA_API_USERNAME, CONOHA_API_PASSWORD
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("conoha: %w", err) return nil, fmt.Errorf("conoha: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.TenantID = values["CONOHA_TENANT_ID"] config.TenantID = values[EnvTenantID]
config.Username = values["CONOHA_API_USERNAME"] config.Username = values[EnvAPIUsername]
config.Password = values["CONOHA_API_PASSWORD"] config.Password = values[EnvAPIPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,11 +8,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"CONOHA_TENANT_ID", EnvTenantID,
"CONOHA_API_USERNAME", EnvAPIUsername,
"CONOHA_API_PASSWORD"). EnvAPIPassword).
WithDomain("CONOHA_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -23,45 +25,45 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "complete credentials, but login failed", desc: "complete credentials, but login failed",
envVars: map[string]string{ envVars: map[string]string{
"CONOHA_TENANT_ID": "tenant_id", EnvTenantID: "tenant_id",
"CONOHA_API_USERNAME": "api_username", EnvAPIUsername: "api_username",
"CONOHA_API_PASSWORD": "api_password", 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}}`, 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", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"CONOHA_TENANT_ID": "", EnvTenantID: "",
"CONOHA_API_USERNAME": "", EnvAPIUsername: "",
"CONOHA_API_PASSWORD": "", EnvAPIPassword: "",
}, },
expected: "conoha: some credentials information are missing: CONOHA_TENANT_ID,CONOHA_API_USERNAME,CONOHA_API_PASSWORD", expected: "conoha: some credentials information are missing: CONOHA_TENANT_ID,CONOHA_API_USERNAME,CONOHA_API_PASSWORD",
}, },
{ {
desc: "missing tenant id", desc: "missing tenant id",
envVars: map[string]string{ envVars: map[string]string{
"CONOHA_TENANT_ID": "", EnvTenantID: "",
"CONOHA_API_USERNAME": "api_username", EnvAPIUsername: "api_username",
"CONOHA_API_PASSWORD": "api_password", EnvAPIPassword: "api_password",
}, },
expected: "conoha: some credentials information are missing: CONOHA_TENANT_ID", expected: "conoha: some credentials information are missing: CONOHA_TENANT_ID",
}, },
{ {
desc: "missing api username", desc: "missing api username",
envVars: map[string]string{ envVars: map[string]string{
"CONOHA_TENANT_ID": "tenant_id", EnvTenantID: "tenant_id",
"CONOHA_API_USERNAME": "", EnvAPIUsername: "",
"CONOHA_API_PASSWORD": "api_password", EnvAPIPassword: "api_password",
}, },
expected: "conoha: some credentials information are missing: CONOHA_API_USERNAME", expected: "conoha: some credentials information are missing: CONOHA_API_USERNAME",
}, },
{ {
desc: "missing api password", desc: "missing api password",
envVars: map[string]string{ envVars: map[string]string{
"CONOHA_TENANT_ID": "tenant_id", EnvTenantID: "tenant_id",
"CONOHA_API_USERNAME": "api_username", EnvAPIUsername: "api_username",
"CONOHA_API_PASSWORD": "", EnvAPIPassword: "",
}, },
expected: "conoha: some credentials information are missing: CONOHA_API_PASSWORD", expected: "conoha: some credentials information are missing: CONOHA_API_PASSWORD",
}, },

View file

@ -12,6 +12,19 @@ import (
"github.com/go-acme/lego/v3/providers/dns/constellix/internal" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -25,11 +38,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("CONSTELLIX_TTL", 300), TTL: env.GetOrDefaultInt(EnvTTL, 300),
PropagationTimeout: env.GetOrDefaultSecond("CONSTELLIX_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("CONSTELLIX_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// CONSTELLIX_API_KEY and CONSTELLIX_SECRET_KEY. // CONSTELLIX_API_KEY and CONSTELLIX_SECRET_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("CONSTELLIX_API_KEY", "CONSTELLIX_SECRET_KEY") values, err := env.Get(EnvAPIKey, EnvSecretKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("constellix: %w", err) return nil, fmt.Errorf("constellix: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["CONSTELLIX_API_KEY"] config.APIKey = values[EnvAPIKey]
config.SecretKey = values["CONSTELLIX_SECRET_KEY"] config.SecretKey = values[EnvSecretKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"CONSTELLIX_API_KEY", EnvAPIKey,
"CONSTELLIX_SECRET_KEY"). EnvSecretKey).
WithDomain("CONSTELLIX_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"CONSTELLIX_API_KEY": "123", EnvAPIKey: "123",
"CONSTELLIX_SECRET_KEY": "456", EnvSecretKey: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"CONSTELLIX_API_KEY": "", EnvAPIKey: "",
"CONSTELLIX_SECRET_KEY": "", EnvSecretKey: "",
}, },
expected: "constellix: some credentials information are missing: CONSTELLIX_API_KEY,CONSTELLIX_SECRET_KEY", expected: "constellix: some credentials information are missing: CONSTELLIX_API_KEY,CONSTELLIX_SECRET_KEY",
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"CONSTELLIX_API_KEY": "", EnvAPIKey: "",
"CONSTELLIX_SECRET_KEY": "api_password", EnvSecretKey: "api_password",
}, },
expected: "constellix: some credentials information are missing: CONSTELLIX_API_KEY", expected: "constellix: some credentials information are missing: CONSTELLIX_API_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"CONSTELLIX_API_KEY": "api_username", EnvAPIKey: "api_username",
"CONSTELLIX_SECRET_KEY": "", EnvSecretKey: "",
}, },
expected: "constellix: some credentials information are missing: CONSTELLIX_SECRET_KEY", expected: "constellix: some credentials information are missing: CONSTELLIX_SECRET_KEY",
}, },

View file

@ -17,6 +17,24 @@ import (
"github.com/gophercloud/gophercloud/openstack/dns/v2/zones" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
PropagationTimeout time.Duration PropagationTimeout time.Duration
@ -28,9 +46,9 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("DESIGNATE_TTL", 10), TTL: env.GetOrDefaultInt(EnvTTL, 10),
PropagationTimeout: env.GetOrDefaultSecond("DESIGNATE_PROPAGATION_TIMEOUT", 10*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 10*time.Minute),
PollingInterval: env.GetOrDefaultSecond("DESIGNATE_POLLING_INTERVAL", 10*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 10*time.Second),
} }
} }
@ -45,7 +63,7 @@ type DNSProvider struct {
// Credentials must be passed in the environment variables: // Credentials must be passed in the environment variables:
// OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, OS_TENANT_NAME, OS_REGION_NAME. // OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, OS_TENANT_NAME, OS_REGION_NAME.
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("designate: %w", err) return nil, fmt.Errorf("designate: %w", err)
} }

View file

@ -10,14 +10,16 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"OS_AUTH_URL", EnvAuthURL,
"OS_USERNAME", EnvUsername,
"OS_PASSWORD", EnvPassword,
"OS_TENANT_NAME", EnvTenantName,
"OS_REGION_NAME", EnvRegionName,
"OS_PROJECT_ID"). EnvProjectID).
WithDomain("DESIGNATE_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
server := getServer() server := getServer()
@ -31,77 +33,77 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": server.URL + "/v2.0/", EnvAuthURL: server.URL + "/v2.0/",
"OS_USERNAME": "B", EnvUsername: "B",
"OS_PASSWORD": "C", EnvPassword: "C",
"OS_REGION_NAME": "D", EnvRegionName: "D",
"OS_TENANT_NAME": "E", EnvTenantName: "E",
"OS_PROJECT_ID": "F", EnvProjectID: "F",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": "", EnvAuthURL: "",
"OS_USERNAME": "", EnvUsername: "",
"OS_PASSWORD": "", EnvPassword: "",
"OS_REGION_NAME": "", EnvRegionName: "",
"OS_TENANT_NAME": "", EnvTenantName: "",
}, },
expected: "designate: some credentials information are missing: OS_AUTH_URL,OS_USERNAME,OS_PASSWORD,OS_TENANT_NAME,OS_REGION_NAME", expected: "designate: some credentials information are missing: OS_AUTH_URL,OS_USERNAME,OS_PASSWORD,OS_TENANT_NAME,OS_REGION_NAME",
}, },
{ {
desc: "missing auth url", desc: "missing auth url",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": "", EnvAuthURL: "",
"OS_USERNAME": "B", EnvUsername: "B",
"OS_PASSWORD": "C", EnvPassword: "C",
"OS_REGION_NAME": "D", EnvRegionName: "D",
"OS_TENANT_NAME": "E", EnvTenantName: "E",
}, },
expected: "designate: some credentials information are missing: OS_AUTH_URL", expected: "designate: some credentials information are missing: OS_AUTH_URL",
}, },
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": server.URL + "/v2.0/", EnvAuthURL: server.URL + "/v2.0/",
"OS_USERNAME": "", EnvUsername: "",
"OS_PASSWORD": "C", EnvPassword: "C",
"OS_REGION_NAME": "D", EnvRegionName: "D",
"OS_TENANT_NAME": "E", EnvTenantName: "E",
}, },
expected: "designate: some credentials information are missing: OS_USERNAME", expected: "designate: some credentials information are missing: OS_USERNAME",
}, },
{ {
desc: "missing password", desc: "missing password",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": server.URL + "/v2.0/", EnvAuthURL: server.URL + "/v2.0/",
"OS_USERNAME": "B", EnvUsername: "B",
"OS_PASSWORD": "", EnvPassword: "",
"OS_REGION_NAME": "D", EnvRegionName: "D",
"OS_TENANT_NAME": "E", EnvTenantName: "E",
}, },
expected: "designate: some credentials information are missing: OS_PASSWORD", expected: "designate: some credentials information are missing: OS_PASSWORD",
}, },
{ {
desc: "missing region name", desc: "missing region name",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": server.URL + "/v2.0/", EnvAuthURL: server.URL + "/v2.0/",
"OS_USERNAME": "B", EnvUsername: "B",
"OS_PASSWORD": "C", EnvPassword: "C",
"OS_REGION_NAME": "", EnvRegionName: "",
"OS_TENANT_NAME": "E", EnvTenantName: "E",
}, },
expected: "designate: some credentials information are missing: OS_REGION_NAME", expected: "designate: some credentials information are missing: OS_REGION_NAME",
}, },
{ {
desc: "missing tenant name", desc: "missing tenant name",
envVars: map[string]string{ envVars: map[string]string{
"OS_AUTH_URL": server.URL + "/v2.0/", EnvAuthURL: server.URL + "/v2.0/",
"OS_USERNAME": "B", EnvUsername: "B",
"OS_PASSWORD": "C", EnvPassword: "C",
"OS_REGION_NAME": "D", EnvRegionName: "D",
"OS_TENANT_NAME": "", EnvTenantName: "",
}, },
expected: "designate: some credentials information are missing: OS_TENANT_NAME", expected: "designate: some credentials information are missing: OS_TENANT_NAME",
}, },

View file

@ -12,6 +12,18 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -26,11 +38,11 @@ type Config struct {
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
BaseURL: defaultBaseURL, BaseURL: defaultBaseURL,
TTL: env.GetOrDefaultInt("DO_TTL", 30), TTL: env.GetOrDefaultInt(EnvTTL, 30),
PropagationTimeout: env.GetOrDefaultSecond("DO_PROPAGATION_TIMEOUT", 60*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Second),
PollingInterval: env.GetOrDefaultSecond("DO_POLLING_INTERVAL", 5*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second),
HTTPClient: &http.Client{ 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: // Ocean. Credentials must be passed in the environment variable:
// DO_AUTH_TOKEN. // DO_AUTH_TOKEN.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DO_AUTH_TOKEN") values, err := env.Get(EnvAuthToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("digitalocean: %w", err) return nil, fmt.Errorf("digitalocean: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.AuthToken = values["DO_AUTH_TOKEN"] config.AuthToken = values[EnvAuthToken]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("DO_AUTH_TOKEN") var envTest = tester.NewEnvTest(EnvAuthToken)
func setupTest() (*DNSProvider, *http.ServeMux, func()) { func setupTest() (*DNSProvider, *http.ServeMux, func()) {
handler := http.NewServeMux() handler := http.NewServeMux()
@ -39,13 +39,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DO_AUTH_TOKEN": "123", EnvAuthToken: "123",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"DO_AUTH_TOKEN": "", EnvAuthToken: "",
}, },
expected: "digitalocean: some credentials information are missing: DO_AUTH_TOKEN", expected: "digitalocean: some credentials information are missing: DO_AUTH_TOKEN",
}, },

View file

@ -15,6 +15,18 @@ import (
"golang.org/x/oauth2" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
AccessToken string AccessToken string
@ -27,9 +39,9 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("DNSIMPLE_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("DNSIMPLE_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DNSIMPLE_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
} }
} }
@ -45,8 +57,8 @@ type DNSProvider struct {
// See: https://developer.dnsimple.com/v2/#authentication // See: https://developer.dnsimple.com/v2/#authentication
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
config := NewDefaultConfig() config := NewDefaultConfig()
config.AccessToken = env.GetOrFile("DNSIMPLE_OAUTH_TOKEN") config.AccessToken = env.GetOrFile(EnvOAuthToken)
config.BaseURL = env.GetOrFile("DNSIMPLE_BASE_URL") config.BaseURL = env.GetOrFile(EnvBaseURL)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -12,11 +12,13 @@ import (
const sandboxURL = "https://api.sandbox.fake.com" const sandboxURL = "https://api.sandbox.fake.com"
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"DNSIMPLE_OAUTH_TOKEN", EnvOAuthToken,
"DNSIMPLE_BASE_URL"). EnvBaseURL).
WithDomain("DNSIMPLE_DOMAIN"). WithDomain(envDomain).
WithLiveTestRequirements("DNSIMPLE_OAUTH_TOKEN", "DNSIMPLE_DOMAIN") WithLiveTestRequirements(EnvOAuthToken, envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -27,20 +29,20 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DNSIMPLE_OAUTH_TOKEN": "my_token", EnvOAuthToken: "my_token",
}, },
}, },
{ {
desc: "success: base url", desc: "success: base url",
envVars: map[string]string{ envVars: map[string]string{
"DNSIMPLE_OAUTH_TOKEN": "my_token", EnvOAuthToken: "my_token",
"DNSIMPLE_BASE_URL": "https://api.dnsimple.test", EnvBaseURL: "https://api.dnsimple.test",
}, },
}, },
{ {
desc: "missing oauth token", desc: "missing oauth token",
envVars: map[string]string{ envVars: map[string]string{
"DNSIMPLE_OAUTH_TOKEN": "", EnvOAuthToken: "",
}, },
expected: "dnsimple: OAuth token is missing", expected: "dnsimple: OAuth token is missing",
}, },
@ -61,7 +63,7 @@ func TestNewDNSProvider(t *testing.T) {
require.NotNil(t, p.config) require.NotNil(t, p.config)
require.NotNil(t, p.client) require.NotNil(t, p.client)
baseURL := os.Getenv("DNSIMPLE_BASE_URL") baseURL := os.Getenv(EnvBaseURL)
if baseURL != "" { if baseURL != "" {
assert.Equal(t, baseURL, p.client.BaseURL) assert.Equal(t, baseURL, p.client.BaseURL)
} }
@ -126,8 +128,8 @@ func TestLivePresent(t *testing.T) {
envTest.RestoreEnv() envTest.RestoreEnv()
if len(os.Getenv("DNSIMPLE_BASE_URL")) == 0 { if len(os.Getenv(EnvBaseURL)) == 0 {
os.Setenv("DNSIMPLE_BASE_URL", sandboxURL) os.Setenv(EnvBaseURL, sandboxURL)
} }
provider, err := NewDNSProvider() provider, err := NewDNSProvider()
@ -144,8 +146,8 @@ func TestLiveCleanUp(t *testing.T) {
envTest.RestoreEnv() envTest.RestoreEnv()
if len(os.Getenv("DNSIMPLE_BASE_URL")) == 0 { if len(os.Getenv(EnvBaseURL)) == 0 {
os.Setenv("DNSIMPLE_BASE_URL", sandboxURL) os.Setenv(EnvBaseURL, sandboxURL)
} }
provider, err := NewDNSProvider() provider, err := NewDNSProvider()

View file

@ -14,6 +14,20 @@ import (
"github.com/go-acme/lego/v3/providers/dns/dnsmadeeasy/internal" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -29,11 +43,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("DNSMADEEASY_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("DNSMADEEASY_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DNSMADEEASY_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond("DNSMADEEASY_HTTP_TIMEOUT", 10*time.Second), Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
Transport: &http.Transport{ Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}, },
@ -52,15 +66,15 @@ type DNSProvider struct {
// Credentials must be passed in the environment variables: // Credentials must be passed in the environment variables:
// DNSMADEEASY_API_KEY and DNSMADEEASY_API_SECRET. // DNSMADEEASY_API_KEY and DNSMADEEASY_API_SECRET.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DNSMADEEASY_API_KEY", "DNSMADEEASY_API_SECRET") values, err := env.Get(EnvAPIKey, EnvAPISecret)
if err != nil { if err != nil {
return nil, fmt.Errorf("dnsmadeeasy: %w", err) return nil, fmt.Errorf("dnsmadeeasy: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Sandbox = env.GetOrDefaultBool("DNSMADEEASY_SANDBOX", false) config.Sandbox = env.GetOrDefaultBool(EnvSandbox, false)
config.APIKey = values["DNSMADEEASY_API_KEY"] config.APIKey = values[EnvAPIKey]
config.APISecret = values["DNSMADEEASY_API_SECRET"] config.APISecret = values[EnvAPISecret]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,13 +8,15 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"DNSMADEEASY_API_KEY", EnvAPIKey,
"DNSMADEEASY_API_SECRET"). EnvAPISecret).
WithDomain("DNSMADEEASY_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
os.Setenv("DNSMADEEASY_SANDBOX", "true") os.Setenv(EnvSandbox, "true")
testCases := []struct { testCases := []struct {
desc string desc string
@ -24,31 +26,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DNSMADEEASY_API_KEY": "123", EnvAPIKey: "123",
"DNSMADEEASY_API_SECRET": "456", EnvAPISecret: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"DNSMADEEASY_API_KEY": "", EnvAPIKey: "",
"DNSMADEEASY_API_SECRET": "", EnvAPISecret: "",
}, },
expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_KEY,DNSMADEEASY_API_SECRET", expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_KEY,DNSMADEEASY_API_SECRET",
}, },
{ {
desc: "missing access key", desc: "missing access key",
envVars: map[string]string{ envVars: map[string]string{
"DNSMADEEASY_API_KEY": "", EnvAPIKey: "",
"DNSMADEEASY_API_SECRET": "456", EnvAPISecret: "456",
}, },
expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_KEY", expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"DNSMADEEASY_API_KEY": "123", EnvAPIKey: "123",
"DNSMADEEASY_API_SECRET": "", EnvAPISecret: "",
}, },
expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_SECRET", expected: "dnsmadeeasy: some credentials information are missing: DNSMADEEASY_API_SECRET",
}, },
@ -76,7 +78,7 @@ func TestNewDNSProvider(t *testing.T) {
} }
func TestNewDNSProviderConfig(t *testing.T) { func TestNewDNSProviderConfig(t *testing.T) {
os.Setenv("DNSMADEEASY_SANDBOX", "true") os.Setenv(EnvSandbox, "true")
testCases := []struct { testCases := []struct {
desc string desc string
@ -130,7 +132,7 @@ func TestLivePresentAndCleanup(t *testing.T) {
t.Skip("skipping live test") t.Skip("skipping live test")
} }
os.Setenv("DNSMADEEASY_SANDBOX", "true") os.Setenv(EnvSandbox, "true")
envTest.RestoreEnv() envTest.RestoreEnv()
provider, err := NewDNSProvider() provider, err := NewDNSProvider()

View file

@ -14,6 +14,18 @@ import (
"github.com/nrdcg/dnspod-go" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
LoginToken string LoginToken string
@ -26,11 +38,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("DNSPOD_TTL", 600), TTL: env.GetOrDefaultInt(EnvTTL, 600),
PropagationTimeout: env.GetOrDefaultSecond("DNSPOD_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DNSPOD_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for dnspod.
// Credentials must be passed in the environment variables: DNSPOD_API_KEY. // Credentials must be passed in the environment variables: DNSPOD_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DNSPOD_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("dnspod: %w", err) return nil, fmt.Errorf("dnspod: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.LoginToken = values["DNSPOD_API_KEY"] config.LoginToken = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,8 +8,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("DNSPOD_API_KEY"). const envDomain = envNamespace + "DOMAIN"
WithDomain("DNSPOD_DOMAIN")
var envTest = tester.NewEnvTest(EnvAPIKey).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -20,13 +22,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DNSPOD_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"DNSPOD_API_KEY": "", EnvAPIKey: "",
}, },
expected: "dnspod: some credentials information are missing: DNSPOD_API_KEY", expected: "dnspod: some credentials information are missing: DNSPOD_API_KEY",
}, },

View file

@ -11,6 +11,18 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Token string Token string
@ -23,11 +35,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("DODE_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DODE_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
SequenceInterval: env.GetOrDefaultSecond("DODE_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout), SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
HTTPClient: &http.Client{ 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 // NewDNSProvider returns a new DNS provider using
// environment variable DODE_TOKEN for adding and removing the DNS record. // environment variable DODE_TOKEN for adding and removing the DNS record.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DODE_TOKEN") values, err := env.Get(EnvToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("do.de: %w", err) return nil, fmt.Errorf("do.de: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Token = values["DODE_TOKEN"] config.Token = values[EnvToken]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,8 +8,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("DODE_TOKEN"). const envDomain = envNamespace + "DOMAIN"
WithDomain("DODE_DOMAIN")
var envTest = tester.NewEnvTest(EnvToken).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -20,13 +22,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DODE_TOKEN": "123", EnvToken: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"DODE_TOKEN": "", EnvToken: "",
}, },
expected: "do.de: some credentials information are missing: DODE_TOKEN", expected: "do.de: some credentials information are missing: DODE_TOKEN",
}, },

View file

@ -13,6 +13,17 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -26,10 +37,10 @@ type Config struct {
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
BaseURL: defaultBaseURL, BaseURL: defaultBaseURL,
PropagationTimeout: env.GetOrDefaultSecond("DREAMHOST_PROPAGATION_TIMEOUT", 60*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Minute),
PollingInterval: env.GetOrDefaultSecond("DREAMHOST_POLLING_INTERVAL", 1*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 1*time.Minute),
HTTPClient: &http.Client{ 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 // NewDNSProvider returns a new DNS provider using
// environment variable DREAMHOST_API_KEY for adding and removing the DNS record. // environment variable DREAMHOST_API_KEY for adding and removing the DNS record.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DREAMHOST_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("dreamhost: %w", err) return nil, fmt.Errorf("dreamhost: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["DREAMHOST_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("DREAMHOST_API_KEY"). const envDomain = envNamespace + "DOMAIN"
WithDomain("DREAMHOST_TEST_DOMAIN")
var envTest = tester.NewEnvTest(EnvAPIKey).
WithDomain(envDomain)
const ( const (
fakeAPIKey = "asdf1234" fakeAPIKey = "asdf1234"
@ -46,13 +48,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DREAMHOST_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "missing API key", desc: "missing API key",
envVars: map[string]string{ envVars: map[string]string{
"DREAMHOST_API_KEY": "", EnvAPIKey: "",
}, },
expected: "dreamhost: some credentials information are missing: DREAMHOST_API_KEY", expected: "dreamhost: some credentials information are missing: DREAMHOST_API_KEY",
}, },

View file

@ -12,6 +12,18 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Token string Token string
@ -24,11 +36,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("DUCKDNS_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DUCKDNS_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
SequenceInterval: env.GetOrDefaultSecond("DUCKDNS_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout), SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
HTTPClient: &http.Client{ 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 // NewDNSProvider returns a new DNS provider using
// environment variable DUCKDNS_TOKEN for adding and removing the DNS record. // environment variable DUCKDNS_TOKEN for adding and removing the DNS record.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("DUCKDNS_TOKEN") values, err := env.Get(EnvToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("duckdns: %w", err) return nil, fmt.Errorf("duckdns: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Token = values["DUCKDNS_TOKEN"] config.Token = values[EnvToken]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -9,8 +9,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("DUCKDNS_TOKEN"). const envDomain = envNamespace + "DOMAIN"
WithDomain("DUCKDNS_DOMAIN")
var envTest = tester.NewEnvTest(EnvToken).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -21,13 +23,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DUCKDNS_TOKEN": "123", EnvToken: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"DUCKDNS_TOKEN": "", EnvToken: "",
}, },
expected: "duckdns: some credentials information are missing: DUCKDNS_TOKEN", expected: "duckdns: some credentials information are missing: DUCKDNS_TOKEN",
}, },

View file

@ -12,6 +12,20 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
CustomerName string CustomerName string
@ -26,11 +40,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("DYN_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("DYN_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("DYN_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// DYN_CUSTOMER_NAME, DYN_USER_NAME and DYN_PASSWORD. // DYN_CUSTOMER_NAME, DYN_USER_NAME and DYN_PASSWORD.
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("dyn: %w", err) return nil, fmt.Errorf("dyn: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.CustomerName = values["DYN_CUSTOMER_NAME"] config.CustomerName = values[EnvCustomerName]
config.UserName = values["DYN_USER_NAME"] config.UserName = values[EnvUserName]
config.Password = values["DYN_PASSWORD"] config.Password = values[EnvPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,11 +8,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"DYN_CUSTOMER_NAME", EnvCustomerName,
"DYN_USER_NAME", EnvUserName,
"DYN_PASSWORD"). EnvPassword).
WithDomain("DYN_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -23,44 +25,44 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"DYN_CUSTOMER_NAME": "A", EnvCustomerName: "A",
"DYN_USER_NAME": "B", EnvUserName: "B",
"DYN_PASSWORD": "C", EnvPassword: "C",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"DYN_CUSTOMER_NAME": "", EnvCustomerName: "",
"DYN_USER_NAME": "", EnvUserName: "",
"DYN_PASSWORD": "", EnvPassword: "",
}, },
expected: "dyn: some credentials information are missing: DYN_CUSTOMER_NAME,DYN_USER_NAME,DYN_PASSWORD", expected: "dyn: some credentials information are missing: DYN_CUSTOMER_NAME,DYN_USER_NAME,DYN_PASSWORD",
}, },
{ {
desc: "missing customer name", desc: "missing customer name",
envVars: map[string]string{ envVars: map[string]string{
"DYN_CUSTOMER_NAME": "", EnvCustomerName: "",
"DYN_USER_NAME": "B", EnvUserName: "B",
"DYN_PASSWORD": "C", EnvPassword: "C",
}, },
expected: "dyn: some credentials information are missing: DYN_CUSTOMER_NAME", expected: "dyn: some credentials information are missing: DYN_CUSTOMER_NAME",
}, },
{ {
desc: "missing password", desc: "missing password",
envVars: map[string]string{ envVars: map[string]string{
"DYN_CUSTOMER_NAME": "A", EnvCustomerName: "A",
"DYN_USER_NAME": "", EnvUserName: "",
"DYN_PASSWORD": "C", EnvPassword: "C",
}, },
expected: "dyn: some credentials information are missing: DYN_USER_NAME", expected: "dyn: some credentials information are missing: DYN_USER_NAME",
}, },
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"DYN_CUSTOMER_NAME": "A", EnvCustomerName: "A",
"DYN_USER_NAME": "B", EnvUserName: "B",
"DYN_PASSWORD": "", EnvPassword: "",
}, },
expected: "dyn: some credentials information are missing: DYN_PASSWORD", expected: "dyn: some credentials information are missing: DYN_PASSWORD",
}, },

View file

@ -123,7 +123,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
NodeName: dns01.UnFqdn(strings.TrimSuffix(fqdn, dns.Fqdn(domain))), NodeName: dns01.UnFqdn(strings.TrimSuffix(fqdn, dns.Fqdn(domain))),
TextData: value, TextData: value,
State: true, State: true,
TTL: 300, TTL: d.config.TTL,
} }
err = d.client.AddNewRecord(rootDomain.ID, record) err = d.client.AddNewRecord(rootDomain.ID, record)

View file

@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "_DOMAIN" const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
EnvAPIKey). EnvAPIKey).

View file

@ -16,6 +16,21 @@ import (
"github.com/miekg/dns" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Endpoint *url.URL Endpoint *url.URL
@ -31,12 +46,12 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("EASYDNS_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
SequenceInterval: env.GetOrDefaultSecond("EASYDNS_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("EASYDNS_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
TTL: env.GetOrDefaultInt("EASYDNS_TTL", dns01.DefaultTTL), SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
HTTPClient: &http.Client{ 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) { func NewDNSProvider() (*DNSProvider, error) {
config := NewDefaultConfig() config := NewDefaultConfig()
endpoint, err := url.Parse(env.GetOrDefaultString("EASYDNS_ENDPOINT", defaultEndpoint)) endpoint, err := url.Parse(env.GetOrDefaultString(EnvEndpoint, defaultEndpoint))
if err != nil { if err != nil {
return nil, fmt.Errorf("easydns: %w", err) return nil, fmt.Errorf("easydns: %w", err)
} }
config.Endpoint = endpoint config.Endpoint = endpoint
values, err := env.Get("EASYDNS_TOKEN", "EASYDNS_KEY") values, err := env.Get(EnvToken, EnvKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("easydns: %w", err) return nil, fmt.Errorf("easydns: %w", err)
} }
config.Token = values["EASYDNS_TOKEN"] config.Token = values[EnvToken]
config.Key = values["EASYDNS_KEY"] config.Key = values[EnvKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -14,11 +14,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"EASYDNS_ENDPOINT", EnvEndpoint,
"EASYDNS_TOKEN", EnvToken,
"EASYDNS_KEY"). EnvKey).
WithDomain("EASYDNS_DOMAIN") WithDomain(envDomain)
func setup() (*DNSProvider, *http.ServeMux, func()) { func setup() (*DNSProvider, *http.ServeMux, func()) {
handler := http.NewServeMux() handler := http.NewServeMux()
@ -51,21 +53,21 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"EASYDNS_TOKEN": "TOKEN", EnvToken: "TOKEN",
"EASYDNS_KEY": "SECRET", EnvKey: "SECRET",
}, },
}, },
{ {
desc: "missing token", desc: "missing token",
envVars: map[string]string{ envVars: map[string]string{
"EASYDNS_KEY": "SECRET", EnvKey: "SECRET",
}, },
expected: "easydns: some credentials information are missing: EASYDNS_TOKEN", expected: "easydns: some credentials information are missing: EASYDNS_TOKEN",
}, },
{ {
desc: "missing key", desc: "missing key",
envVars: map[string]string{ envVars: map[string]string{
"EASYDNS_TOKEN": "TOKEN", EnvToken: "TOKEN",
}, },
expected: "easydns: some credentials information are missing: EASYDNS_KEY", expected: "easydns: some credentials information are missing: EASYDNS_KEY",
}, },

View file

@ -13,6 +13,17 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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. // Config Provider configuration.
type Config struct { type Config struct {
Program string Program string
@ -24,8 +35,8 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("EXEC_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("EXEC_POLLING_INTERVAL", dns01.DefaultPollingInterval), 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 // NewDNSProvider returns a new DNS provider which runs the program in the
// environment variable EXEC_PATH for adding and removing the DNS record. // environment variable EXEC_PATH for adding and removing the DNS record.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("EXEC_PATH") values, err := env.Get(EnvPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("exec: %w", err) return nil, fmt.Errorf("exec: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Program = values["EXEC_PATH"] config.Program = values[EnvPath]
config.Mode = os.Getenv("EXEC_MODE") config.Mode = os.Getenv(EnvMode)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -15,6 +15,20 @@ import (
const defaultBaseURL = "https://api.exoscale.com/dns" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -29,11 +43,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("EXOSCALE_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("EXOSCALE_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("EXOSCALE_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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: // NewDNSProvider Credentials must be passed in the environment variables:
// EXOSCALE_API_KEY, EXOSCALE_API_SECRET, EXOSCALE_ENDPOINT. // EXOSCALE_API_KEY, EXOSCALE_API_SECRET, EXOSCALE_ENDPOINT.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("EXOSCALE_API_KEY", "EXOSCALE_API_SECRET") values, err := env.Get(EnvAPIKey, EnvAPISecret)
if err != nil { if err != nil {
return nil, fmt.Errorf("exoscale: %w", err) return nil, fmt.Errorf("exoscale: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["EXOSCALE_API_KEY"] config.APIKey = values[EnvAPIKey]
config.APISecret = values["EXOSCALE_API_SECRET"] config.APISecret = values[EnvAPISecret]
config.Endpoint = env.GetOrFile("EXOSCALE_ENDPOINT") config.Endpoint = env.GetOrFile(EnvEndpoint)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -9,10 +9,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"EXOSCALE_API_SECRET", EnvAPISecret,
"EXOSCALE_API_KEY"). EnvAPIKey).
WithDomain("EXOSCALE_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -23,31 +25,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"EXOSCALE_API_KEY": "123", EnvAPIKey: "123",
"EXOSCALE_API_SECRET": "456", EnvAPISecret: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"EXOSCALE_API_KEY": "", EnvAPIKey: "",
"EXOSCALE_API_SECRET": "", EnvAPISecret: "",
}, },
expected: "exoscale: some credentials information are missing: EXOSCALE_API_KEY,EXOSCALE_API_SECRET", expected: "exoscale: some credentials information are missing: EXOSCALE_API_KEY,EXOSCALE_API_SECRET",
}, },
{ {
desc: "missing access key", desc: "missing access key",
envVars: map[string]string{ envVars: map[string]string{
"EXOSCALE_API_KEY": "", EnvAPIKey: "",
"EXOSCALE_API_SECRET": "456", EnvAPISecret: "456",
}, },
expected: "exoscale: some credentials information are missing: EXOSCALE_API_KEY", expected: "exoscale: some credentials information are missing: EXOSCALE_API_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"EXOSCALE_API_KEY": "123", EnvAPIKey: "123",
"EXOSCALE_API_SECRET": "", EnvAPISecret: "",
}, },
expected: "exoscale: some credentials information are missing: EXOSCALE_API_SECRET", expected: "exoscale: some credentials information are missing: EXOSCALE_API_SECRET",
}, },

View file

@ -13,6 +13,20 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
edgegrid.Config edgegrid.Config
@ -24,9 +38,9 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("AKAMAI_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PollingInterval: env.GetOrDefaultSecond("AKAMAI_POLLING_INTERVAL", dns01.DefaultPollingInterval), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
TTL: env.GetOrDefaultInt("AKAMAI_TTL", dns01.DefaultTTL), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
} }
} }
@ -38,17 +52,17 @@ type DNSProvider struct {
// NewDNSProvider uses the supplied environment variables to return a DNSProvider instance: // NewDNSProvider uses the supplied environment variables to return a DNSProvider instance:
// AKAMAI_HOST, AKAMAI_CLIENT_TOKEN, AKAMAI_CLIENT_SECRET, AKAMAI_ACCESS_TOKEN // AKAMAI_HOST, AKAMAI_CLIENT_TOKEN, AKAMAI_CLIENT_SECRET, AKAMAI_ACCESS_TOKEN
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("fastdns: %w", err) return nil, fmt.Errorf("fastdns: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Config = edgegrid.Config{ config.Config = edgegrid.Config{
Host: values["AKAMAI_HOST"], Host: values[EnvHost],
ClientToken: values["AKAMAI_CLIENT_TOKEN"], ClientToken: values[EnvClientToken],
ClientSecret: values["AKAMAI_CLIENT_SECRET"], ClientSecret: values[EnvClientSecret],
AccessToken: values["AKAMAI_ACCESS_TOKEN"], AccessToken: values[EnvAccessToken],
MaxBody: 131072, MaxBody: 131072,
} }

View file

@ -9,12 +9,14 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "TEST_DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"AKAMAI_HOST", EnvHost,
"AKAMAI_CLIENT_TOKEN", EnvClientToken,
"AKAMAI_CLIENT_SECRET", EnvClientSecret,
"AKAMAI_ACCESS_TOKEN"). EnvAccessToken).
WithDomain("AKAMAI_TEST_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -25,59 +27,59 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"AKAMAI_HOST": "A", EnvHost: "A",
"AKAMAI_CLIENT_TOKEN": "B", EnvClientToken: "B",
"AKAMAI_CLIENT_SECRET": "C", EnvClientSecret: "C",
"AKAMAI_ACCESS_TOKEN": "D", EnvAccessToken: "D",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"AKAMAI_HOST": "", EnvHost: "",
"AKAMAI_CLIENT_TOKEN": "", EnvClientToken: "",
"AKAMAI_CLIENT_SECRET": "", EnvClientSecret: "",
"AKAMAI_ACCESS_TOKEN": "", EnvAccessToken: "",
}, },
expected: "fastdns: some credentials information are missing: AKAMAI_HOST,AKAMAI_CLIENT_TOKEN,AKAMAI_CLIENT_SECRET,AKAMAI_ACCESS_TOKEN", expected: "fastdns: some credentials information are missing: AKAMAI_HOST,AKAMAI_CLIENT_TOKEN,AKAMAI_CLIENT_SECRET,AKAMAI_ACCESS_TOKEN",
}, },
{ {
desc: "missing host", desc: "missing host",
envVars: map[string]string{ envVars: map[string]string{
"AKAMAI_HOST": "", EnvHost: "",
"AKAMAI_CLIENT_TOKEN": "B", EnvClientToken: "B",
"AKAMAI_CLIENT_SECRET": "C", EnvClientSecret: "C",
"AKAMAI_ACCESS_TOKEN": "D", EnvAccessToken: "D",
}, },
expected: "fastdns: some credentials information are missing: AKAMAI_HOST", expected: "fastdns: some credentials information are missing: AKAMAI_HOST",
}, },
{ {
desc: "missing client token", desc: "missing client token",
envVars: map[string]string{ envVars: map[string]string{
"AKAMAI_HOST": "A", EnvHost: "A",
"AKAMAI_CLIENT_TOKEN": "", EnvClientToken: "",
"AKAMAI_CLIENT_SECRET": "C", EnvClientSecret: "C",
"AKAMAI_ACCESS_TOKEN": "D", EnvAccessToken: "D",
}, },
expected: "fastdns: some credentials information are missing: AKAMAI_CLIENT_TOKEN", expected: "fastdns: some credentials information are missing: AKAMAI_CLIENT_TOKEN",
}, },
{ {
desc: "missing client secret", desc: "missing client secret",
envVars: map[string]string{ envVars: map[string]string{
"AKAMAI_HOST": "A", EnvHost: "A",
"AKAMAI_CLIENT_TOKEN": "B", EnvClientToken: "B",
"AKAMAI_CLIENT_SECRET": "", EnvClientSecret: "",
"AKAMAI_ACCESS_TOKEN": "D", EnvAccessToken: "D",
}, },
expected: "fastdns: some credentials information are missing: AKAMAI_CLIENT_SECRET", expected: "fastdns: some credentials information are missing: AKAMAI_CLIENT_SECRET",
}, },
{ {
desc: "missing access token", desc: "missing access token",
envVars: map[string]string{ envVars: map[string]string{
"AKAMAI_HOST": "A", EnvHost: "A",
"AKAMAI_CLIENT_TOKEN": "B", EnvClientToken: "B",
"AKAMAI_CLIENT_SECRET": "C", EnvClientSecret: "C",
"AKAMAI_ACCESS_TOKEN": "", EnvAccessToken: "",
}, },
expected: "fastdns: some credentials information are missing: AKAMAI_ACCESS_TOKEN", expected: "fastdns: some credentials information are missing: AKAMAI_ACCESS_TOKEN",
}, },

View file

@ -22,6 +22,18 @@ const (
minTTL = 300 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -35,11 +47,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("GANDI_TTL", minTTL), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond("GANDI_PROPAGATION_TIMEOUT", 40*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 40*time.Minute),
PollingInterval: env.GetOrDefaultSecond("GANDI_POLLING_INTERVAL", 60*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 60*time.Second),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for Gandi.
// Credentials must be passed in the environment variable: GANDI_API_KEY. // Credentials must be passed in the environment variable: GANDI_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("GANDI_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("gandi: %w", err) return nil, fmt.Errorf("gandi: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["GANDI_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("GANDI_API_KEY") var envTest = tester.NewEnvTest(EnvAPIKey)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -24,13 +24,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"GANDI_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"GANDI_API_KEY": "", EnvAPIKey: "",
}, },
expected: "gandi: some credentials information are missing: GANDI_API_KEY", expected: "gandi: some credentials information are missing: GANDI_API_KEY",
}, },

View file

@ -21,6 +21,18 @@ const (
minTTL = 300 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 // inProgressInfo contains information about an in-progress challenge
type inProgressInfo struct { type inProgressInfo struct {
fieldName string fieldName string
@ -40,11 +52,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("GANDIV5_TTL", minTTL), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond("GANDIV5_PROPAGATION_TIMEOUT", 20*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 20*time.Minute),
PollingInterval: env.GetOrDefaultSecond("GANDIV5_POLLING_INTERVAL", 20*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 20*time.Second),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for Gandi.
// Credentials must be passed in the environment variable: GANDIV5_API_KEY. // Credentials must be passed in the environment variable: GANDIV5_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("GANDIV5_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("gandi: %w", err) return nil, fmt.Errorf("gandi: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["GANDIV5_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("GANDIV5_API_KEY") var envTest = tester.NewEnvTest(EnvAPIKey)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -24,13 +24,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"GANDIV5_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"GANDIV5_API_KEY": "", EnvAPIKey: "",
}, },
expected: "gandi: some credentials information are missing: GANDIV5_API_KEY", expected: "gandi: some credentials information are missing: GANDIV5_API_KEY",
}, },

View file

@ -26,6 +26,19 @@ const (
changeStatusDone = "done" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Debug bool Debug bool
@ -39,10 +52,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
Debug: env.GetOrDefaultBool("GCE_DEBUG", false), Debug: env.GetOrDefaultBool(EnvDebug, false),
TTL: env.GetOrDefaultInt("GCE_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("GCE_PROPAGATION_TIMEOUT", 180*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 180*time.Second),
PollingInterval: env.GetOrDefaultSecond("GCE_POLLING_INTERVAL", 5*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 // or by specifying the keyfile location: GCE_SERVICE_ACCOUNT_FILE
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
// Use a service account file if specified via environment variable. // 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)) return NewDNSProviderServiceAccountKey([]byte(saKey))
} }
// Use default credentials. // Use default credentials.
project := env.GetOrDefaultString("GCE_PROJECT", autodetectProjectID()) project := env.GetOrDefaultString(EnvProject, autodetectProjectID())
return NewDNSProviderCredentials(project) 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 // If GCE_PROJECT is non-empty it overrides the project in the service
// account file. // account file.
project := env.GetOrDefaultString("GCE_PROJECT", "") project := env.GetOrDefaultString(EnvProject, "")
if project == "" { if project == "" {
// read project id from service account file // read project id from service account file
var datJSON struct { var datJSON struct {

View file

@ -16,13 +16,22 @@ import (
"google.golang.org/api/dns/v1" "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( var envTest = tester.NewEnvTest(
"GCE_PROJECT", EnvProject,
"GCE_SERVICE_ACCOUNT_FILE", envServiceAccountFile,
"GOOGLE_APPLICATION_CREDENTIALS", envGoogleApplicationCredentials,
"GCE_METADATA_HOST", envMetadataHost,
"GCE_SERVICE_ACCOUNT"). EnvServiceAccount).
WithDomain("GCE_DOMAIN"). WithDomain(envDomain).
WithLiveTestExtra(func() bool { WithLiveTestExtra(func() bool {
_, err := google.DefaultClient(context.Background(), dns.NdevClouddnsReadwriteScope) _, err := google.DefaultClient(context.Background(), dns.NdevClouddnsReadwriteScope)
return err == nil return err == nil
@ -37,36 +46,36 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "invalid credentials", desc: "invalid credentials",
envVars: map[string]string{ envVars: map[string]string{
"GCE_PROJECT": "123", EnvProject: "123",
"GCE_SERVICE_ACCOUNT_FILE": "", envServiceAccountFile: "",
// as Travis run on GCE, we have to alter env // as Travis run on GCE, we have to alter env
"GOOGLE_APPLICATION_CREDENTIALS": "not-a-secret-file", envGoogleApplicationCredentials: "not-a-secret-file",
"GCE_METADATA_HOST": "http://lego.wtf", // defined here to avoid the client cache. 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", 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", desc: "missing project",
envVars: map[string]string{ envVars: map[string]string{
"GCE_PROJECT": "", EnvProject: "",
"GCE_SERVICE_ACCOUNT_FILE": "", envServiceAccountFile: "",
// as Travis run on GCE, we have to alter env // 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", expected: "googlecloud: project name missing",
}, },
{ {
desc: "success key file", desc: "success key file",
envVars: map[string]string{ envVars: map[string]string{
"GCE_PROJECT": "", EnvProject: "",
"GCE_SERVICE_ACCOUNT_FILE": "fixtures/gce_account_service_file.json", envServiceAccountFile: "fixtures/gce_account_service_file.json",
}, },
}, },
{ {
desc: "success key", desc: "success key",
envVars: map[string]string{ envVars: map[string]string{
"GCE_PROJECT": "", EnvProject: "",
"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"}`, 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() envTest.RestoreEnv()
provider, err := NewDNSProviderCredentials(envTest.GetValue("GCE_PROJECT")) provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
require.NoError(t, err) require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==") err = provider.Present(envTest.GetDomain(), "", "123d==")
@ -395,7 +404,7 @@ func TestLivePresentMultiple(t *testing.T) {
envTest.RestoreEnv() envTest.RestoreEnv()
provider, err := NewDNSProviderCredentials(envTest.GetValue("GCE_PROJECT")) provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
require.NoError(t, err) require.NoError(t, err)
// Check that we're able to create multiple entries // Check that we're able to create multiple entries
@ -413,7 +422,7 @@ func TestLiveCleanUp(t *testing.T) {
envTest.RestoreEnv() envTest.RestoreEnv()
provider, err := NewDNSProviderCredentials(envTest.GetValue("GCE_PROJECT")) provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
require.NoError(t, err) require.NoError(t, err)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View file

@ -19,6 +19,19 @@ const (
minTTL = 60 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIUser string APIUser string
@ -32,11 +45,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("GLESYS_TTL", minTTL), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond("GLESYS_PROPAGATION_TIMEOUT", 20*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 20*time.Minute),
PollingInterval: env.GetOrDefaultSecond("GLESYS_POLLING_INTERVAL", 20*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 20*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// GLESYS_API_USER and GLESYS_API_KEY. // GLESYS_API_USER and GLESYS_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("GLESYS_API_USER", "GLESYS_API_KEY") values, err := env.Get(EnvAPIUser, EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("glesys: %w", err) return nil, fmt.Errorf("glesys: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIUser = values["GLESYS_API_USER"] config.APIUser = values[EnvAPIUser]
config.APIKey = values["GLESYS_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -7,10 +7,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"GLESYS_API_USER", EnvAPIUser,
"GLESYS_API_KEY"). EnvAPIKey).
WithDomain("GLESYS_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -21,31 +23,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"GLESYS_API_USER": "A", EnvAPIUser: "A",
"GLESYS_API_KEY": "B", EnvAPIKey: "B",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"GLESYS_API_USER": "", EnvAPIUser: "",
"GLESYS_API_KEY": "", EnvAPIKey: "",
}, },
expected: "glesys: some credentials information are missing: GLESYS_API_USER,GLESYS_API_KEY", expected: "glesys: some credentials information are missing: GLESYS_API_USER,GLESYS_API_KEY",
}, },
{ {
desc: "missing api user", desc: "missing api user",
envVars: map[string]string{ envVars: map[string]string{
"GLESYS_API_USER": "", EnvAPIUser: "",
"GLESYS_API_KEY": "B", EnvAPIKey: "B",
}, },
expected: "glesys: some credentials information are missing: GLESYS_API_USER", expected: "glesys: some credentials information are missing: GLESYS_API_USER",
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"GLESYS_API_USER": "A", EnvAPIUser: "A",
"GLESYS_API_KEY": "", EnvAPIKey: "",
}, },
expected: "glesys: some credentials information are missing: GLESYS_API_KEY", expected: "glesys: some credentials information are missing: GLESYS_API_KEY",
}, },

View file

@ -18,6 +18,20 @@ const (
minTTL = 600 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -32,12 +46,12 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("GODADDY_TTL", minTTL), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond("GODADDY_PROPAGATION_TIMEOUT", 120*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
PollingInterval: env.GetOrDefaultSecond("GODADDY_POLLING_INTERVAL", 2*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
SequenceInterval: env.GetOrDefaultSecond("GODADDY_SEQUENCE_INTERVAL", dns01.DefaultPropagationTimeout), SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// GODADDY_API_KEY and GODADDY_API_SECRET. // GODADDY_API_KEY and GODADDY_API_SECRET.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("GODADDY_API_KEY", "GODADDY_API_SECRET") values, err := env.Get(EnvAPIKey, EnvAPISecret)
if err != nil { if err != nil {
return nil, fmt.Errorf("godaddy: %w", err) return nil, fmt.Errorf("godaddy: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["GODADDY_API_KEY"] config.APIKey = values[EnvAPIKey]
config.APISecret = values["GODADDY_API_SECRET"] config.APISecret = values[EnvAPISecret]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -7,10 +7,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"GODADDY_API_KEY", EnvAPIKey,
"GODADDY_API_SECRET"). EnvAPISecret).
WithDomain("GODADDY_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -21,31 +23,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"GODADDY_API_KEY": "123", EnvAPIKey: "123",
"GODADDY_API_SECRET": "456", EnvAPISecret: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"GODADDY_API_KEY": "", EnvAPIKey: "",
"GODADDY_API_SECRET": "", EnvAPISecret: "",
}, },
expected: "godaddy: some credentials information are missing: GODADDY_API_KEY,GODADDY_API_SECRET", expected: "godaddy: some credentials information are missing: GODADDY_API_KEY,GODADDY_API_SECRET",
}, },
{ {
desc: "missing access key", desc: "missing access key",
envVars: map[string]string{ envVars: map[string]string{
"GODADDY_API_KEY": "", EnvAPIKey: "",
"GODADDY_API_SECRET": "456", EnvAPISecret: "456",
}, },
expected: "godaddy: some credentials information are missing: GODADDY_API_KEY", expected: "godaddy: some credentials information are missing: GODADDY_API_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"GODADDY_API_KEY": "123", EnvAPIKey: "123",
"GODADDY_API_SECRET": "", EnvAPISecret: "",
}, },
expected: "godaddy: some credentials information are missing: GODADDY_API_SECRET", expected: "godaddy: some credentials information are missing: GODADDY_API_SECRET",
}, },

View file

@ -12,6 +12,19 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -25,11 +38,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("HOSTINGDE_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("HOSTINGDE_PROPAGATION_TIMEOUT", 2*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond("HOSTINGDE_POLLING_INTERVAL", 2*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// HOSTINGDE_ZONE_NAME and HOSTINGDE_API_KEY // HOSTINGDE_ZONE_NAME and HOSTINGDE_API_KEY
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("HOSTINGDE_API_KEY", "HOSTINGDE_ZONE_NAME") values, err := env.Get(EnvAPIKey, EnvZoneName)
if err != nil { if err != nil {
return nil, fmt.Errorf("hostingde: %w", err) return nil, fmt.Errorf("hostingde: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["HOSTINGDE_API_KEY"] config.APIKey = values[EnvAPIKey]
config.ZoneName = values["HOSTINGDE_ZONE_NAME"] config.ZoneName = values[EnvZoneName]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"HOSTINGDE_API_KEY", EnvAPIKey,
"HOSTINGDE_ZONE_NAME"). EnvZoneName).
WithDomain("HOSTINGDE_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"HOSTINGDE_API_KEY": "123", EnvAPIKey: "123",
"HOSTINGDE_ZONE_NAME": "456", EnvZoneName: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"HOSTINGDE_API_KEY": "", EnvAPIKey: "",
"HOSTINGDE_ZONE_NAME": "", EnvZoneName: "",
}, },
expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY,HOSTINGDE_ZONE_NAME", expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY,HOSTINGDE_ZONE_NAME",
}, },
{ {
desc: "missing access key", desc: "missing access key",
envVars: map[string]string{ envVars: map[string]string{
"HOSTINGDE_API_KEY": "", EnvAPIKey: "",
"HOSTINGDE_ZONE_NAME": "456", EnvZoneName: "456",
}, },
expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY", expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY",
}, },
{ {
desc: "missing zone name", desc: "missing zone name",
envVars: map[string]string{ envVars: map[string]string{
"HOSTINGDE_API_KEY": "123", EnvAPIKey: "123",
"HOSTINGDE_ZONE_NAME": "", EnvZoneName: "",
}, },
expected: "hostingde: some credentials information are missing: HOSTINGDE_ZONE_NAME", expected: "hostingde: some credentials information are missing: HOSTINGDE_ZONE_NAME",
}, },

View file

@ -16,6 +16,20 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 { type message struct {
FQDN string `json:"fqdn"` FQDN string `json:"fqdn"`
Value string `json:"value"` Value string `json:"value"`
@ -41,10 +55,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("HTTPREQ_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("HTTPREQ_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("HTTPREQ_ENDPOINT") values, err := env.Get(EnvEndpoint)
if err != nil { if err != nil {
return nil, fmt.Errorf("httpreq: %w", err) return nil, fmt.Errorf("httpreq: %w", err)
} }
endpoint, err := url.Parse(values["HTTPREQ_ENDPOINT"]) endpoint, err := url.Parse(values[EnvEndpoint])
if err != nil { if err != nil {
return nil, fmt.Errorf("httpreq: %w", err) return nil, fmt.Errorf("httpreq: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Mode = env.GetOrFile("HTTPREQ_MODE") config.Mode = env.GetOrFile(EnvMode)
config.Username = env.GetOrFile("HTTPREQ_USERNAME") config.Username = env.GetOrFile(EnvUsername)
config.Password = env.GetOrFile("HTTPREQ_PASSWORD") config.Password = env.GetOrFile(EnvPassword)
config.Endpoint = endpoint config.Endpoint = endpoint
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require" "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) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -24,20 +24,20 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"HTTPREQ_ENDPOINT": "http://localhost:8090", EnvEndpoint: "http://localhost:8090",
}, },
}, },
{ {
desc: "invalid URL", desc: "invalid URL",
envVars: map[string]string{ envVars: map[string]string{
"HTTPREQ_ENDPOINT": ":", EnvEndpoint: ":",
}, },
expected: `httpreq: parse ":": missing protocol scheme`, expected: `httpreq: parse ":": missing protocol scheme`,
}, },
{ {
desc: "missing endpoint", desc: "missing endpoint",
envVars: map[string]string{ envVars: map[string]string{
"HTTPREQ_ENDPOINT": "", EnvEndpoint: "",
}, },
expected: "httpreq: some credentials information are missing: HTTPREQ_ENDPOINT", expected: "httpreq: some credentials information are missing: HTTPREQ_ENDPOINT",
}, },

View file

@ -14,6 +14,19 @@ import (
"github.com/iij/doapi/protocol" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
AccessKey string AccessKey string
@ -27,9 +40,9 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("IIJ_TTL", 300), TTL: env.GetOrDefaultInt(EnvTTL, 300),
PropagationTimeout: env.GetOrDefaultSecond("IIJ_PROPAGATION_TIMEOUT", 2*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond("IIJ_POLLING_INTERVAL", 4*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 4*time.Second),
} }
} }
@ -41,15 +54,15 @@ type DNSProvider struct {
// NewDNSProvider returns a DNSProvider instance configured for IIJ DO // NewDNSProvider returns a DNSProvider instance configured for IIJ DO
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("iij: %w", err) return nil, fmt.Errorf("iij: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.AccessKey = values["IIJ_API_ACCESS_KEY"] config.AccessKey = values[EnvAPIAccessKey]
config.SecretKey = values["IIJ_API_SECRET_KEY"] config.SecretKey = values[EnvAPISecretKey]
config.DoServiceCode = values["IIJ_DO_SERVICE_CODE"] config.DoServiceCode = values[EnvDoServiceCode]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,11 +8,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "TESTDOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"IIJ_API_ACCESS_KEY", EnvAPIAccessKey,
"IIJ_API_SECRET_KEY", EnvAPISecretKey,
"IIJ_DO_SERVICE_CODE"). EnvDoServiceCode).
WithDomain("IIJ_API_TESTDOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -23,44 +25,44 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"IIJ_API_ACCESS_KEY": "A", EnvAPIAccessKey: "A",
"IIJ_API_SECRET_KEY": "B", EnvAPISecretKey: "B",
"IIJ_DO_SERVICE_CODE": "C", EnvDoServiceCode: "C",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"IIJ_API_ACCESS_KEY": "", EnvAPIAccessKey: "",
"IIJ_API_SECRET_KEY": "", EnvAPISecretKey: "",
"IIJ_DO_SERVICE_CODE": "", EnvDoServiceCode: "",
}, },
expected: "iij: some credentials information are missing: IIJ_API_ACCESS_KEY,IIJ_API_SECRET_KEY,IIJ_DO_SERVICE_CODE", expected: "iij: some credentials information are missing: IIJ_API_ACCESS_KEY,IIJ_API_SECRET_KEY,IIJ_DO_SERVICE_CODE",
}, },
{ {
desc: "missing api access key", desc: "missing api access key",
envVars: map[string]string{ envVars: map[string]string{
"IIJ_API_ACCESS_KEY": "", EnvAPIAccessKey: "",
"IIJ_API_SECRET_KEY": "B", EnvAPISecretKey: "B",
"IIJ_DO_SERVICE_CODE": "C", EnvDoServiceCode: "C",
}, },
expected: "iij: some credentials information are missing: IIJ_API_ACCESS_KEY", expected: "iij: some credentials information are missing: IIJ_API_ACCESS_KEY",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"IIJ_API_ACCESS_KEY": "A", EnvAPIAccessKey: "A",
"IIJ_API_SECRET_KEY": "", EnvAPISecretKey: "",
"IIJ_DO_SERVICE_CODE": "C", EnvDoServiceCode: "C",
}, },
expected: "iij: some credentials information are missing: IIJ_API_SECRET_KEY", expected: "iij: some credentials information are missing: IIJ_API_SECRET_KEY",
}, },
{ {
desc: "missing do service code", desc: "missing do service code",
envVars: map[string]string{ envVars: map[string]string{
"IIJ_API_ACCESS_KEY": "A", EnvAPIAccessKey: "A",
"IIJ_API_SECRET_KEY": "B", EnvAPISecretKey: "B",
"IIJ_DO_SERVICE_CODE": "", EnvDoServiceCode: "",
}, },
expected: "iij: some credentials information are missing: IIJ_DO_SERVICE_CODE", expected: "iij: some credentials information are missing: IIJ_DO_SERVICE_CODE",
}, },

View file

@ -12,6 +12,19 @@ import (
"github.com/nrdcg/goinwx" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Username string Username string
@ -25,10 +38,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("INWX_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), TTL: env.GetOrDefaultInt(EnvTTL, 300),
PollingInterval: env.GetOrDefaultSecond("INWX_POLLING_INTERVAL", dns01.DefaultPollingInterval), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
TTL: env.GetOrDefaultInt("INWX_TTL", 300), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
Sandbox: env.GetOrDefaultBool("INWX_SANDBOX", false), Sandbox: env.GetOrDefaultBool(EnvSandbox, false),
} }
} }
@ -42,14 +55,14 @@ type DNSProvider struct {
// Credentials must be passed in the environment variables: // Credentials must be passed in the environment variables:
// INWX_USERNAME and INWX_PASSWORD. // INWX_USERNAME and INWX_PASSWORD.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("INWX_USERNAME", "INWX_PASSWORD") values, err := env.Get(EnvUsername, EnvPassword)
if err != nil { if err != nil {
return nil, fmt.Errorf("inwx: %w", err) return nil, fmt.Errorf("inwx: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Username = values["INWX_USERNAME"] config.Username = values[EnvUsername]
config.Password = values["INWX_PASSWORD"] config.Password = values[EnvPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -7,13 +7,15 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"INWX_USERNAME", EnvUsername,
"INWX_PASSWORD", EnvPassword,
"INWX_SANDBOX", EnvSandbox,
"INWX_TTL"). EnvTTL).
WithDomain("INWX_DOMAIN"). WithDomain(envDomain).
WithLiveTestRequirements("INWX_USERNAME", "INWX_PASSWORD", "INWX_DOMAIN") WithLiveTestRequirements(EnvUsername, EnvPassword, envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -24,31 +26,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"INWX_USERNAME": "123", EnvUsername: "123",
"INWX_PASSWORD": "456", EnvPassword: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"INWX_USERNAME": "", EnvUsername: "",
"INWX_PASSWORD": "", EnvPassword: "",
}, },
expected: "inwx: some credentials information are missing: INWX_USERNAME,INWX_PASSWORD", expected: "inwx: some credentials information are missing: INWX_USERNAME,INWX_PASSWORD",
}, },
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"INWX_USERNAME": "", EnvUsername: "",
"INWX_PASSWORD": "456", EnvPassword: "456",
}, },
expected: "inwx: some credentials information are missing: INWX_USERNAME", expected: "inwx: some credentials information are missing: INWX_USERNAME",
}, },
{ {
desc: "missing password", desc: "missing password",
envVars: map[string]string{ envVars: map[string]string{
"INWX_USERNAME": "123", EnvUsername: "123",
"INWX_PASSWORD": "", EnvPassword: "",
}, },
expected: "inwx: some credentials information are missing: INWX_PASSWORD", expected: "inwx: some credentials information are missing: INWX_PASSWORD",
}, },
@ -120,8 +122,8 @@ func TestLivePresentAndCleanup(t *testing.T) {
envTest.RestoreEnv() envTest.RestoreEnv()
envTest.Apply(map[string]string{ envTest.Apply(map[string]string{
"INWX_SANDBOX": "true", EnvSandbox: "true",
"INWX_TTL": "3600", // In sandbox mode, the minimum allowed TTL is 3600 EnvTTL: "3600", // In sandbox mode, the minimum allowed TTL is 3600
}) })
defer envTest.RestoreEnv() defer envTest.RestoreEnv()

View file

@ -13,6 +13,21 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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. // Config is used to configure the creation of the DNSProvider.
type Config struct { type Config struct {
Debug bool Debug bool
@ -31,12 +46,12 @@ type Config struct {
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
BaseURL: defaultBaseURL, BaseURL: defaultBaseURL,
Debug: env.GetOrDefaultBool("JOKER_DEBUG", false), Debug: env.GetOrDefaultBool(EnvDebug, false),
TTL: env.GetOrDefaultInt("JOKER_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("JOKER_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("JOKER_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for Joker DMAPI.
// Credentials must be passed in the environment variable JOKER_API_KEY. // Credentials must be passed in the environment variable JOKER_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("JOKER_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
var errU error var errU error
values, errU = env.Get("JOKER_USERNAME", "JOKER_PASSWORD") values, errU = env.Get(EnvUsername, EnvPassword)
if errU != nil { if errU != nil {
return nil, fmt.Errorf("joker: %v or %v", errU, err) return nil, fmt.Errorf("joker: %v or %v", errU, err)
} }
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["JOKER_API_KEY"] config.APIKey = values[EnvAPIKey]
config.Username = values["JOKER_USERNAME"] config.Username = values[EnvUsername]
config.Password = values["JOKER_PASSWORD"] config.Password = values[EnvPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -9,8 +9,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("JOKER_API_KEY", "JOKER_USERNAME", "JOKER_PASSWORD"). const envDomain = envNamespace + "DOMAIN"
WithDomain("JOKER_DOMAIN")
var envTest = tester.NewEnvTest(EnvAPIKey, EnvUsername, EnvPassword).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -21,40 +23,40 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success API key", desc: "success API key",
envVars: map[string]string{ envVars: map[string]string{
"JOKER_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "success username password", desc: "success username password",
envVars: map[string]string{ envVars: map[string]string{
"JOKER_USERNAME": "123", EnvUsername: "123",
"JOKER_PASSWORD": "123", EnvPassword: "123",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"JOKER_API_KEY": "", EnvAPIKey: "",
"JOKER_USERNAME": "", EnvUsername: "",
"JOKER_PASSWORD": "", EnvPassword: "",
}, },
expected: "joker: some credentials information are missing: JOKER_USERNAME,JOKER_PASSWORD or some credentials information are missing: JOKER_API_KEY", expected: "joker: some credentials information are missing: JOKER_USERNAME,JOKER_PASSWORD or some credentials information are missing: JOKER_API_KEY",
}, },
{ {
desc: "missing password", desc: "missing password",
envVars: map[string]string{ envVars: map[string]string{
"JOKER_API_KEY": "", EnvAPIKey: "",
"JOKER_USERNAME": "123", EnvUsername: "123",
"JOKER_PASSWORD": "", EnvPassword: "",
}, },
expected: "joker: some credentials information are missing: JOKER_PASSWORD or some credentials information are missing: JOKER_API_KEY", expected: "joker: some credentials information are missing: JOKER_PASSWORD or some credentials information are missing: JOKER_API_KEY",
}, },
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"JOKER_API_KEY": "", EnvAPIKey: "",
"JOKER_USERNAME": "", EnvUsername: "",
"JOKER_PASSWORD": "123", EnvPassword: "123",
}, },
expected: "joker: some credentials information are missing: JOKER_USERNAME or some credentials information are missing: JOKER_API_KEY", expected: "joker: some credentials information are missing: JOKER_USERNAME or some credentials information are missing: JOKER_API_KEY",
}, },

View file

@ -20,6 +20,17 @@ const (
maxRetries = 5 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. // 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). // It controls the logic for retrying recoverable request errors (e.g. when rate limits are exceeded).
type customRetryer struct { type customRetryer struct {
@ -52,10 +63,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
DNSZone: env.GetOrFile("DNS_ZONE"), DNSZone: env.GetOrFile(EnvDNSZone),
PropagationTimeout: env.GetOrDefaultSecond("LIGHTSAIL_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("LIGHTSAIL_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
Region: env.GetOrDefaultString("LIGHTSAIL_REGION", "us-east-1"), Region: env.GetOrDefaultString(EnvRegion, "us-east-1"),
} }
} }

View file

@ -13,13 +13,22 @@ import (
"github.com/stretchr/testify/require" "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( var envTest = tester.NewEnvTest(
"AWS_ACCESS_KEY_ID", envAwsAccessKeyID,
"AWS_SECRET_ACCESS_KEY", envAwsSecretAccessKey,
"AWS_REGION", envAwsRegion,
"AWS_HOSTED_ZONE_ID"). envAwsHostedZoneID).
WithDomain("DNS_ZONE"). WithDomain(EnvDNSZone).
WithLiveTestRequirements("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "DNS_ZONE") WithLiveTestRequirements(envAwsAccessKeyID, envAwsSecretAccessKey, EnvDNSZone)
func makeProvider(ts *httptest.Server) (*DNSProvider, error) { func makeProvider(ts *httptest.Server) (*DNSProvider, error) {
config := &aws.Config{ config := &aws.Config{
@ -44,9 +53,9 @@ func TestCredentialsFromEnv(t *testing.T) {
defer envTest.RestoreEnv() defer envTest.RestoreEnv()
envTest.ClearEnv() envTest.ClearEnv()
os.Setenv("AWS_ACCESS_KEY_ID", "123") os.Setenv(envAwsAccessKeyID, "123")
os.Setenv("AWS_SECRET_ACCESS_KEY", "123") os.Setenv(envAwsSecretAccessKey, "123")
os.Setenv("AWS_REGION", "us-east-1") os.Setenv(envAwsRegion, "us-east-1")
config := &aws.Config{ config := &aws.Config{
CredentialsChainVerboseErrors: aws.Bool(true), CredentialsChainVerboseErrors: aws.Bool(true),

View file

@ -18,6 +18,16 @@ const (
dnsUpdateFudgeSecs = 120 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -28,8 +38,8 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
} }
} }
@ -47,13 +57,13 @@ type DNSProvider struct {
// NewDNSProvider returns a DNSProvider instance configured for Linode. // NewDNSProvider returns a DNSProvider instance configured for Linode.
// Credentials must be passed in the environment variable: LINODE_API_KEY. // Credentials must be passed in the environment variable: LINODE_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("LINODE_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("linode: %w", err) return nil, fmt.Errorf("linode: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["LINODE_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -29,7 +29,7 @@ type (
MockResponseMap map[string]MockResponse MockResponseMap map[string]MockResponse
) )
var envTest = tester.NewEnvTest("LINODE_API_KEY") var envTest = tester.NewEnvTest(EnvAPIKey)
func newMockServer(responses MockResponseMap) *httptest.Server { func newMockServer(responses MockResponseMap) *httptest.Server {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -77,13 +77,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"LINODE_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"LINODE_API_KEY": "", EnvAPIKey: "",
}, },
expected: "linode: some credentials information are missing: LINODE_API_KEY", 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) { func TestDNSProvider_Present(t *testing.T) {
defer envTest.RestoreEnv() defer envTest.RestoreEnv()
os.Setenv("LINODE_API_KEY", "testing") os.Setenv(EnvAPIKey, "testing")
p, err := NewDNSProvider() p, err := NewDNSProvider()
require.NoError(t, err) require.NoError(t, err)
@ -234,7 +234,7 @@ func TestDNSProvider_Present(t *testing.T) {
func TestDNSProvider_CleanUp(t *testing.T) { func TestDNSProvider_CleanUp(t *testing.T) {
defer envTest.RestoreEnv() defer envTest.RestoreEnv()
os.Setenv("LINODE_API_KEY", "testing") os.Setenv(EnvAPIKey, "testing")
p, err := NewDNSProvider() p, err := NewDNSProvider()
require.NoError(t, err) require.NoError(t, err)

View file

@ -22,6 +22,18 @@ const (
dnsUpdateFudgeSecs = 120 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Token string Token string
@ -34,10 +46,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("LINODE_PROPAGATION_TIMEOUT", 0), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 0),
TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
HTTPTimeout: env.GetOrDefaultSecond("LINODE_HTTP_TIMEOUT", 0), HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 0),
} }
} }
@ -55,13 +67,13 @@ type DNSProvider struct {
// NewDNSProvider returns a DNSProvider instance configured for Linode. // NewDNSProvider returns a DNSProvider instance configured for Linode.
// Credentials must be passed in the environment variable: LINODE_TOKEN. // Credentials must be passed in the environment variable: LINODE_TOKEN.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("LINODE_TOKEN") values, err := env.Get(EnvToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("linodev4: %w", err) return nil, fmt.Errorf("linodev4: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Token = values["LINODE_TOKEN"] config.Token = values[EnvToken]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -15,11 +15,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
type ( type MockResponseMap map[string]interface{}
MockResponseMap map[string]interface{}
)
var envTest = tester.NewEnvTest("LINODE_TOKEN") var envTest = tester.NewEnvTest(EnvToken)
func newMockServer(responses MockResponseMap) *httptest.Server { func newMockServer(responses MockResponseMap) *httptest.Server {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -68,13 +66,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"LINODE_TOKEN": "123", EnvToken: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"LINODE_TOKEN": "", EnvToken: "",
}, },
expected: "linodev4: some credentials information are missing: LINODE_TOKEN", expected: "linodev4: some credentials information are missing: LINODE_TOKEN",
}, },
@ -138,7 +136,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
func TestDNSProvider_Present(t *testing.T) { func TestDNSProvider_Present(t *testing.T) {
defer envTest.RestoreEnv() defer envTest.RestoreEnv()
os.Setenv("LINODE_TOKEN", "testing") os.Setenv(EnvToken, "testing")
p, err := NewDNSProvider() p, err := NewDNSProvider()
require.NoError(t, err) require.NoError(t, err)
@ -227,7 +225,7 @@ func TestDNSProvider_Present(t *testing.T) {
func TestDNSProvider_CleanUp(t *testing.T) { func TestDNSProvider_CleanUp(t *testing.T) {
defer envTest.RestoreEnv() defer envTest.RestoreEnv()
os.Setenv("LINODE_TOKEN", "testing") os.Setenv(EnvToken, "testing")
p, err := NewDNSProvider() p, err := NewDNSProvider()
require.NoError(t, err) require.NoError(t, err)

View file

@ -16,6 +16,21 @@ import (
const defaultBaseURL = "https://api.stormondemand.com" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -32,10 +47,10 @@ type Config struct {
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
config := &Config{ config := &Config{
BaseURL: defaultBaseURL, BaseURL: defaultBaseURL,
TTL: env.GetOrDefaultInt("LIQUID_WEB_TTL", 300), TTL: env.GetOrDefaultInt(EnvTTL, 300),
PollingInterval: env.GetOrDefaultSecond("LIQUID_WEB_POLLING_INTERVAL", 2*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PropagationTimeout: env.GetOrDefaultSecond("LIQUID_WEB_PROPAGATION_TIMEOUT", 2*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
HTTPTimeout: env.GetOrDefaultSecond("LIQUID_WEB_HTTP_TIMEOUT", 1*time.Minute), HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 1*time.Minute),
} }
return config return config
@ -52,16 +67,16 @@ type DNSProvider struct {
// NewDNSProvider returns a DNSProvider instance configured for Liquid Web. // NewDNSProvider returns a DNSProvider instance configured for Liquid Web.
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("liquidweb: %w", err) return nil, fmt.Errorf("liquidweb: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.BaseURL = env.GetOrFile("LIQUID_WEB_URL") config.BaseURL = env.GetOrFile(EnvURL)
config.Username = values["LIQUID_WEB_USERNAME"] config.Username = values[EnvUsername]
config.Password = values["LIQUID_WEB_PASSWORD"] config.Password = values[EnvPassword]
config.Zone = values["LIQUID_WEB_ZONE"] config.Zone = values[EnvZone]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -13,12 +13,14 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"LIQUID_WEB_URL", EnvURL,
"LIQUID_WEB_USERNAME", EnvUsername,
"LIQUID_WEB_PASSWORD", EnvPassword,
"LIQUID_WEB_ZONE"). EnvZone).
WithDomain("LIQUID_WEB_DOMAIN") WithDomain(envDomain)
func setupTest() (*DNSProvider, *http.ServeMux, func()) { func setupTest() (*DNSProvider, *http.ServeMux, func()) {
handler := http.NewServeMux() handler := http.NewServeMux()
@ -47,10 +49,10 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"LIQUID_WEB_URL": "https://storm.com", EnvURL: "https://storm.com",
"LIQUID_WEB_USERNAME": "blars", EnvUsername: "blars",
"LIQUID_WEB_PASSWORD": "tacoman", EnvPassword: "tacoman",
"LIQUID_WEB_ZONE": "blars.com", EnvZone: "blars.com",
}, },
}, },
{ {
@ -61,23 +63,23 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"LIQUID_WEB_PASSWORD": "tacoman", EnvPassword: "tacoman",
"LIQUID_WEB_ZONE": "blars.com", EnvZone: "blars.com",
}, },
expected: "liquidweb: some credentials information are missing: LIQUID_WEB_USERNAME", expected: "liquidweb: some credentials information are missing: LIQUID_WEB_USERNAME",
}, },
{ {
desc: "missing password", desc: "missing password",
envVars: map[string]string{ envVars: map[string]string{
"LIQUID_WEB_USERNAME": "blars", EnvUsername: "blars",
"LIQUID_WEB_ZONE": "blars.com", EnvZone: "blars.com",
}, expected: "liquidweb: some credentials information are missing: LIQUID_WEB_PASSWORD", }, expected: "liquidweb: some credentials information are missing: LIQUID_WEB_PASSWORD",
}, },
{ {
desc: "missing zone", desc: "missing zone",
envVars: map[string]string{ envVars: map[string]string{
"LIQUID_WEB_USERNAME": "blars", EnvUsername: "blars",
"LIQUID_WEB_PASSWORD": "tacoman", EnvPassword: "tacoman",
}, expected: "liquidweb: some credentials information are missing: LIQUID_WEB_ZONE", }, expected: "liquidweb: some credentials information are missing: LIQUID_WEB_ZONE",
}, },
} }

View file

@ -13,6 +13,18 @@ import (
const defaultBaseURL = "https://www.mydns.jp/directedit.html" 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
MasterID string MasterID string
@ -25,10 +37,10 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("MYDNSJP_PROPAGATION_TIMEOUT", 2*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond("MYDNSJP_POLLING_INTERVAL", 2*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for MyDNS.jp.
// Credentials must be passed in the environment variables: MYDNSJP_MASTER_ID and MYDNSJP_PASSWORD. // Credentials must be passed in the environment variables: MYDNSJP_MASTER_ID and MYDNSJP_PASSWORD.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("MYDNSJP_MASTER_ID", "MYDNSJP_PASSWORD") values, err := env.Get(EnvMasterID, EnvPassword)
if err != nil { if err != nil {
return nil, fmt.Errorf("mydnsjp: %w", err) return nil, fmt.Errorf("mydnsjp: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.MasterID = values["MYDNSJP_MASTER_ID"] config.MasterID = values[EnvMasterID]
config.Password = values["MYDNSJP_PASSWORD"] config.Password = values[EnvPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -9,8 +9,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("MYDNSJP_MASTER_ID", "MYDNSJP_PASSWORD"). const envDomain = envNamespace + "DOMAIN"
WithDomain("MYDNSJP_DOMAIN")
var envTest = tester.NewEnvTest(EnvMasterID, EnvPassword).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -21,31 +23,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"MYDNSJP_MASTER_ID": "test@example.com", EnvMasterID: "test@example.com",
"MYDNSJP_PASSWORD": "123", EnvPassword: "123",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"MYDNSJP_MASTER_ID": "", EnvMasterID: "",
"MYDNSJP_PASSWORD": "", EnvPassword: "",
}, },
expected: "mydnsjp: some credentials information are missing: MYDNSJP_MASTER_ID,MYDNSJP_PASSWORD", expected: "mydnsjp: some credentials information are missing: MYDNSJP_MASTER_ID,MYDNSJP_PASSWORD",
}, },
{ {
desc: "missing email", desc: "missing email",
envVars: map[string]string{ envVars: map[string]string{
"MYDNSJP_MASTER_ID": "", EnvMasterID: "",
"MYDNSJP_PASSWORD": "key", EnvPassword: "key",
}, },
expected: "mydnsjp: some credentials information are missing: MYDNSJP_MASTER_ID", expected: "mydnsjp: some credentials information are missing: MYDNSJP_MASTER_ID",
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"MYDNSJP_MASTER_ID": "awesome@possum.com", EnvMasterID: "awesome@possum.com",
"MYDNSJP_PASSWORD": "", EnvPassword: "",
}, },
expected: "mydnsjp: some credentials information are missing: MYDNSJP_PASSWORD", expected: "mydnsjp: some credentials information are missing: MYDNSJP_PASSWORD",
}, },

View file

@ -35,6 +35,22 @@ const (
getIPURL = "https://dynamicdns.park-your-domain.com/getip" 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 // A challenge represents all the data needed to specify a dns-01 challenge
// to lets-encrypt. // to lets-encrypt.
type challenge struct { type challenge struct {
@ -63,18 +79,18 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
baseURL := defaultBaseURL baseURL := defaultBaseURL
if env.GetOrDefaultBool("NAMECHEAP_SANDBOX", false) { if env.GetOrDefaultBool(EnvSandbox, false) {
baseURL = sandboxBaseURL baseURL = sandboxBaseURL
} }
return &Config{ return &Config{
BaseURL: baseURL, BaseURL: baseURL,
Debug: env.GetOrDefaultBool("NAMECHEAP_DEBUG", false), Debug: env.GetOrDefaultBool(EnvDebug, false),
TTL: env.GetOrDefaultInt("NAMECHEAP_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("NAMECHEAP_PROPAGATION_TIMEOUT", 60*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Minute),
PollingInterval: env.GetOrDefaultSecond("NAMECHEAP_POLLING_INTERVAL", 15*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 15*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// NAMECHEAP_API_USER and NAMECHEAP_API_KEY. // NAMECHEAP_API_USER and NAMECHEAP_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("NAMECHEAP_API_USER", "NAMECHEAP_API_KEY") values, err := env.Get(EnvAPIUser, EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("namecheap: %w", err) return nil, fmt.Errorf("namecheap: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIUser = values["NAMECHEAP_API_USER"] config.APIUser = values[EnvAPIUser]
config.APIKey = values["NAMECHEAP_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -16,6 +16,20 @@ import (
// according to https://www.name.com/api-docs/DNS#CreateRecord // according to https://www.name.com/api-docs/DNS#CreateRecord
const minTTL = 300 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Username string Username string
@ -30,11 +44,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("NAMECOM_TTL", minTTL), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond("NAMECOM_PROPAGATION_TIMEOUT", 15*time.Minute), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 15*time.Minute),
PollingInterval: env.GetOrDefaultSecond("NAMECOM_POLLING_INTERVAL", 20*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 20*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// NAMECOM_USERNAME and NAMECOM_API_TOKEN // NAMECOM_USERNAME and NAMECOM_API_TOKEN
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("NAMECOM_USERNAME", "NAMECOM_API_TOKEN") values, err := env.Get(EnvUsername, EnvAPIToken)
if err != nil { if err != nil {
return nil, fmt.Errorf("namedotcom: %w", err) return nil, fmt.Errorf("namedotcom: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Username = values["NAMECOM_USERNAME"] config.Username = values[EnvUsername]
config.APIToken = values["NAMECOM_API_TOKEN"] config.APIToken = values[EnvAPIToken]
config.Server = env.GetOrFile("NAMECOM_SERVER") config.Server = env.GetOrFile(EnvServer)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"NAMECOM_USERNAME", EnvUsername,
"NAMECOM_API_TOKEN"). EnvAPIToken).
WithDomain("NAMEDOTCOM_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"NAMECOM_USERNAME": "A", EnvUsername: "A",
"NAMECOM_API_TOKEN": "B", EnvAPIToken: "B",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"NAMECOM_USERNAME": "", EnvUsername: "",
"NAMECOM_API_TOKEN": "", EnvAPIToken: "",
}, },
expected: "namedotcom: some credentials information are missing: NAMECOM_USERNAME,NAMECOM_API_TOKEN", expected: "namedotcom: some credentials information are missing: NAMECOM_USERNAME,NAMECOM_API_TOKEN",
}, },
{ {
desc: "missing username", desc: "missing username",
envVars: map[string]string{ envVars: map[string]string{
"NAMECOM_USERNAME": "", EnvUsername: "",
"NAMECOM_API_TOKEN": "B", EnvAPIToken: "B",
}, },
expected: "namedotcom: some credentials information are missing: NAMECOM_USERNAME", expected: "namedotcom: some credentials information are missing: NAMECOM_USERNAME",
}, },
{ {
desc: "missing api token", desc: "missing api token",
envVars: map[string]string{ envVars: map[string]string{
"NAMECOM_USERNAME": "A", EnvUsername: "A",
"NAMECOM_API_TOKEN": "", EnvAPIToken: "",
}, },
expected: "namedotcom: some credentials information are missing: NAMECOM_API_TOKEN", expected: "namedotcom: some credentials information are missing: NAMECOM_API_TOKEN",
}, },

View file

@ -17,6 +17,17 @@ const (
maxTTL = 2592000 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -28,9 +39,9 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PropagationTimeout: env.GetOrDefaultSecond("NAMESILO_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL),
PollingInterval: env.GetOrDefaultSecond("NAMESILO_POLLING_INTERVAL", dns01.DefaultPollingInterval), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
TTL: env.GetOrDefaultInt("NAMESILO_TTL", defaultTTL), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
} }
} }
@ -45,13 +56,13 @@ type DNSProvider struct {
// //
// See: https://www.namesilo.com/api_reference.php // See: https://www.namesilo.com/api_reference.php
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("NAMESILO_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("namesilo: %w", err) return nil, fmt.Errorf("namesilo: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["NAMESILO_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"NAMESILO_TTL", EnvTTL,
"NAMESILO_API_KEY"). EnvAPIKey).
WithDomain("NAMESILO_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,7 +24,7 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"NAMESILO_API_KEY": "A", EnvAPIKey: "A",
}, },
}, },
{ {
@ -33,8 +35,8 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "unsupported TTL", desc: "unsupported TTL",
envVars: map[string]string{ envVars: map[string]string{
"NAMESILO_API_KEY": "A", EnvAPIKey: "A",
"NAMESILO_TTL": "180", EnvTTL: "180",
}, },
expected: "namesilo: TTL should be in [3600, 2592000]", expected: "namesilo: TTL should be in [3600, 2592000]",
}, },

View file

@ -15,6 +15,20 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Key string Key string
@ -29,11 +43,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("NETCUP_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("NETCUP_PROPAGATION_TIMEOUT", 120*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
PollingInterval: env.GetOrDefaultSecond("NETCUP_POLLING_INTERVAL", 5*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// NETCUP_CUSTOMER_NUMBER, NETCUP_API_KEY, NETCUP_API_PASSWORD // NETCUP_CUSTOMER_NUMBER, NETCUP_API_KEY, NETCUP_API_PASSWORD
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("netcup: %w", err) return nil, fmt.Errorf("netcup: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Customer = values["NETCUP_CUSTOMER_NUMBER"] config.Customer = values[EnvCustomerNumber]
config.Key = values["NETCUP_API_KEY"] config.Key = values[EnvAPIKey]
config.Password = values["NETCUP_API_PASSWORD"] config.Password = values[EnvAPIPassword]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -9,11 +9,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"NETCUP_CUSTOMER_NUMBER", EnvCustomerNumber,
"NETCUP_API_KEY", EnvAPIKey,
"NETCUP_API_PASSWORD"). EnvAPIPassword).
WithDomain("NETCUP_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -24,44 +26,44 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "A", EnvCustomerNumber: "A",
"NETCUP_API_KEY": "B", EnvAPIKey: "B",
"NETCUP_API_PASSWORD": "C", EnvAPIPassword: "C",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "", EnvCustomerNumber: "",
"NETCUP_API_KEY": "", EnvAPIKey: "",
"NETCUP_API_PASSWORD": "", EnvAPIPassword: "",
}, },
expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER,NETCUP_API_KEY,NETCUP_API_PASSWORD", expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER,NETCUP_API_KEY,NETCUP_API_PASSWORD",
}, },
{ {
desc: "missing customer number", desc: "missing customer number",
envVars: map[string]string{ envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "", EnvCustomerNumber: "",
"NETCUP_API_KEY": "B", EnvAPIKey: "B",
"NETCUP_API_PASSWORD": "C", EnvAPIPassword: "C",
}, },
expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER", expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER",
}, },
{ {
desc: "missing API key", desc: "missing API key",
envVars: map[string]string{ envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "A", EnvCustomerNumber: "A",
"NETCUP_API_KEY": "", EnvAPIKey: "",
"NETCUP_API_PASSWORD": "C", EnvAPIPassword: "C",
}, },
expected: "netcup: some credentials information are missing: NETCUP_API_KEY", expected: "netcup: some credentials information are missing: NETCUP_API_KEY",
}, },
{ {
desc: "missing api password", desc: "missing api password",
envVars: map[string]string{ envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "A", EnvCustomerNumber: "A",
"NETCUP_API_KEY": "B", EnvAPIKey: "B",
"NETCUP_API_PASSWORD": "", EnvAPIPassword: "",
}, },
expected: "netcup: some credentials information are missing: NETCUP_API_PASSWORD", expected: "netcup: some credentials information are missing: NETCUP_API_PASSWORD",
}, },

View file

@ -14,6 +14,20 @@ import (
"github.com/go-acme/lego/v3/platform/wait" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
BaseURL string BaseURL string
@ -28,11 +42,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("NIFCLOUD_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("NIFCLOUD_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("NIFCLOUD_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variables:
// NIFCLOUD_ACCESS_KEY_ID and NIFCLOUD_SECRET_ACCESS_KEY. // NIFCLOUD_ACCESS_KEY_ID and NIFCLOUD_SECRET_ACCESS_KEY.
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("nifcloud: %w", err) return nil, fmt.Errorf("nifcloud: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.BaseURL = env.GetOrFile("NIFCLOUD_DNS_ENDPOINT") config.BaseURL = env.GetOrFile(EnvDNSEndpoint)
config.AccessKey = values["NIFCLOUD_ACCESS_KEY_ID"] config.AccessKey = values[EnvAccessKeyID]
config.SecretKey = values["NIFCLOUD_SECRET_ACCESS_KEY"] config.SecretKey = values[EnvSecretAccessKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"NIFCLOUD_ACCESS_KEY_ID", EnvAccessKeyID,
"NIFCLOUD_SECRET_ACCESS_KEY"). EnvSecretAccessKey).
WithDomain("NIFCLOUD_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"NIFCLOUD_ACCESS_KEY_ID": "123", EnvAccessKeyID: "123",
"NIFCLOUD_SECRET_ACCESS_KEY": "456", EnvSecretAccessKey: "456",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"NIFCLOUD_ACCESS_KEY_ID": "", EnvAccessKeyID: "",
"NIFCLOUD_SECRET_ACCESS_KEY": "", EnvSecretAccessKey: "",
}, },
expected: "nifcloud: some credentials information are missing: NIFCLOUD_ACCESS_KEY_ID,NIFCLOUD_SECRET_ACCESS_KEY", expected: "nifcloud: some credentials information are missing: NIFCLOUD_ACCESS_KEY_ID,NIFCLOUD_SECRET_ACCESS_KEY",
}, },
{ {
desc: "missing access key", desc: "missing access key",
envVars: map[string]string{ envVars: map[string]string{
"NIFCLOUD_ACCESS_KEY_ID": "", EnvAccessKeyID: "",
"NIFCLOUD_SECRET_ACCESS_KEY": "456", EnvSecretAccessKey: "456",
}, },
expected: "nifcloud: some credentials information are missing: NIFCLOUD_ACCESS_KEY_ID", expected: "nifcloud: some credentials information are missing: NIFCLOUD_ACCESS_KEY_ID",
}, },
{ {
desc: "missing secret key", desc: "missing secret key",
envVars: map[string]string{ envVars: map[string]string{
"NIFCLOUD_ACCESS_KEY_ID": "123", EnvAccessKeyID: "123",
"NIFCLOUD_SECRET_ACCESS_KEY": "", EnvSecretAccessKey: "",
}, },
expected: "nifcloud: some credentials information are missing: NIFCLOUD_SECRET_ACCESS_KEY", expected: "nifcloud: some credentials information are missing: NIFCLOUD_SECRET_ACCESS_KEY",
}, },

View file

@ -15,6 +15,18 @@ import (
"gopkg.in/ns1/ns1-go.v2/rest/model/dns" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -27,11 +39,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("NS1_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("NS1_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("NS1_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for NS1.
// Credentials must be passed in the environment variables: NS1_API_KEY. // Credentials must be passed in the environment variables: NS1_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("NS1_API_KEY") values, err := env.Get(EnvAPIKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("ns1: %w", err) return nil, fmt.Errorf("ns1: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIKey = values["NS1_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -9,8 +9,10 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var envTest = tester.NewEnvTest("NS1_API_KEY"). const envDomain = envNamespace + "DOMAIN"
WithDomain("NS1_DOMAIN")
var envTest = tester.NewEnvTest(EnvAPIKey).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -21,13 +23,13 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"NS1_API_KEY": "123", EnvAPIKey: "123",
}, },
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"NS1_API_KEY": "", EnvAPIKey: "",
}, },
expected: "ns1: some credentials information are missing: NS1_API_KEY", expected: "ns1: some credentials information are missing: NS1_API_KEY",
}, },

View file

@ -11,15 +11,6 @@ import (
"github.com/oracle/oci-go-sdk/common" "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 { type configProvider struct {
values map[string]string values map[string]string
privateKeyPassphrase string privateKeyPassphrase string
@ -28,12 +19,12 @@ type configProvider struct {
func newConfigProvider(values map[string]string) *configProvider { func newConfigProvider(values map[string]string) *configProvider {
return &configProvider{ return &configProvider{
values: values, values: values,
privateKeyPassphrase: env.GetOrFile(ociPrivkeyPass), privateKeyPassphrase: env.GetOrFile(EnvPrivKeyPass),
} }
} }
func (p *configProvider) PrivateRSAKey() (*rsa.PrivateKey, error) { func (p *configProvider) PrivateRSAKey() (*rsa.PrivateKey, error) {
privateKey, err := getPrivateKey(ociPrivkey) privateKey, err := getPrivateKey(envPrivKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -61,19 +52,19 @@ func (p *configProvider) KeyID() (string, error) {
} }
func (p *configProvider) TenancyOCID() (value string, err 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) { func (p *configProvider) UserOCID() (string, error) {
return p.values[ociUserOCID], nil return p.values[EnvUserOCID], nil
} }
func (p *configProvider) KeyFingerprint() (string, error) { func (p *configProvider) KeyFingerprint() (string, error) {
return p.values[ociPubkeyFingerprint], nil return p.values[EnvPubKeyFingerprint], nil
} }
func (p *configProvider) Region() (string, error) { func (p *configProvider) Region() (string, error) {
return p.values[ociRegion], nil return p.values[EnvRegion], nil
} }
func getPrivateKey(envVar string) ([]byte, error) { func getPrivateKey(envVar string) ([]byte, error) {

View file

@ -13,6 +13,25 @@ import (
"github.com/oracle/oci-go-sdk/dns" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
CompartmentID string CompartmentID string
@ -26,11 +45,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("OCI_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("OCI_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("OCI_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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. // NewDNSProvider returns a DNSProvider instance configured for OracleCloud.
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("oraclecloud: %w", err) return nil, fmt.Errorf("oraclecloud: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.CompartmentID = values["OCI_COMPARTMENT_OCID"] config.CompartmentID = values[EnvCompartmentOCID]
config.OCIConfigProvider = newConfigProvider(values) config.OCIConfigProvider = newConfigProvider(values)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)

View file

@ -16,16 +16,18 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
ociPrivkey, envPrivKey,
ociPrivkey+"_FILE", EnvPrivKeyFile,
ociPrivkeyPass, EnvPrivKeyPass,
ociTenancyOCID, EnvTenancyOCID,
ociUserOCID, EnvUserOCID,
ociPubkeyFingerprint, EnvPubKeyFingerprint,
ociRegion, EnvRegion,
"OCI_COMPARTMENT_OCID"). EnvCompartmentOCID).
WithDomain("ORACLECLOUD_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -36,25 +38,25 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret1"), envPrivKey: mustGeneratePrivateKey("secret1"),
ociPrivkeyPass: "secret1", EnvPrivKeyPass: "secret1",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
}, },
{ {
desc: "success file", desc: "success file",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey + "_FILE": mustGeneratePrivateKeyFile("secret1"), EnvPrivKeyFile: mustGeneratePrivateKeyFile("secret1"),
ociPrivkeyPass: "secret1", EnvPrivKeyPass: "secret1",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
}, },
{ {
@ -65,104 +67,104 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "missing CompartmentID", desc: "missing CompartmentID",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "", EnvCompartmentOCID: "",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_COMPARTMENT_OCID", expected: "oraclecloud: some credentials information are missing: OCI_COMPARTMENT_OCID",
}, },
{ {
desc: "missing OCI_PRIVKEY", desc: "missing OCI_PRIVKEY",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: "", envPrivKey: "",
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_PRIVKEY", expected: "oraclecloud: some credentials information are missing: OCI_PRIVKEY",
}, },
{ {
desc: "missing OCI_PRIVKEY_PASS", desc: "missing OCI_PRIVKEY_PASS",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "", EnvPrivKeyPass: "",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: can not create client, bad configuration: x509: decryption password incorrect", expected: "oraclecloud: can not create client, bad configuration: x509: decryption password incorrect",
}, },
{ {
desc: "missing OCI_TENANCY_OCID", desc: "missing OCI_TENANCY_OCID",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "", EnvTenancyOCID: "",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_TENANCY_OCID", expected: "oraclecloud: some credentials information are missing: OCI_TENANCY_OCID",
}, },
{ {
desc: "missing OCI_USER_OCID", desc: "missing OCI_USER_OCID",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "", EnvUserOCID: "",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_USER_OCID", expected: "oraclecloud: some credentials information are missing: OCI_USER_OCID",
}, },
{ {
desc: "missing OCI_PUBKEY_FINGERPRINT", desc: "missing OCI_PUBKEY_FINGERPRINT",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "", EnvPubKeyFingerprint: "",
ociRegion: "us-phoenix-1", EnvRegion: "us-phoenix-1",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_PUBKEY_FINGERPRINT", expected: "oraclecloud: some credentials information are missing: OCI_PUBKEY_FINGERPRINT",
}, },
{ {
desc: "missing OCI_REGION", desc: "missing OCI_REGION",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "", EnvRegion: "",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_REGION", expected: "oraclecloud: some credentials information are missing: OCI_REGION",
}, },
{ {
desc: "missing OCI_REGION", desc: "missing OCI_REGION",
envVars: map[string]string{ envVars: map[string]string{
ociPrivkey: mustGeneratePrivateKey("secret"), envPrivKey: mustGeneratePrivateKey("secret"),
ociPrivkeyPass: "secret", EnvPrivKeyPass: "secret",
ociTenancyOCID: "ocid1.tenancy.oc1..secret", EnvTenancyOCID: "ocid1.tenancy.oc1..secret",
ociUserOCID: "ocid1.user.oc1..secret", EnvUserOCID: "ocid1.user.oc1..secret",
ociPubkeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", EnvPubKeyFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
ociRegion: "", EnvRegion: "",
"OCI_COMPARTMENT_OCID": "123", EnvCompartmentOCID: "123",
}, },
expected: "oraclecloud: some credentials information are missing: OCI_REGION", expected: "oraclecloud: some credentials information are missing: OCI_REGION",
}, },
@ -171,7 +173,7 @@ func TestNewDNSProvider(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
defer func() { defer func() {
privKeyFile := os.Getenv(ociPrivkey + "_FILE") privKeyFile := os.Getenv(EnvPrivKeyFile)
if privKeyFile != "" { if privKeyFile != "" {
_ = os.Remove(privKeyFile) _ = os.Remove(privKeyFile)
} }

View file

@ -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 // minTTL 300 is otc minimum value for ttl
const minTTL = 300 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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
IdentityEndpoint string IdentityEndpoint string
@ -33,12 +49,12 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
IdentityEndpoint: env.GetOrDefaultString("OTC_IDENTITY_ENDPOINT", defaultIdentityEndpoint), TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond("OTC_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("OTC_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
TTL: env.GetOrDefaultInt("OTC_TTL", minTTL), IdentityEndpoint: env.GetOrDefaultString(EnvIdentityEndpoint, defaultIdentityEndpoint),
HTTPClient: &http.Client{ HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond("OTC_HTTP_TIMEOUT", 10*time.Second), Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
Transport: &http.Transport{ Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{ DialContext: (&net.Dialer{
@ -70,16 +86,16 @@ type DNSProvider struct {
// Credentials must be passed in the environment variables: OTC_USER_NAME, // Credentials must be passed in the environment variables: OTC_USER_NAME,
// OTC_DOMAIN_NAME, OTC_PASSWORD OTC_PROJECT_NAME and OTC_IDENTITY_ENDPOINT. // OTC_DOMAIN_NAME, OTC_PASSWORD OTC_PROJECT_NAME and OTC_IDENTITY_ENDPOINT.
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("otc: %w", err) return nil, fmt.Errorf("otc: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.DomainName = values["OTC_DOMAIN_NAME"] config.DomainName = values[EnvDomainName]
config.UserName = values["OTC_USER_NAME"] config.UserName = values[EnvUserName]
config.Password = values["OTC_PASSWORD"] config.Password = values[EnvPassword]
config.ProjectName = values["OTC_PROJECT_NAME"] config.ProjectName = values[EnvProjectName]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -19,11 +19,11 @@ func (s *OTCSuite) SetupTest() {
s.Mock = NewDNSServerMock(s.T()) s.Mock = NewDNSServerMock(s.T())
s.Mock.HandleAuthSuccessfully() s.Mock.HandleAuthSuccessfully()
s.envTest = tester.NewEnvTest( s.envTest = tester.NewEnvTest(
"OTC_DOMAIN_NAME", EnvDomainName,
"OTC_USER_NAME", EnvUserName,
"OTC_PASSWORD", EnvPassword,
"OTC_PROJECT_NAME", EnvProjectName,
"OTC_IDENTITY_ENDPOINT", EnvIdentityEndpoint,
) )
} }
@ -62,11 +62,11 @@ func (s *OTCSuite) TestLoginEnv() {
s.envTest.ClearEnv() s.envTest.ClearEnv()
s.envTest.Apply(map[string]string{ s.envTest.Apply(map[string]string{
"OTC_DOMAIN_NAME": "unittest1", EnvDomainName: "unittest1",
"OTC_USER_NAME": "unittest2", EnvUserName: "unittest2",
"OTC_PASSWORD": "unittest3", EnvPassword: "unittest3",
"OTC_PROJECT_NAME": "unittest4", EnvProjectName: "unittest4",
"OTC_IDENTITY_ENDPOINT": "unittest5", EnvIdentityEndpoint: "unittest5",
}) })
provider, err := NewDNSProvider() provider, err := NewDNSProvider()
@ -78,7 +78,7 @@ func (s *OTCSuite) TestLoginEnv() {
s.Equal(provider.config.ProjectName, "unittest4") s.Equal(provider.config.ProjectName, "unittest4")
s.Equal(provider.config.IdentityEndpoint, "unittest5") s.Equal(provider.config.IdentityEndpoint, "unittest5")
os.Setenv("OTC_IDENTITY_ENDPOINT", "") os.Setenv(EnvIdentityEndpoint, "")
provider, err = NewDNSProvider() provider, err = NewDNSProvider()
s.Require().NoError(err) s.Require().NoError(err)

View file

@ -17,6 +17,21 @@ import (
// OVH API reference: https://eu.api.ovh.com/ // OVH API reference: https://eu.api.ovh.com/
// Create a Token: https://eu.api.ovh.com/createToken/ // 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 // Record a DNS record
type Record struct { type Record struct {
ID int64 `json:"id,omitempty"` ID int64 `json:"id,omitempty"`
@ -42,11 +57,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("OVH_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("OVH_PROPAGATION_TIMEOUT", dns01.DefaultPropagationTimeout), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond("OVH_POLLING_INTERVAL", dns01.DefaultPollingInterval), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{ 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_APPLICATION_SECRET
// OVH_CONSUMER_KEY // OVH_CONSUMER_KEY
func NewDNSProvider() (*DNSProvider, error) { 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 { if err != nil {
return nil, fmt.Errorf("ovh: %w", err) return nil, fmt.Errorf("ovh: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.APIEndpoint = values["OVH_ENDPOINT"] config.APIEndpoint = values[EnvEndpoint]
config.ApplicationKey = values["OVH_APPLICATION_KEY"] config.ApplicationKey = values[EnvApplicationKey]
config.ApplicationSecret = values["OVH_APPLICATION_SECRET"] config.ApplicationSecret = values[EnvApplicationSecret]
config.ConsumerKey = values["OVH_CONSUMER_KEY"] config.ConsumerKey = values[EnvConsumerKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,12 +8,14 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"OVH_ENDPOINT", EnvEndpoint,
"OVH_APPLICATION_KEY", EnvApplicationKey,
"OVH_APPLICATION_SECRET", EnvApplicationSecret,
"OVH_CONSUMER_KEY"). EnvConsumerKey).
WithDomain("OVH_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -24,69 +26,69 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu", EnvEndpoint: "ovh-eu",
"OVH_APPLICATION_KEY": "B", EnvApplicationKey: "B",
"OVH_APPLICATION_SECRET": "C", EnvApplicationSecret: "C",
"OVH_CONSUMER_KEY": "D", EnvConsumerKey: "D",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "", EnvEndpoint: "",
"OVH_APPLICATION_KEY": "", EnvApplicationKey: "",
"OVH_APPLICATION_SECRET": "", EnvApplicationSecret: "",
"OVH_CONSUMER_KEY": "", EnvConsumerKey: "",
}, },
expected: "ovh: some credentials information are missing: OVH_ENDPOINT,OVH_APPLICATION_KEY,OVH_APPLICATION_SECRET,OVH_CONSUMER_KEY", expected: "ovh: some credentials information are missing: OVH_ENDPOINT,OVH_APPLICATION_KEY,OVH_APPLICATION_SECRET,OVH_CONSUMER_KEY",
}, },
{ {
desc: "missing endpoint", desc: "missing endpoint",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "", EnvEndpoint: "",
"OVH_APPLICATION_KEY": "B", EnvApplicationKey: "B",
"OVH_APPLICATION_SECRET": "C", EnvApplicationSecret: "C",
"OVH_CONSUMER_KEY": "D", EnvConsumerKey: "D",
}, },
expected: "ovh: some credentials information are missing: OVH_ENDPOINT", expected: "ovh: some credentials information are missing: OVH_ENDPOINT",
}, },
{ {
desc: "missing invalid endpoint", desc: "missing invalid endpoint",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "foobar", EnvEndpoint: "foobar",
"OVH_APPLICATION_KEY": "B", EnvApplicationKey: "B",
"OVH_APPLICATION_SECRET": "C", EnvApplicationSecret: "C",
"OVH_CONSUMER_KEY": "D", EnvConsumerKey: "D",
}, },
expected: "ovh: unknown endpoint 'foobar', consider checking 'Endpoints' list of using an URL", expected: "ovh: unknown endpoint 'foobar', consider checking 'Endpoints' list of using an URL",
}, },
{ {
desc: "missing application key", desc: "missing application key",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu", EnvEndpoint: "ovh-eu",
"OVH_APPLICATION_KEY": "", EnvApplicationKey: "",
"OVH_APPLICATION_SECRET": "C", EnvApplicationSecret: "C",
"OVH_CONSUMER_KEY": "D", EnvConsumerKey: "D",
}, },
expected: "ovh: some credentials information are missing: OVH_APPLICATION_KEY", expected: "ovh: some credentials information are missing: OVH_APPLICATION_KEY",
}, },
{ {
desc: "missing application secret", desc: "missing application secret",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu", EnvEndpoint: "ovh-eu",
"OVH_APPLICATION_KEY": "B", EnvApplicationKey: "B",
"OVH_APPLICATION_SECRET": "", EnvApplicationSecret: "",
"OVH_CONSUMER_KEY": "D", EnvConsumerKey: "D",
}, },
expected: "ovh: some credentials information are missing: OVH_APPLICATION_SECRET", expected: "ovh: some credentials information are missing: OVH_APPLICATION_SECRET",
}, },
{ {
desc: "missing consumer key", desc: "missing consumer key",
envVars: map[string]string{ envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu", EnvEndpoint: "ovh-eu",
"OVH_APPLICATION_KEY": "B", EnvApplicationKey: "B",
"OVH_APPLICATION_SECRET": "C", EnvApplicationSecret: "C",
"OVH_CONSUMER_KEY": "", EnvConsumerKey: "",
}, },
expected: "ovh: some credentials information are missing: OVH_CONSUMER_KEY", expected: "ovh: some credentials information are missing: OVH_CONSUMER_KEY",
}, },

View file

@ -15,6 +15,19 @@ import (
"github.com/go-acme/lego/v3/platform/config/env" "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 // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
APIKey string APIKey string
@ -28,11 +41,11 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
TTL: env.GetOrDefaultInt("PDNS_TTL", dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond("PDNS_PROPAGATION_TIMEOUT", 120*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
PollingInterval: env.GetOrDefaultSecond("PDNS_POLLING_INTERVAL", 2*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
HTTPClient: &http.Client{ 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: // Credentials must be passed in the environment variable:
// PDNS_API_URL and PDNS_API_KEY. // PDNS_API_URL and PDNS_API_KEY.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("PDNS_API_KEY", "PDNS_API_URL") values, err := env.Get(EnvAPIKey, EnvAPIURL)
if err != nil { if err != nil {
return nil, fmt.Errorf("pdns: %w", err) return nil, fmt.Errorf("pdns: %w", err)
} }
hostURL, err := url.Parse(values["PDNS_API_URL"]) hostURL, err := url.Parse(values[EnvAPIURL])
if err != nil { if err != nil {
return nil, fmt.Errorf("pdns: %w", err) return nil, fmt.Errorf("pdns: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Host = hostURL config.Host = hostURL
config.APIKey = values["PDNS_API_KEY"] config.APIKey = values[EnvAPIKey]
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest( var envTest = tester.NewEnvTest(
"PDNS_API_URL", EnvAPIURL,
"PDNS_API_KEY"). EnvAPIKey).
WithDomain("PDNS_DOMAIN") WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
testCases := []struct { testCases := []struct {
@ -22,31 +24,31 @@ func TestNewDNSProvider(t *testing.T) {
{ {
desc: "success", desc: "success",
envVars: map[string]string{ envVars: map[string]string{
"PDNS_API_KEY": "123", EnvAPIKey: "123",
"PDNS_API_URL": "http://example.com", EnvAPIURL: "http://example.com",
}, },
}, },
{ {
desc: "missing credentials", desc: "missing credentials",
envVars: map[string]string{ envVars: map[string]string{
"PDNS_API_KEY": "", EnvAPIKey: "",
"PDNS_API_URL": "", EnvAPIURL: "",
}, },
expected: "pdns: some credentials information are missing: PDNS_API_KEY,PDNS_API_URL", expected: "pdns: some credentials information are missing: PDNS_API_KEY,PDNS_API_URL",
}, },
{ {
desc: "missing api key", desc: "missing api key",
envVars: map[string]string{ envVars: map[string]string{
"PDNS_API_KEY": "", EnvAPIKey: "",
"PDNS_API_URL": "http://example.com", EnvAPIURL: "http://example.com",
}, },
expected: "pdns: some credentials information are missing: PDNS_API_KEY", expected: "pdns: some credentials information are missing: PDNS_API_KEY",
}, },
{ {
desc: "missing API URL", desc: "missing API URL",
envVars: map[string]string{ envVars: map[string]string{
"PDNS_API_KEY": "123", EnvAPIKey: "123",
"PDNS_API_URL": "", EnvAPIURL: "",
}, },
expected: "pdns: some credentials information are missing: PDNS_API_URL", 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