mirror of
https://github.com/minio/minio.git
synced 2025-01-24 13:13:16 -05:00
Properly load creds from env and save them when server cmd is executed (#2970)
This commit is contained in:
parent
0f26ec8095
commit
2005d656e6
17
cmd/main.go
17
cmd/main.go
@ -174,6 +174,23 @@ func Main() {
|
||||
err := initConfig()
|
||||
fatalIf(err, "Unable to initialize minio config.")
|
||||
|
||||
// Fetch access keys from environment variables and update the config.
|
||||
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
||||
secretKey := os.Getenv("MINIO_SECRET_KEY")
|
||||
if accessKey != "" && secretKey != "" {
|
||||
if !isValidAccessKey.MatchString(accessKey) {
|
||||
fatalIf(errInvalidArgument, "Invalid access key.")
|
||||
}
|
||||
if !isValidSecretKey.MatchString(secretKey) {
|
||||
fatalIf(errInvalidArgument, "Invalid secret key.")
|
||||
}
|
||||
// Set new credentials.
|
||||
serverConfig.SetCredential(credential{
|
||||
AccessKeyID: accessKey,
|
||||
SecretAccessKey: secretKey,
|
||||
})
|
||||
}
|
||||
|
||||
// Enable all loggers by now.
|
||||
enableLoggers()
|
||||
|
||||
|
@ -174,28 +174,11 @@ func initServerConfig(c *cli.Context) {
|
||||
fatalIf(err, "Unable to convert MINIO_CACHE_EXPIRY=%s environment variable into its time.Duration value.", cacheExpiryStr)
|
||||
}
|
||||
|
||||
// Fetch access keys from environment variables if any and update the config.
|
||||
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
||||
secretKey := os.Getenv("MINIO_SECRET_KEY")
|
||||
|
||||
// Validate if both keys are specified and they are valid save them.
|
||||
if accessKey != "" && secretKey != "" {
|
||||
if !isValidAccessKey.MatchString(accessKey) {
|
||||
fatalIf(errInvalidArgument, "Invalid access key.")
|
||||
}
|
||||
if !isValidSecretKey.MatchString(secretKey) {
|
||||
fatalIf(errInvalidArgument, "Invalid secret key.")
|
||||
}
|
||||
|
||||
// Set new credentials.
|
||||
serverConfig.SetCredential(credential{
|
||||
AccessKeyID: accessKey,
|
||||
SecretAccessKey: secretKey,
|
||||
})
|
||||
|
||||
// Save new config.
|
||||
// When credentials inherited from the env, server cmd has to save them in the disk
|
||||
if os.Getenv("MINIO_ACCESS_KEY") != "" && os.Getenv("MINIO_SECRET_KEY") != "" {
|
||||
// Env credentials are already loaded in serverConfig, just save in the disk
|
||||
err = serverConfig.Save()
|
||||
fatalIf(err, "Unable to save config.")
|
||||
fatalIf(err, "Unable to save credentials in the disk.")
|
||||
}
|
||||
|
||||
// Set maxOpenFiles, This is necessary since default operating
|
||||
|
Loading…
x
Reference in New Issue
Block a user