server: Introduce a new env MINIO_REGION. (#4078)

This is implemented to be able to override region
through command line just like how access and
secret keys are provided.
master
Harshavardhana 7 years ago committed by GitHub
parent 604417baf4
commit b927523223
  1. 12
      cmd/config-v18.go
  2. 14
      cmd/config-v18_test.go
  3. 6
      cmd/globals.go
  4. 7
      cmd/server-main.go
  5. 2
      cmd/test-utils_test.go

@ -170,6 +170,10 @@ func newConfig() error {
srvCfg.SetBrowser(globalIsBrowserEnabled)
}
if globalIsEnvRegion {
srvCfg.SetRegion(globalServerRegion)
}
// hold the mutex lock before a new config is assigned.
// Save the new config globally.
// unlock the mutex.
@ -295,10 +299,15 @@ func loadConfig() error {
if globalIsEnvCreds {
srvCfg.SetCredential(globalActiveCred)
}
if globalIsEnvBrowser {
srvCfg.SetBrowser(globalIsBrowserEnabled)
}
if globalIsEnvRegion {
srvCfg.SetRegion(globalServerRegion)
}
// hold the mutex lock before a new config is assigned.
serverConfigMu.Lock()
serverConfig = srvCfg
@ -308,6 +317,9 @@ func loadConfig() error {
if !globalIsEnvBrowser {
globalIsBrowserEnabled = serverConfig.GetBrowser()
}
if !globalIsEnvRegion {
globalServerRegion = serverConfig.GetRegion()
}
serverConfigMu.Unlock()
return nil

@ -138,10 +138,10 @@ func TestServerConfigWithEnvs(t *testing.T) {
os.Setenv("MINIO_SECRET_KEY", "minio123")
defer os.Unsetenv("MINIO_SECRET_KEY")
defer func() {
globalIsEnvBrowser = false
globalIsEnvCreds = false
}()
os.Setenv("MINIO_REGION", "us-west-1")
defer os.Unsetenv("MINIO_REGION")
defer resetGlobalIsEnvs()
// Get test root.
rootPath, err := getTestRoot()
@ -165,6 +165,11 @@ func TestServerConfigWithEnvs(t *testing.T) {
t.Errorf("Expecting browser is set to false found %v", serverConfig.GetBrowser())
}
// Check if serverConfig has
if serverConfig.GetRegion() != "us-west-1" {
t.Errorf("Expecting region to be \"us-west-1\" found %v", serverConfig.GetRegion())
}
// Check if serverConfig has
cred := serverConfig.GetCredential()
@ -175,6 +180,7 @@ func TestServerConfigWithEnvs(t *testing.T) {
if cred.SecretKey != "minio123" {
t.Errorf("Expecting access key to be `minio123` found %s", cred.SecretKey)
}
}
func TestCheckDupJSONKeys(t *testing.T) {

@ -66,9 +66,15 @@ var (
globalIsBrowserEnabled = true
// This flag is set to 'true' when MINIO_BROWSER env is set.
globalIsEnvBrowser = false
// Set to true if credentials were passed from env, default is false.
globalIsEnvCreds = false
// This flag is set to 'true' wen MINIO_REGION env is set.
globalIsEnvRegion = false
// This flag is set to 'us-east-1' by default
globalServerRegion = globalMinioDefaultRegion
// Maximum size of internal objects parts
globalPutPartSize = int64(64 * 1024 * 1024)

@ -454,6 +454,13 @@ func serverHandleEnvVars() {
globalIsEnvBrowser = true
globalIsBrowserEnabled = bool(browserFlag)
}
if serverRegion := os.Getenv("MINIO_REGION"); serverRegion != "" {
// region Envs are set globally.
globalIsEnvRegion = true
globalServerRegion = serverRegion
}
}
// serverMain handler called for 'minio server' command.

@ -490,6 +490,8 @@ func resetGlobalIsXL() {
func resetGlobalIsEnvs() {
globalIsEnvCreds = false
globalIsEnvBrowser = false
globalIsEnvRegion = false
}
// Resets all the globals used modified in tests.

Loading…
Cancel
Save