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 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

View file

@ -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`)

View file

@ -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" >}}).

View file

@ -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)
}

View file

@ -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/"

View file

@ -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),
},
}