Merge pull request #1418 from harshavardhana/config-fixes

config: fix config version 6 by removing glob hosts
This commit is contained in:
Harshavardhana
2015-11-18 00:57:25 -08:00
2 changed files with 59 additions and 3 deletions
+3 -3
View File
@@ -300,12 +300,12 @@ func migrateConfigV5ToV6() {
}
}
// Fix config version ‘3’, by removing broken struct tags
// Fix config version ‘3’, by removing broken struct tags.
func fixConfigV3() {
if !isMcConfigExists() {
return
}
// brokenConfigV3 broken config between version 3
// brokenConfigV3 broken config between version 3.
type brokenConfigV3 struct {
Version string
ACL string
@@ -326,7 +326,7 @@ func fixConfigV3() {
mcConfigV3, err := quick.Load(mustGetMcConfigPath(), conf)
fatalIf(err.Trace(), "Unable to load config.")
// Update to newer version
// Update to newer version.
if len(mcConfigV3.Data().(*brokenConfigV3).Aliases) != 0 || mcConfigV3.Data().(*brokenConfigV3).ACL != "" || mcConfigV3.Data().(*brokenConfigV3).Access != "" && mcConfigV3.Version() == "3" {
confV3 := new(configV3)
confV3.Aliases = mcConfigV3.Data().(*brokenConfigV3).Aliases
+56
View File
@@ -20,8 +20,10 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio-xl/pkg/probe"
"github.com/minio/minio-xl/pkg/quick"
)
@@ -238,6 +240,58 @@ func newConfig() (config quick.Config, err *probe.Error) {
return config, nil
}
func fixConfigV6() {
if !isMcConfigExists() {
return
}
config, err := quick.New(newConfigV6())
fatalIf(err.Trace(), "Unable to initialize config.")
err = config.Load(mustGetMcConfigPath())
fatalIf(err.Trace(), "Unable to load config.")
if config.Data().(*configV6).Version == "6" {
newConfig := new(configV6)
newConfig.Aliases = make(map[string]string)
newConfig.Hosts = make(map[string]hostConfig)
newConfig.Version = "6"
newConfig.Aliases = config.Data().(*configV6).Aliases
for host, hostCfg := range config.Data().(*configV6).Hosts {
if strings.Contains(host, "*s3*") || strings.Contains(host, "*.s3*") {
console.Infoln("Found glob url, replacing " + host + " with s3.amazonaws.com")
newConfig.Hosts["s3.amazonaws.com"] = hostCfg
continue
}
if strings.Contains(host, "s3*") {
console.Infoln("Found glob url, replacing " + host + " with s3.amazonaws.com")
newConfig.Hosts["s3.amazonaws.com"] = hostCfg
continue
}
if strings.Contains(host, "*storage.googleapis.com") {
console.Infoln("Found glob url, replacing " + host + " with storage.googleapis.com")
newConfig.Hosts["storage.googleapis.com"] = hostCfg
continue
}
if strings.Contains(host, "localhost:*") {
console.Infoln("Found glob url, replacing " + host + " with localhost:9000")
newConfig.Hosts["localhost:9000"] = hostCfg
continue
}
if strings.Contains(host, "127.0.0.1:*") {
console.Infoln("Found glob url, replacing " + host + " with 127.0.0.1:9000")
newConfig.Hosts["127.0.0.1:9000"] = hostCfg
continue
}
newConfig.Hosts[host] = hostCfg
}
newConf, err := quick.New(newConfig)
fatalIf(err.Trace(), "Unable to initialize newly fixed config.")
err = newConf.Save(mustGetMcConfigPath())
fatalIf(err.Trace(mustGetMcConfigPath()), "Unable to save newly fixed config path.")
}
}
func migrateConfig() {
// Migrate config V1 to V101
migrateConfigV1ToV101()
@@ -256,4 +310,6 @@ func migrateConfig() {
func fixConfig() {
// Fix config V3
fixConfigV3()
// Fix config V6
fixConfigV6()
}