1
0
Fork 0
mirror of https://github.com/Luzifer/vault-openvpn.git synced 2024-12-25 22:31:20 +00:00

Use a replacer to convert dashes

this enables setting all flags through ENV variables

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-06-14 16:01:41 +02:00
parent a0b26ea1ae
commit 47d94f072a
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"time" "time"
"github.com/hashicorp/vault/api" "github.com/hashicorp/vault/api"
@ -80,8 +81,7 @@ func init() {
RootCmd.PersistentFlags().StringVar(&cfg.LogLevel, "log-level", "info", "Log level to use (debug, info, warning, error)") RootCmd.PersistentFlags().StringVar(&cfg.LogLevel, "log-level", "info", "Log level to use (debug, info, warning, error)")
viper.BindPFlags(RootCmd.PersistentFlags()) viper.BindPFlags(RootCmd.PersistentFlags())
viper.BindEnv("vault-addr", "VAULT_ADDR") viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.BindEnv("vault-token", "VAULT_TOKEN")
if tok := vaultTokenFromDisk(); tok != "" { if tok := vaultTokenFromDisk(); tok != "" {
viper.SetDefault("vault-token", tok) viper.SetDefault("vault-token", tok)