diff --git a/cmd/config-v18.go b/cmd/config-v18.go index 37844c9b8..f75c0cb4d 100644 --- a/cmd/config-v18.go +++ b/cmd/config-v18.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 diff --git a/cmd/config-v18_test.go b/cmd/config-v18_test.go index f443e1c14..e2bb4f008 100644 --- a/cmd/config-v18_test.go +++ b/cmd/config-v18_test.go @@ -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) { diff --git a/cmd/globals.go b/cmd/globals.go index 5d98aa822..1b09d2421 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -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) diff --git a/cmd/server-main.go b/cmd/server-main.go index 13d4f76b2..cbe327d0f 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -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. diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index a78a4183e..0bfea9bc2 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -490,6 +490,8 @@ func resetGlobalIsXL() { func resetGlobalIsEnvs() { globalIsEnvCreds = false + globalIsEnvBrowser = false + globalIsEnvRegion = false } // Resets all the globals used modified in tests.