scaleway: add alternative env var names (#2136)

This commit is contained in:
Ludovic Fernandez 2024-03-20 04:31:18 +01:00 committed by GitHub
parent 61553c4195
commit 27fd142ca1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 47 additions and 27 deletions

View file

@ -13,7 +13,7 @@
- **[dnsprovider]** Add DNS provider for Shellrent - **[dnsprovider]** Add DNS provider for Shellrent
- **[dnsprovider]** Add DNS provider for Mail-in-a-Box - **[dnsprovider]** Add DNS provider for Mail-in-a-Box
- **[dnsprovider]** Add DNS provider for CPanel and WHM - **[dnsprovider]** Add DNS provider for CPanel and WHM
-
### Changed ### Changed
- **[lib,ari]** Implement 'replaces' field in newOrder and draft-ietf-acme-ari-03 CertID changes - **[lib,ari]** Implement 'replaces' field in newOrder and draft-ietf-acme-ari-03 CertID changes

View file

@ -2363,14 +2363,15 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln() ew.writeln()
ew.writeln(`Credentials:`) ew.writeln(`Credentials:`)
ew.writeln(` - "SCALEWAY_API_TOKEN": API token`) ew.writeln(` - "SCW_PROJECT_ID": Project to use (optional)`)
ew.writeln(` - "SCALEWAY_PROJECT_ID": Project to use (optional)`) ew.writeln(` - "SCW_SECRET_KEY": Secret key`)
ew.writeln() ew.writeln()
ew.writeln(`Additional Configuration:`) ew.writeln(`Additional Configuration:`)
ew.writeln(` - "SCALEWAY_POLLING_INTERVAL": Time between DNS propagation check`) ew.writeln(` - "SCW_ACCESS_KEY": Access key`)
ew.writeln(` - "SCALEWAY_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) ew.writeln(` - "SCW_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "SCALEWAY_TTL": The TTL of the TXT record used for the DNS challenge`) 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()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/scaleway`) ew.writeln(`More information: https://go-acme.github.io/lego/dns/scaleway`)

View file

@ -26,7 +26,7 @@ Configuration for [Scaleway](https://developers.scaleway.com/).
Here is an example bash command using the Scaleway provider: Here is an example bash command using the Scaleway provider:
```bash ```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 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 | | Environment Variable Name | Description |
|-----------------------|-------------| |-----------------------|-------------|
| `SCALEWAY_API_TOKEN` | API token | | `SCW_PROJECT_ID` | Project to use (optional) |
| `SCALEWAY_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. 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" >}}). More information [here]({{< ref "dns#configuration-and-credentials" >}}).
@ -48,9 +48,10 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
| Environment Variable Name | Description | | Environment Variable Name | Description |
|--------------------------------|-------------| |--------------------------------|-------------|
| `SCALEWAY_POLLING_INTERVAL` | Time between DNS propagation check | | `SCW_ACCESS_KEY` | Access key |
| `SCALEWAY_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | `SCW_POLLING_INTERVAL` | Time between DNS propagation check |
| `SCALEWAY_TTL` | The TTL of the TXT record used for the DNS challenge | | `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. 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" >}}). More information [here]({{< ref "dns#configuration-and-credentials" >}}).

View file

@ -5,6 +5,8 @@ package scaleway
import ( import (
"errors" "errors"
"fmt" "fmt"
"strconv"
"strings"
"time" "time"
"github.com/go-acme/lego/v4/challenge/dns01" "github.com/go-acme/lego/v4/challenge/dns01"
@ -19,6 +21,9 @@ const (
defaultPropagationTimeout = 120 * time.Second defaultPropagationTimeout = 120 * time.Second
) )
// The access key is not used by the Scaleway client.
const dumpAccessKey = "SCWXXXXXXXXXXXXXXXXX"
// Environment variables names. // Environment variables names.
const ( const (
envNamespace = "SCALEWAY_" envNamespace = "SCALEWAY_"
@ -26,6 +31,11 @@ const (
EnvAPIToken = envNamespace + "API_TOKEN" EnvAPIToken = envNamespace + "API_TOKEN"
EnvProjectID = envNamespace + "PROJECT_ID" EnvProjectID = envNamespace + "PROJECT_ID"
altEnvNamespace = "SCW_"
EnvAccessKey = altEnvNamespace + "ACCESS_KEY"
EnvSecretKey = altEnvNamespace + "SECRET_KEY"
EnvTTL = envNamespace + "TTL" EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT" EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL" EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
@ -34,7 +44,8 @@ const (
// 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 {
ProjectID string ProjectID string
Token string Token string // TODO(ldez) rename to SecretKey in the next major.
AccessKey string
PropagationTimeout time.Duration PropagationTimeout time.Duration
PollingInterval time.Duration PollingInterval time.Duration
TTL int TTL int
@ -43,9 +54,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(EnvTTL, minTTL), AccessKey: dumpAccessKey,
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, defaultPropagationTimeout), TTL: env.GetOneWithFallback(EnvTTL, minTTL, strconv.Atoi, altEnvName(EnvTTL)),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, defaultPollingInterval), 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: // Credentials must be passed in the environment variables:
// SCALEWAY_API_TOKEN, SCALEWAY_PROJECT_ID. // SCALEWAY_API_TOKEN, SCALEWAY_PROJECT_ID.
func NewDNSProvider() (*DNSProvider, error) { func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvAPIToken) values, err := env.GetWithFallback([]string{EnvSecretKey, EnvAPIToken})
if err != nil { if err != nil {
return nil, fmt.Errorf("scaleway: %w", err) return nil, fmt.Errorf("scaleway: %w", err)
} }
config := NewDefaultConfig() config := NewDefaultConfig()
config.Token = values[EnvAPIToken] config.Token = values[EnvSecretKey]
config.AccessKey = env.GetOrDefaultString(EnvAccessKey, dumpAccessKey)
config.ProjectID = env.GetOrFile(EnvProjectID) config.ProjectID = env.GetOrFile(EnvProjectID)
return NewDNSProviderConfig(config) return NewDNSProviderConfig(config)
@ -86,7 +99,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
} }
configuration := []scw.ClientOption{ configuration := []scw.ClientOption{
scw.WithAuth("SCWXXXXXXXXXXXXXXXXX", config.Token), scw.WithAuth(config.AccessKey, config.Token),
scw.WithUserAgent("Scaleway Lego's provider"), scw.WithUserAgent("Scaleway Lego's provider"),
} }
@ -164,3 +177,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return nil return nil
} }
func altEnvName(v string) string {
return strings.ReplaceAll(v, envNamespace, altEnvNamespace)
}

View file

@ -5,18 +5,19 @@ Code = "scaleway"
Since = "v3.4.0" Since = "v3.4.0"
Example = ''' 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 lego --email you@example.com --dns scaleway --domains my.example.org run
''' '''
[Configuration] [Configuration]
[Configuration.Credentials] [Configuration.Credentials]
SCALEWAY_API_TOKEN = "API token" SCW_SECRET_KEY = "Secret key"
SCALEWAY_PROJECT_ID = "Project to use (optional)" SCW_PROJECT_ID = "Project to use (optional)"
[Configuration.Additional] [Configuration.Additional]
SCALEWAY_POLLING_INTERVAL = "Time between DNS propagation check" SCW_ACCESS_KEY = "Access key"
SCALEWAY_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" SCW_POLLING_INTERVAL = "Time between DNS propagation check"
SCALEWAY_TTL = "The TTL of the TXT record used for the DNS challenge" SCW_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
SCW_TTL = "The TTL of the TXT record used for the DNS challenge"
[Links] [Links]
API = "https://developers.scaleway.com/en/products/domain/dns/api/" API = "https://developers.scaleway.com/en/products/domain/dns/api/"

View file

@ -12,7 +12,7 @@ import (
const envDomain = envNamespace + "DOMAIN" const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest(EnvAPIToken, EnvProjectID). var envTest = tester.NewEnvTest(EnvAPIToken, EnvSecretKey, EnvAccessKey, EnvProjectID).
WithDomain(envDomain) WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) { func TestNewDNSProvider(t *testing.T) {
@ -34,7 +34,7 @@ func TestNewDNSProvider(t *testing.T) {
EnvAPIToken: "", EnvAPIToken: "",
EnvProjectID: "", EnvProjectID: "",
}, },
expected: fmt.Sprintf("scaleway: some credentials information are missing: %s", EnvAPIToken), expected: fmt.Sprintf("scaleway: some credentials information are missing: %s", EnvSecretKey),
}, },
} }