Emit warnings about deprecated settings [#10]

These aren't an error case--the plugin will work just fine--but users
should be aware they (the settings) aren't being respected.
This commit is contained in:
Erin Call
2019-12-31 10:03:53 -08:00
parent 353bd76f8f
commit 7cd46bb8b1
3 changed files with 38 additions and 2 deletions

View File

@@ -4,10 +4,15 @@ import (
"fmt"
"github.com/kelseyhightower/envconfig"
"io"
"os"
"regexp"
"strings"
)
var justNumbers = regexp.MustCompile(`^\d+$`)
var (
justNumbers = regexp.MustCompile(`^\d+$`)
deprecatedVars = []string{"PURGE", "RECREATE_PODS", "TILLER_NS", "UPGRADE", "CANARY_IMAGE", "CLIENT_ONLY", "STABLE_REPO_URL"}
)
// The Config struct captures the `settings` and `environment` blocks in the application's drone
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
@@ -73,6 +78,8 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
cfg.logDebug()
}
cfg.deprecationWarn()
return &cfg, nil
}
@@ -82,3 +89,13 @@ func (cfg Config) logDebug() {
}
fmt.Fprintf(cfg.Stderr, "Generated config: %+v\n", cfg)
}
func (cfg *Config) deprecationWarn() {
for _, varname := range deprecatedVars {
_, barePresent := os.LookupEnv(varname)
_, prefixedPresent := os.LookupEnv("PLUGIN_" + varname)
if barePresent || prefixedPresent {
fmt.Fprintf(cfg.Stderr, "Warning: ignoring deprecated '%s' setting\n", strings.ToLower(varname))
}
}
}