Skip to content

Commit 27fd142

Browse files
authored
scaleway: add alternative env var names (go-acme#2136)
1 parent 61553c4 commit 27fd142

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- **[dnsprovider]** Add DNS provider for Shellrent
1414
- **[dnsprovider]** Add DNS provider for Mail-in-a-Box
1515
- **[dnsprovider]** Add DNS provider for CPanel and WHM
16-
-
16+
1717
### Changed
1818

1919
- **[lib,ari]** Implement 'replaces' field in newOrder and draft-ietf-acme-ari-03 CertID changes

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,14 +2363,15 @@ func displayDNSHelp(w io.Writer, name string) error {
23632363
ew.writeln()
23642364

23652365
ew.writeln(`Credentials:`)
2366-
ew.writeln(` - "SCALEWAY_API_TOKEN": API token`)
2367-
ew.writeln(` - "SCALEWAY_PROJECT_ID": Project to use (optional)`)
2366+
ew.writeln(` - "SCW_PROJECT_ID": Project to use (optional)`)
2367+
ew.writeln(` - "SCW_SECRET_KEY": Secret key`)
23682368
ew.writeln()
23692369

23702370
ew.writeln(`Additional Configuration:`)
2371-
ew.writeln(` - "SCALEWAY_POLLING_INTERVAL": Time between DNS propagation check`)
2372-
ew.writeln(` - "SCALEWAY_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
2373-
ew.writeln(` - "SCALEWAY_TTL": The TTL of the TXT record used for the DNS challenge`)
2371+
ew.writeln(` - "SCW_ACCESS_KEY": Access key`)
2372+
ew.writeln(` - "SCW_POLLING_INTERVAL": Time between DNS propagation check`)
2373+
ew.writeln(` - "SCW_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
2374+
ew.writeln(` - "SCW_TTL": The TTL of the TXT record used for the DNS challenge`)
23742375

23752376
ew.writeln()
23762377
ew.writeln(`More information: https://go-acme.github.io/lego/dns/scaleway`)

docs/content/dns/zz_gen_scaleway.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Configuration for [Scaleway](https://developers.scaleway.com/).
2626
Here is an example bash command using the Scaleway provider:
2727

2828
```bash
29-
SCALEWAY_API_TOKEN=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \
29+
SCW_SECRET_KEY=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \
3030
lego --email [email protected] --dns scaleway --domains my.example.org run
3131
```
3232

@@ -37,8 +37,8 @@ lego --email [email protected] --dns scaleway --domains my.example.org run
3737

3838
| Environment Variable Name | Description |
3939
|-----------------------|-------------|
40-
| `SCALEWAY_API_TOKEN` | API token |
41-
| `SCALEWAY_PROJECT_ID` | Project to use (optional) |
40+
| `SCW_PROJECT_ID` | Project to use (optional) |
41+
| `SCW_SECRET_KEY` | Secret key |
4242

4343
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
4444
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
@@ -48,9 +48,10 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
4848

4949
| Environment Variable Name | Description |
5050
|--------------------------------|-------------|
51-
| `SCALEWAY_POLLING_INTERVAL` | Time between DNS propagation check |
52-
| `SCALEWAY_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
53-
| `SCALEWAY_TTL` | The TTL of the TXT record used for the DNS challenge |
51+
| `SCW_ACCESS_KEY` | Access key |
52+
| `SCW_POLLING_INTERVAL` | Time between DNS propagation check |
53+
| `SCW_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
54+
| `SCW_TTL` | The TTL of the TXT record used for the DNS challenge |
5455

5556
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
5657
More information [here]({{< ref "dns#configuration-and-credentials" >}}).

providers/dns/scaleway/scaleway.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package scaleway
55
import (
66
"errors"
77
"fmt"
8+
"strconv"
9+
"strings"
810
"time"
911

1012
"github.com/go-acme/lego/v4/challenge/dns01"
@@ -19,13 +21,21 @@ const (
1921
defaultPropagationTimeout = 120 * time.Second
2022
)
2123

24+
// The access key is not used by the Scaleway client.
25+
const dumpAccessKey = "SCWXXXXXXXXXXXXXXXXX"
26+
2227
// Environment variables names.
2328
const (
2429
envNamespace = "SCALEWAY_"
2530

2631
EnvAPIToken = envNamespace + "API_TOKEN"
2732
EnvProjectID = envNamespace + "PROJECT_ID"
2833

34+
altEnvNamespace = "SCW_"
35+
36+
EnvAccessKey = altEnvNamespace + "ACCESS_KEY"
37+
EnvSecretKey = altEnvNamespace + "SECRET_KEY"
38+
2939
EnvTTL = envNamespace + "TTL"
3040
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
3141
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
@@ -34,7 +44,8 @@ const (
3444
// Config is used to configure the creation of the DNSProvider.
3545
type Config struct {
3646
ProjectID string
37-
Token string
47+
Token string // TODO(ldez) rename to SecretKey in the next major.
48+
AccessKey string
3849
PropagationTimeout time.Duration
3950
PollingInterval time.Duration
4051
TTL int
@@ -43,9 +54,10 @@ type Config struct {
4354
// NewDefaultConfig returns a default configuration for the DNSProvider.
4455
func NewDefaultConfig() *Config {
4556
return &Config{
46-
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
47-
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, defaultPropagationTimeout),
48-
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, defaultPollingInterval),
57+
AccessKey: dumpAccessKey,
58+
TTL: env.GetOneWithFallback(EnvTTL, minTTL, strconv.Atoi, altEnvName(EnvTTL)),
59+
PropagationTimeout: env.GetOneWithFallback(EnvPropagationTimeout, defaultPropagationTimeout, env.ParseSecond, altEnvName(EnvPropagationTimeout)),
60+
PollingInterval: env.GetOneWithFallback(EnvPollingInterval, defaultPollingInterval, env.ParseSecond, altEnvName(EnvPollingInterval)),
4961
}
5062
}
5163

@@ -59,13 +71,14 @@ type DNSProvider struct {
5971
// Credentials must be passed in the environment variables:
6072
// SCALEWAY_API_TOKEN, SCALEWAY_PROJECT_ID.
6173
func NewDNSProvider() (*DNSProvider, error) {
62-
values, err := env.Get(EnvAPIToken)
74+
values, err := env.GetWithFallback([]string{EnvSecretKey, EnvAPIToken})
6375
if err != nil {
6476
return nil, fmt.Errorf("scaleway: %w", err)
6577
}
6678

6779
config := NewDefaultConfig()
68-
config.Token = values[EnvAPIToken]
80+
config.Token = values[EnvSecretKey]
81+
config.AccessKey = env.GetOrDefaultString(EnvAccessKey, dumpAccessKey)
6982
config.ProjectID = env.GetOrFile(EnvProjectID)
7083

7184
return NewDNSProviderConfig(config)
@@ -86,7 +99,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
8699
}
87100

88101
configuration := []scw.ClientOption{
89-
scw.WithAuth("SCWXXXXXXXXXXXXXXXXX", config.Token),
102+
scw.WithAuth(config.AccessKey, config.Token),
90103
scw.WithUserAgent("Scaleway Lego's provider"),
91104
}
92105

@@ -164,3 +177,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
164177

165178
return nil
166179
}
180+
181+
func altEnvName(v string) string {
182+
return strings.ReplaceAll(v, envNamespace, altEnvNamespace)
183+
}

providers/dns/scaleway/scaleway.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ Code = "scaleway"
55
Since = "v3.4.0"
66

77
Example = '''
8-
SCALEWAY_API_TOKEN=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \
8+
SCW_SECRET_KEY=xxxxxxx-xxxxx-xxxx-xxx-xxxxxx \
99
lego --email [email protected] --dns scaleway --domains my.example.org run
1010
'''
1111

1212
[Configuration]
1313
[Configuration.Credentials]
14-
SCALEWAY_API_TOKEN = "API token"
15-
SCALEWAY_PROJECT_ID = "Project to use (optional)"
14+
SCW_SECRET_KEY = "Secret key"
15+
SCW_PROJECT_ID = "Project to use (optional)"
1616
[Configuration.Additional]
17-
SCALEWAY_POLLING_INTERVAL = "Time between DNS propagation check"
18-
SCALEWAY_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
19-
SCALEWAY_TTL = "The TTL of the TXT record used for the DNS challenge"
17+
SCW_ACCESS_KEY = "Access key"
18+
SCW_POLLING_INTERVAL = "Time between DNS propagation check"
19+
SCW_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
20+
SCW_TTL = "The TTL of the TXT record used for the DNS challenge"
2021

2122
[Links]
2223
API = "https://developers.scaleway.com/en/products/domain/dns/api/"

providers/dns/scaleway/scaleway_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const envDomain = envNamespace + "DOMAIN"
1414

15-
var envTest = tester.NewEnvTest(EnvAPIToken, EnvProjectID).
15+
var envTest = tester.NewEnvTest(EnvAPIToken, EnvSecretKey, EnvAccessKey, EnvProjectID).
1616
WithDomain(envDomain)
1717

1818
func TestNewDNSProvider(t *testing.T) {
@@ -34,7 +34,7 @@ func TestNewDNSProvider(t *testing.T) {
3434
EnvAPIToken: "",
3535
EnvProjectID: "",
3636
},
37-
expected: fmt.Sprintf("scaleway: some credentials information are missing: %s", EnvAPIToken),
37+
expected: fmt.Sprintf("scaleway: some credentials information are missing: %s", EnvSecretKey),
3838
},
3939
}
4040

0 commit comments

Comments
 (0)