Skip to content

Commit

Permalink
scaleway: add alternative env var names (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Mar 20, 2024
1 parent 61553c4 commit 27fd142
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
13 changes: 7 additions & 6 deletions docs/content/dns/zz_gen_scaleway.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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" >}}).
Expand All @@ -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" >}}).
Expand Down
31 changes: 24 additions & 7 deletions providers/dns/scaleway/scaleway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package scaleway
import (
"errors"
"fmt"
"strconv"
"strings"
"time"

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

// The access key is not used by the Scaleway client.
const dumpAccessKey = "SCWXXXXXXXXXXXXXXXXX"

// Environment variables names.
const (
envNamespace = "SCALEWAY_"

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

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

Expand Down Expand Up @@ -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)
}
13 changes: 7 additions & 6 deletions providers/dns/scaleway/scaleway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
4 changes: 2 additions & 2 deletions providers/dns/scaleway/scaleway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
},
}

Expand Down

0 comments on commit 27fd142

Please sign in to comment.