lego: DNS providers: Don't return half-populated configs from environment
I’m trying to make DNS providers with a custom config, but pre-populating default values from environment variables.
For example, take the Cloudflare provider: https://pkg.go.dev/github.com/go-acme/lego/v3@v3.3.0/providers/dns/cloudflare?tab=doc - the env variable logic is split into two places: NewDefaultConfig() and NewDNSProvider(). But these functions can’t be used together!
Only NewDNSProvider() fills in default credentials from the environment, but it does not expose the config for further customization. So the config is only half-filled out, and we cannot use NewDefaultConfig() and NewDNSProvider() together.
If a default config was pre-populated from the environment and then returned from NewDefaultConfig(), this would make it possible for us to avoid putting DNS provider credentials in app config files. It’d be nice to call just one function and get a config that is filled out all the way from the environment. Otherwise, we’ll have to copy+paste and repeat the env variable logic for every DNS provider that does this in our own applications. 😢
So, could we move all the environment variable logic into NewDefaultConfig() rather than having it split in two places like it is now? 😁
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (18 by maintainers)
Commits related to this issue
- httpcaddyfile: Add support for DNS challenge solvers Configuration via the Caddyfile requires use of env variables, but an upstream issue is currently blocking that: https://github.com/go-acme/lego/i... — committed to caddyserver/caddy by mholt 4 years ago
- cloudflare, digitalocean, dnsimple: Implement NewConfigFromEnv() This allows getting a config populated from env variables. Without this, the only way to do this is to copy/duplicate all the env var ... — committed to mholt/lego by mholt 4 years ago
ok so just create a function
NewConfigFromEnv()who callNewDefaultConfig()so I propose to:
NewCommonConfig()NewDefaultConfig()and callNewCommonConfig()inside this functionNewConfigFromEnv()who callNewCommonConfig()