mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Honor envs properly for access and secret key. (#3703)
Also changes the behavior of `secretKeyHash` which is not necessary to be sent over the network, each node has its own secretKeyHash to validate. Fixes #3696 Partial(fix) #3700 (More changes needed with some code cleanup)
This commit is contained in:
47
cmd/main.go
47
cmd/main.go
@@ -163,6 +163,29 @@ func checkUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes a new config if it doesn't exist, else migrates any old config
|
||||
// to newer config and finally loads the config to memory.
|
||||
func initConfig() {
|
||||
envCreds := mustGetCredentialFromEnv()
|
||||
|
||||
// Config file does not exist, we create it fresh and return upon success.
|
||||
if !isConfigFileExists() {
|
||||
if err := newConfig(envCreds); err != nil {
|
||||
console.Fatalf("Unable to initialize minio config for the first time. Err: %s.\n", err)
|
||||
}
|
||||
console.Println("Created minio configuration file successfully at " + mustGetConfigPath())
|
||||
return
|
||||
}
|
||||
|
||||
// Migrate any old version of config / state files to newer format.
|
||||
migrate()
|
||||
|
||||
// Once we have migrated all the old config, now load them.
|
||||
if err := loadConfig(envCreds); err != nil {
|
||||
console.Fatalf("Unable to initialize minio config. Err: %s.\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Generic Minio initialization to create/load config, prepare loggers, etc..
|
||||
func minioInit(ctx *cli.Context) {
|
||||
// Set global variables after parsing passed arguments
|
||||
@@ -174,32 +197,12 @@ func minioInit(ctx *cli.Context) {
|
||||
// Is TLS configured?.
|
||||
globalIsSSL = isSSL()
|
||||
|
||||
// Migrate any old version of config / state files to newer format.
|
||||
migrate()
|
||||
|
||||
// Initialize config.
|
||||
configCreated, err := initConfig()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to initialize minio config. Err: %s.\n", err)
|
||||
}
|
||||
if configCreated {
|
||||
console.Println("Created minio configuration file at " + mustGetConfigPath())
|
||||
}
|
||||
// Initialize minio server config.
|
||||
initConfig()
|
||||
|
||||
// Enable all loggers by now so we can use errorIf() and fatalIf()
|
||||
enableLoggers()
|
||||
|
||||
// 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 != "" {
|
||||
creds, err := getCredential(accessKey, secretKey)
|
||||
fatalIf(err, "Credentials are invalid, please set proper credentials `minio server --help`")
|
||||
|
||||
// Set new credentials.
|
||||
serverConfig.SetCredential(creds)
|
||||
}
|
||||
|
||||
// Init the error tracing module.
|
||||
initError()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user