From 27fd142ca15ad6858510569a224227765ff814e8 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 20 Mar 2024 04:31:18 +0100 Subject: [PATCH] scaleway: add alternative env var names (#2136) --- CHANGELOG.md | 2 +- cmd/zz_gen_cmd_dnshelp.go | 11 +++++---- docs/content/dns/zz_gen_scaleway.md | 13 ++++++----- providers/dns/scaleway/scaleway.go | 31 +++++++++++++++++++------ providers/dns/scaleway/scaleway.toml | 13 ++++++----- providers/dns/scaleway/scaleway_test.go | 4 ++-- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f136edc5..09694396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - **[dnsprovider]** Add DNS provider for Shellrent - **[dnsprovider]** Add DNS provider for Mail-in-a-Box - **[dnsprovider]** Add DNS provider for CPanel and WHM -- + ### Changed - **[lib,ari]** Implement 'replaces' field in newOrder and draft-ietf-acme-ari-03 CertID changes diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index 7cd56f9c..919ce614 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -2363,14 +2363,15 @@ func displayDNSHelp(w io.Writer, name string) error { ew.writeln() ew.writeln(`Credentials:`) - ew.writeln(` - "SCALEWAY_API_TOKEN": API token`) - ew.writeln(` - "SCALEWAY_PROJECT_ID": Project to use (optional)`) + ew.writeln(` - "SCW_PROJECT_ID": Project to use (optional)`) + ew.writeln(` - "SCW_SECRET_KEY": Secret key`) ew.writeln() ew.writeln(`Additional Configuration:`) - ew.writeln(` - "SCALEWAY_POLLING_INTERVAL": Time between DNS propagation check`) - ew.writeln(` - "SCALEWAY_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) - ew.writeln(` - "SCALEWAY_TTL": The TTL of the TXT record used for the DNS challenge`) + ew.writeln(` - "SCW_ACCESS_KEY": Access key`) + ew.writeln(` - "SCW_POLLING_INTERVAL": Time between DNS propagation check`) + ew.writeln(` - "SCW_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) + ew.writeln(` - "SCW_TTL": The TTL of the TXT record used for the DNS challenge`) ew.writeln() ew.writeln(`More information: https://go-acme.github.io/lego/dns/scaleway`) diff --git a/docs/content/dns/zz_gen_scaleway.md b/docs/content/dns/zz_gen_scaleway.md index 376f1b59..78ff0d7e 100644 --- a/docs/content/dns/zz_gen_scaleway.md +++ b/docs/content/dns/zz_gen_scaleway.md @@ -26,7 +26,7 @@ Configuration for [Scaleway](https://developers.scaleway.com/). Here is an example bash command using the Scaleway provider: ```bash -SCALEWAY_API_TOKEN=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \ +SCW_SECRET_KEY=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \ lego --email you@example.com --dns scaleway --domains my.example.org run ``` @@ -37,8 +37,8 @@ lego --email you@example.com --dns scaleway --domains my.example.org run | Environment Variable Name | Description | |-----------------------|-------------| -| `SCALEWAY_API_TOKEN` | API token | -| `SCALEWAY_PROJECT_ID` | Project to use (optional) | +| `SCW_PROJECT_ID` | Project to use (optional) | +| `SCW_SECRET_KEY` | Secret key | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. More information [here]({{< ref "dns#configuration-and-credentials" >}}). @@ -48,9 +48,10 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}). | Environment Variable Name | Description | |--------------------------------|-------------| -| `SCALEWAY_POLLING_INTERVAL` | Time between DNS propagation check | -| `SCALEWAY_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | -| `SCALEWAY_TTL` | The TTL of the TXT record used for the DNS challenge | +| `SCW_ACCESS_KEY` | Access key | +| `SCW_POLLING_INTERVAL` | Time between DNS propagation check | +| `SCW_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | +| `SCW_TTL` | The TTL of the TXT record used for the DNS challenge | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. More information [here]({{< ref "dns#configuration-and-credentials" >}}). diff --git a/providers/dns/scaleway/scaleway.go b/providers/dns/scaleway/scaleway.go index f6f606f3..70b8a8ea 100644 --- a/providers/dns/scaleway/scaleway.go +++ b/providers/dns/scaleway/scaleway.go @@ -5,6 +5,8 @@ package scaleway import ( "errors" "fmt" + "strconv" + "strings" "time" "github.com/go-acme/lego/v4/challenge/dns01" @@ -19,6 +21,9 @@ const ( defaultPropagationTimeout = 120 * time.Second ) +// The access key is not used by the Scaleway client. +const dumpAccessKey = "SCWXXXXXXXXXXXXXXXXX" + // Environment variables names. const ( envNamespace = "SCALEWAY_" @@ -26,6 +31,11 @@ const ( EnvAPIToken = envNamespace + "API_TOKEN" EnvProjectID = envNamespace + "PROJECT_ID" + altEnvNamespace = "SCW_" + + EnvAccessKey = altEnvNamespace + "ACCESS_KEY" + EnvSecretKey = altEnvNamespace + "SECRET_KEY" + EnvTTL = envNamespace + "TTL" EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT" EnvPollingInterval = envNamespace + "POLLING_INTERVAL" @@ -34,7 +44,8 @@ const ( // Config is used to configure the creation of the DNSProvider. type Config struct { ProjectID string - Token string + Token string // TODO(ldez) rename to SecretKey in the next major. + AccessKey string PropagationTimeout time.Duration PollingInterval time.Duration TTL int @@ -43,9 +54,10 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ - TTL: env.GetOrDefaultInt(EnvTTL, minTTL), - PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, defaultPropagationTimeout), - PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, defaultPollingInterval), + AccessKey: dumpAccessKey, + TTL: env.GetOneWithFallback(EnvTTL, minTTL, strconv.Atoi, altEnvName(EnvTTL)), + PropagationTimeout: env.GetOneWithFallback(EnvPropagationTimeout, defaultPropagationTimeout, env.ParseSecond, altEnvName(EnvPropagationTimeout)), + PollingInterval: env.GetOneWithFallback(EnvPollingInterval, defaultPollingInterval, env.ParseSecond, altEnvName(EnvPollingInterval)), } } @@ -59,13 +71,14 @@ type DNSProvider struct { // Credentials must be passed in the environment variables: // SCALEWAY_API_TOKEN, SCALEWAY_PROJECT_ID. func NewDNSProvider() (*DNSProvider, error) { - values, err := env.Get(EnvAPIToken) + values, err := env.GetWithFallback([]string{EnvSecretKey, EnvAPIToken}) if err != nil { return nil, fmt.Errorf("scaleway: %w", err) } config := NewDefaultConfig() - config.Token = values[EnvAPIToken] + config.Token = values[EnvSecretKey] + config.AccessKey = env.GetOrDefaultString(EnvAccessKey, dumpAccessKey) config.ProjectID = env.GetOrFile(EnvProjectID) return NewDNSProviderConfig(config) @@ -86,7 +99,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { } configuration := []scw.ClientOption{ - scw.WithAuth("SCWXXXXXXXXXXXXXXXXX", config.Token), + scw.WithAuth(config.AccessKey, config.Token), scw.WithUserAgent("Scaleway Lego's provider"), } @@ -164,3 +177,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } + +func altEnvName(v string) string { + return strings.ReplaceAll(v, envNamespace, altEnvNamespace) +} diff --git a/providers/dns/scaleway/scaleway.toml b/providers/dns/scaleway/scaleway.toml index bbcdb75a..569c032f 100644 --- a/providers/dns/scaleway/scaleway.toml +++ b/providers/dns/scaleway/scaleway.toml @@ -5,18 +5,19 @@ Code = "scaleway" Since = "v3.4.0" Example = ''' -SCALEWAY_API_TOKEN=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \ +SCW_SECRET_KEY=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \ lego --email you@example.com --dns scaleway --domains my.example.org run ''' [Configuration] [Configuration.Credentials] - SCALEWAY_API_TOKEN = "API token" - SCALEWAY_PROJECT_ID = "Project to use (optional)" + SCW_SECRET_KEY = "Secret key" + SCW_PROJECT_ID = "Project to use (optional)" [Configuration.Additional] - SCALEWAY_POLLING_INTERVAL = "Time between DNS propagation check" - SCALEWAY_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" - SCALEWAY_TTL = "The TTL of the TXT record used for the DNS challenge" + SCW_ACCESS_KEY = "Access key" + SCW_POLLING_INTERVAL = "Time between DNS propagation check" + SCW_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" + SCW_TTL = "The TTL of the TXT record used for the DNS challenge" [Links] API = "https://developers.scaleway.com/en/products/domain/dns/api/" diff --git a/providers/dns/scaleway/scaleway_test.go b/providers/dns/scaleway/scaleway_test.go index 7dc8c06e..bf950e84 100644 --- a/providers/dns/scaleway/scaleway_test.go +++ b/providers/dns/scaleway/scaleway_test.go @@ -12,7 +12,7 @@ import ( const envDomain = envNamespace + "DOMAIN" -var envTest = tester.NewEnvTest(EnvAPIToken, EnvProjectID). +var envTest = tester.NewEnvTest(EnvAPIToken, EnvSecretKey, EnvAccessKey, EnvProjectID). WithDomain(envDomain) func TestNewDNSProvider(t *testing.T) { @@ -34,7 +34,7 @@ func TestNewDNSProvider(t *testing.T) { EnvAPIToken: "", EnvProjectID: "", }, - expected: fmt.Sprintf("scaleway: some credentials information are missing: %s", EnvAPIToken), + expected: fmt.Sprintf("scaleway: some credentials information are missing: %s", EnvSecretKey), }, }