|
|
@ -17,6 +17,7 @@ |
|
|
|
package cmd |
|
|
|
package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
"sync" |
|
|
@ -27,6 +28,9 @@ import ( |
|
|
|
// Read Write mutex for safe access to ServerConfig.
|
|
|
|
// Read Write mutex for safe access to ServerConfig.
|
|
|
|
var serverConfigMu sync.RWMutex |
|
|
|
var serverConfigMu sync.RWMutex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Config version
|
|
|
|
|
|
|
|
var v14 = "14" |
|
|
|
|
|
|
|
|
|
|
|
// serverConfigV14 server configuration version '14' which is like
|
|
|
|
// serverConfigV14 server configuration version '14' which is like
|
|
|
|
// version '13' except it adds support of browser param.
|
|
|
|
// version '13' except it adds support of browser param.
|
|
|
|
type serverConfigV14 struct { |
|
|
|
type serverConfigV14 struct { |
|
|
@ -44,30 +48,15 @@ type serverConfigV14 struct { |
|
|
|
Notify *notifier `json:"notify"` |
|
|
|
Notify *notifier `json:"notify"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// newConfig - initialize a new server config, saves env parameters if
|
|
|
|
func newServerConfigV14() *serverConfigV14 { |
|
|
|
// found, otherwise use default parameters
|
|
|
|
|
|
|
|
func newConfig(envParams envParams) error { |
|
|
|
|
|
|
|
// Initialize server config.
|
|
|
|
|
|
|
|
srvCfg := &serverConfigV14{ |
|
|
|
srvCfg := &serverConfigV14{ |
|
|
|
|
|
|
|
Version: v14, |
|
|
|
|
|
|
|
Region: globalMinioDefaultRegion, |
|
|
|
Logger: &logger{}, |
|
|
|
Logger: &logger{}, |
|
|
|
Notify: ¬ifier{}, |
|
|
|
Notify: ¬ifier{}, |
|
|
|
} |
|
|
|
} |
|
|
|
srvCfg.Version = globalMinioConfigVersion |
|
|
|
|
|
|
|
srvCfg.Region = globalMinioDefaultRegion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If env is set for a fresh start, save them to config file.
|
|
|
|
|
|
|
|
if globalIsEnvCreds { |
|
|
|
|
|
|
|
srvCfg.SetCredential(envParams.creds) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
srvCfg.SetCredential(newCredential()) |
|
|
|
srvCfg.SetCredential(newCredential()) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if globalIsEnvBrowser { |
|
|
|
|
|
|
|
srvCfg.SetBrowser(envParams.browser) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
srvCfg.SetBrowser("on") |
|
|
|
srvCfg.SetBrowser("on") |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Enable console logger by default on a fresh run.
|
|
|
|
// Enable console logger by default on a fresh run.
|
|
|
|
srvCfg.Logger.Console = consoleLogger{ |
|
|
|
srvCfg.Logger.Console = consoleLogger{ |
|
|
|
Enable: true, |
|
|
|
Enable: true, |
|
|
@ -90,6 +79,24 @@ func newConfig(envParams envParams) error { |
|
|
|
srvCfg.Notify.Webhook = make(map[string]webhookNotify) |
|
|
|
srvCfg.Notify.Webhook = make(map[string]webhookNotify) |
|
|
|
srvCfg.Notify.Webhook["1"] = webhookNotify{} |
|
|
|
srvCfg.Notify.Webhook["1"] = webhookNotify{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return srvCfg |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// newConfig - initialize a new server config, saves env parameters if
|
|
|
|
|
|
|
|
// found, otherwise use default parameters
|
|
|
|
|
|
|
|
func newConfig(envParams envParams) error { |
|
|
|
|
|
|
|
// Initialize server config.
|
|
|
|
|
|
|
|
srvCfg := newServerConfigV14() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If env is set for a fresh start, save them to config file.
|
|
|
|
|
|
|
|
if globalIsEnvCreds { |
|
|
|
|
|
|
|
srvCfg.SetCredential(envParams.creds) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if globalIsEnvBrowser { |
|
|
|
|
|
|
|
srvCfg.SetBrowser(envParams.browser) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create config path.
|
|
|
|
// Create config path.
|
|
|
|
if err := createConfigPath(); err != nil { |
|
|
|
if err := createConfigPath(); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
@ -117,8 +124,9 @@ func loadConfig(envParams envParams) error { |
|
|
|
if _, err = os.Stat(configFile); err != nil { |
|
|
|
if _, err = os.Stat(configFile); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
srvCfg := &serverConfigV14{} |
|
|
|
srvCfg := &serverConfigV14{} |
|
|
|
srvCfg.Version = globalMinioConfigVersion |
|
|
|
|
|
|
|
qc, err := quick.New(srvCfg) |
|
|
|
qc, err := quick.New(srvCfg) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
@ -131,8 +139,6 @@ func loadConfig(envParams envParams) error { |
|
|
|
// If env is set override the credentials from config file.
|
|
|
|
// If env is set override the credentials from config file.
|
|
|
|
if globalIsEnvCreds { |
|
|
|
if globalIsEnvCreds { |
|
|
|
srvCfg.SetCredential(envParams.creds) |
|
|
|
srvCfg.SetCredential(envParams.creds) |
|
|
|
} else { |
|
|
|
|
|
|
|
srvCfg.SetCredential(srvCfg.Credential) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if globalIsEnvBrowser { |
|
|
|
if globalIsEnvBrowser { |
|
|
@ -149,8 +155,10 @@ func loadConfig(envParams envParams) error { |
|
|
|
serverConfig = srvCfg |
|
|
|
serverConfig = srvCfg |
|
|
|
serverConfigMu.Unlock() |
|
|
|
serverConfigMu.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
// Set the version properly after the unmarshalled json is loaded.
|
|
|
|
if serverConfig.Version != v14 { |
|
|
|
serverConfig.Version = globalMinioConfigVersion |
|
|
|
return errors.New("Unsupported config version `" + serverConfig.Version + "`.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|