Retrieve acessKey/secretKey from the environment first

This commit is contained in:
Anis Elleuch
2016-03-28 19:36:13 +01:00
parent a02ae19de2
commit 13a4133da5
+27 -2
View File
@@ -23,6 +23,7 @@ import (
"runtime"
"strings"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/probe"
)
@@ -113,8 +114,32 @@ func newClientFromAlias(alias string, urlStr string) (Client, *probe.Error) {
// We have a valid alias and hostConfig. We populate the
// credentials from the match found in the config file.
s3Config := new(Config)
s3Config.AccessKey = hostCfg.AccessKey
s3Config.SecretKey = hostCfg.SecretKey
// secretKey retrieved from the environement overrides the one
// present in the config file
keysPairEnv := os.Getenv("MC_SECRET_" + alias)
keysPairArray := strings.Split(keysPairEnv, ":")
var accessKeyEnv, secretKeyEnv string
if len(keysPairArray) >= 1 {
accessKeyEnv = keysPairArray[0]
}
if len(keysPairArray) >= 2 {
secretKeyEnv = keysPairArray[1]
}
if len(keysPairEnv) > 0 &&
isValidAccessKey(accessKeyEnv) && isValidSecretKey(secretKeyEnv) {
s3Config.AccessKey = accessKeyEnv
s3Config.SecretKey = secretKeyEnv
} else {
if len(keysPairEnv) > 0 {
console.Errorln("Access/Secret keys associated to `" + alias + "' " +
"are found in your environment but not suitable for use. " +
"Falling back to the standard config.")
}
s3Config.AccessKey = hostCfg.AccessKey
s3Config.SecretKey = hostCfg.SecretKey
}
s3Config.Signature = hostCfg.API
s3Config.AppName = "mc"
s3Config.AppVersion = mcVersion