fs: Debug the names of env vars we read values from as part of the config

See: https://forum.rclone.org/t/how-can-i-check-if-environment-variables-are-being-used/17490
This commit is contained in:
Nick Craig-Wood 2020-06-28 18:05:03 +01:00
parent 61ff7306ae
commit a76c9a1636
3 changed files with 23 additions and 8 deletions

View File

@ -172,7 +172,7 @@ func makeConfigPath() string {
// Check to see if user supplied a --config variable or environment
// variable. We can't use pflag for this because it isn't initialised
// yet so we search the command line manually.
_, configSupplied := os.LookupEnv("RCLONE_CONFIG")
_, configSupplied := fs.LookupEnv("RCLONE_CONFIG")
if !configSupplied {
for _, item := range os.Args {
if item == "--config" || strings.HasPrefix(item, "--config=") {
@ -311,7 +311,7 @@ func loadConfigFile() (*goconfig.ConfigFile, error) {
} else {
usingPasswordCommand = false
envpw := os.Getenv("RCLONE_CONFIG_PASS")
envpw := fs.Getenv("RCLONE_CONFIG_PASS")
if envpw != "" {
err := setConfigPassword(envpw)
@ -1432,7 +1432,7 @@ func FileGetFlag(section, key string) (string, bool) {
// It looks up defaults in the environment if they are present
func FileGet(section, key string, defaultVal ...string) string {
envKey := fs.ConfigToEnv(section, key)
newValue, found := os.LookupEnv(envKey)
newValue, found := fs.LookupEnv(envKey)
if found {
defaultVal = []string{newValue}
}

View File

@ -4,7 +4,6 @@ package flags
import (
"log"
"os"
"time"
"github.com/rclone/rclone/fs"
@ -15,7 +14,7 @@ import (
// sets the default from the environment if possible.
func setDefaultFromEnv(flags *pflag.FlagSet, name string) {
key := fs.OptionToEnv(name)
newValue, found := os.LookupEnv(key)
newValue, found := fs.LookupEnv(key)
if found {
flag := flags.Lookup(name)
if flag == nil {

View File

@ -1193,9 +1193,25 @@ func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err e
// A configmap.Getter to read from the environment RCLONE_CONFIG_backend_option_name
type configEnvVars string
// LookupEnv calls os.LookupEnv and Debugfs a message if the env var was found
func LookupEnv(key string) (value string, ok bool) {
value, ok = os.LookupEnv(key)
if ok {
Debugf(nil, "Read env var %s", key)
}
return value, ok
}
// Getenv calls os.LookupEnv and Debugfs a message if the env var was
// found. If the var wasn't round it returns empty string.
func Getenv(key string) (value string) {
value, _ = LookupEnv(key)
return value
}
// Get a config item from the environment variables if possible
func (configName configEnvVars) Get(key string) (value string, ok bool) {
return os.LookupEnv(ConfigToEnv(string(configName), key))
return LookupEnv(ConfigToEnv(string(configName), key))
}
// A configmap.Getter to read from the environment RCLONE_option_name
@ -1211,12 +1227,12 @@ func (oev optionEnvVars) Get(key string) (value string, ok bool) {
}
// For options with NoPrefix set, check without prefix too
if opt.NoPrefix {
value, ok = os.LookupEnv(OptionToEnv(key))
value, ok = LookupEnv(OptionToEnv(key))
if ok {
return value, ok
}
}
return os.LookupEnv(OptionToEnv(oev.fsInfo.Prefix + "-" + key))
return LookupEnv(OptionToEnv(oev.fsInfo.Prefix + "-" + key))
}
// A configmap.Getter to read either the default value or the set