Merge pull request #1276 from harshavardhana/config
config: migrate to new configV6
This commit is contained in:
@@ -126,7 +126,7 @@ func listAliases() {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
for k, v := range newConf.Aliases {
|
||||
printMsg(aliasMessage{op: "list", Alias: k, URL: v})
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func removeAlias(alias string) {
|
||||
}
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
if _, ok := newConf.Aliases[alias]; !ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ does not exist.", alias))
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func addAlias(alias, url string) {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
if oldURL, ok := newConf.Aliases[alias]; ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL))
|
||||
}
|
||||
|
||||
+3
-3
@@ -141,7 +141,7 @@ func listHosts() {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
for k, v := range newConf.Hosts {
|
||||
printMsg(hostMessage{op: "list", Host: k, AccessKeyID: v.AccessKeyID, SecretAccessKey: v.SecretAccessKey, API: v.API})
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func removeHost(hostGlob string) {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
if _, ok := newConf.Hosts[hostGlob]; !ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Host glob ‘%s’ does not exist.", hostGlob))
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func addHost(hostGlob, accessKeyID, secretAccessKey, api string) {
|
||||
}
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
newConf.Hosts[hostGlob] = hostConfig{
|
||||
AccessKeyID: accessKeyID,
|
||||
SecretAccessKey: secretAccessKey,
|
||||
|
||||
@@ -51,7 +51,7 @@ func mainConfigVersion(ctx *cli.Context) {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf := config.Data().(*configV6)
|
||||
type Version struct {
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
@@ -28,6 +29,12 @@ import (
|
||||
"github.com/minio/minio-xl/pkg/quick"
|
||||
)
|
||||
|
||||
type configV6 struct {
|
||||
Version string `json:"version"`
|
||||
Aliases map[string]string `json:"alias"`
|
||||
Hosts map[string]hostConfig `json:"hosts"`
|
||||
}
|
||||
|
||||
type configV5 struct {
|
||||
Version string `json:"version"`
|
||||
Aliases map[string]string `json:"alias"`
|
||||
@@ -137,7 +144,7 @@ func mustGetMcConfigPath() string {
|
||||
}
|
||||
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV5, *probe.Error) {
|
||||
func getMcConfig() (*configV6, *probe.Error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, errInvalidArgument().Trace()
|
||||
}
|
||||
@@ -149,10 +156,10 @@ func getMcConfig() (*configV5, *probe.Error) {
|
||||
|
||||
// Cached in private global variable.
|
||||
if v := cache.Get(); v != nil { // Use previously cached config.
|
||||
return v.(quick.Config).Data().(*configV5), nil
|
||||
return v.(quick.Config).Data().(*configV6), nil
|
||||
}
|
||||
|
||||
conf := new(configV5)
|
||||
conf := new(configV6)
|
||||
conf.Version = globalMCConfigVersion
|
||||
qconf, err := quick.New(conf)
|
||||
if err != nil {
|
||||
@@ -164,11 +171,11 @@ func getMcConfig() (*configV5, *probe.Error) {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
cache.Put(qconf)
|
||||
return qconf.Data().(*configV5), nil
|
||||
return qconf.Data().(*configV6), nil
|
||||
}
|
||||
|
||||
// mustGetMcConfig - reads configuration file and returns configs, exits on error
|
||||
func mustGetMcConfig() *configV5 {
|
||||
func mustGetMcConfig() *configV6 {
|
||||
config, err := getMcConfig()
|
||||
fatalIf(err.Trace(), "Unable to read mc configuration.")
|
||||
return config
|
||||
@@ -216,6 +223,8 @@ func migrateConfig() {
|
||||
migrateConfigV3ToV4()
|
||||
// Migrate config V4 to V5
|
||||
migrateConfigV4ToV5()
|
||||
// Migrate config V5 to V6
|
||||
migrateConfigV5ToV6()
|
||||
}
|
||||
|
||||
func fixConfig() {
|
||||
@@ -376,7 +385,7 @@ func migrateConfigV4ToV5() {
|
||||
return
|
||||
}
|
||||
mcConfigV4, err := quick.Load(mustGetMcConfigPath(), newConfigV4())
|
||||
fatalIf(err.Trace(), "Unable to load mc config V2.")
|
||||
fatalIf(err.Trace(), "Unable to load mc config V4.")
|
||||
|
||||
// update to newer version
|
||||
if mcConfigV4.Version() == "4" {
|
||||
@@ -390,7 +399,7 @@ func migrateConfigV4ToV5() {
|
||||
API: "S3v4",
|
||||
}
|
||||
}
|
||||
confV5.Version = globalMCConfigVersion
|
||||
confV5.Version = "5"
|
||||
|
||||
mcNewConfigV5, err := quick.New(confV5)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘5’.")
|
||||
@@ -402,6 +411,45 @@ func migrateConfigV4ToV5() {
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate config version ‘4’ to ‘5’
|
||||
func migrateConfigV5ToV6() {
|
||||
if !isMcConfigExists() {
|
||||
return
|
||||
}
|
||||
mcConfigV5, err := quick.Load(mustGetMcConfigPath(), newConfigV5())
|
||||
fatalIf(err.Trace(), "Unable to load mc config V5.")
|
||||
|
||||
// update to newer version
|
||||
if mcConfigV5.Version() == "5" {
|
||||
confV6 := new(configV6)
|
||||
confV6.Aliases = mcConfigV5.Data().(*configV5).Aliases
|
||||
confV6.Aliases["gcs"] = "https://storage.googleapis.com"
|
||||
confV6.Hosts = make(map[string]hostConfig)
|
||||
for host, hostConf := range mcConfigV5.Data().(*configV5).Hosts {
|
||||
confV6.Hosts[host] = hostConf
|
||||
}
|
||||
for host, hostConf := range confV6.Hosts {
|
||||
if strings.Contains(host, "s3") {
|
||||
confV6.Hosts["*s3*amazonaws.com"] = hostConf
|
||||
break
|
||||
}
|
||||
}
|
||||
confV6.Hosts["*storage.googleapis.com"] = hostConfig{
|
||||
AccessKeyID: globalAccessKeyID,
|
||||
SecretAccessKey: globalSecretAccessKey,
|
||||
API: "S3v2",
|
||||
}
|
||||
confV6.Version = globalMCConfigVersion
|
||||
mcNewConfigV6, err := quick.New(confV6)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘6’.")
|
||||
|
||||
err = mcNewConfigV6.Save(mustGetMcConfigPath())
|
||||
fatalIf(err.Trace(), "Unable to save config version ‘6’.")
|
||||
|
||||
console.Infof("Successfully migrated %s from version ‘5’ to version ‘6’.\n", mustGetMcConfigPath())
|
||||
}
|
||||
}
|
||||
|
||||
// Fix config version ‘3’, by removing broken struct tags
|
||||
func fixConfigV3() {
|
||||
if !isMcConfigExists() {
|
||||
@@ -529,6 +577,16 @@ func newConfigV4() *configV4 {
|
||||
|
||||
func newConfigV5() *configV5 {
|
||||
conf := new(configV5)
|
||||
conf.Version = "5"
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
conf.Aliases = make(map[string]string)
|
||||
return conf
|
||||
}
|
||||
|
||||
func newConfigV6() *configV6 {
|
||||
conf := new(configV6)
|
||||
conf.Version = globalMCConfigVersion
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
@@ -547,6 +605,12 @@ func newConfigV5() *configV5 {
|
||||
API: "S3v4",
|
||||
}
|
||||
|
||||
googlHostConf := hostConfig{
|
||||
AccessKeyID: globalAccessKeyID,
|
||||
SecretAccessKey: globalSecretAccessKey,
|
||||
API: "S3v2",
|
||||
}
|
||||
|
||||
// Your example host config
|
||||
exampleHostConf := hostConfig{
|
||||
AccessKeyID: globalAccessKeyID,
|
||||
@@ -569,15 +633,16 @@ func newConfigV5() *configV5 {
|
||||
conf.Hosts[globalExampleHostURL] = exampleHostConf
|
||||
conf.Hosts["localhost:*"] = localHostConfig
|
||||
conf.Hosts["127.0.0.1:*"] = localHostConfig
|
||||
conf.Hosts["s3*.amazonaws.com"] = s3HostConf
|
||||
conf.Hosts["*.s3*.amazonaws.com"] = s3HostConf
|
||||
conf.Hosts["play.minio.io:9000"] = playHostConfig
|
||||
conf.Hosts["dl.minio.io:9000"] = dlHostConfig
|
||||
conf.Hosts["*s3*amazonaws.com"] = s3HostConf
|
||||
conf.Hosts["play.minio.io:9000"] = playHostConfig
|
||||
conf.Hosts["*storage.googleapis.com"] = googlHostConf
|
||||
|
||||
aliases := make(map[string]string)
|
||||
aliases["s3"] = "https://s3.amazonaws.com"
|
||||
aliases["play"] = "https://play.minio.io:9000"
|
||||
aliases["dl"] = "https://dl.minio.io:9000"
|
||||
aliases["gcs"] = "https://storage.googleapis.com"
|
||||
aliases["play"] = "https://play.minio.io:9000"
|
||||
aliases["localhost"] = "http://localhost:9000"
|
||||
conf.Aliases = aliases
|
||||
return conf
|
||||
@@ -585,7 +650,7 @@ func newConfigV5() *configV5 {
|
||||
|
||||
// newConfig - get new config interface
|
||||
func newConfig() (config quick.Config, err *probe.Error) {
|
||||
config, err = quick.New(newConfigV5())
|
||||
config, err = quick.New(newConfigV6())
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ var (
|
||||
|
||||
// mc configuration related constants.
|
||||
const (
|
||||
globalMCConfigVersion = "5"
|
||||
globalMCConfigVersion = "6"
|
||||
|
||||
globalMCConfigDir = ".mc/"
|
||||
globalMCConfigWindowsDir = "mc\\"
|
||||
|
||||
+6
-5
@@ -69,7 +69,7 @@ func (s *TestSuite) SetUpSuite(c *C) {
|
||||
config, err := newConfig()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
config.Data().(*configV5).Hosts["127.0.0.1:*"] = hostConfig{
|
||||
config.Data().(*configV6).Hosts["127.0.0.1:*"] = hostConfig{
|
||||
AccessKeyID: "WLGDGYAQYIGI833EV05A",
|
||||
SecretAccessKey: "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF",
|
||||
API: "S3v4",
|
||||
@@ -104,7 +104,7 @@ func (s *TestSuite) TestGetNewClient(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *TestSuite) TestNewConfigV5(c *C) {
|
||||
func (s *TestSuite) TestNewConfigV6(c *C) {
|
||||
root, e := ioutil.TempDir(os.TempDir(), "mc-")
|
||||
c.Assert(e, IsNil)
|
||||
defer os.RemoveAll(root)
|
||||
@@ -115,12 +115,12 @@ func (s *TestSuite) TestNewConfigV5(c *C) {
|
||||
err = conf.Save(configFile)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
confNew := newConfigV5()
|
||||
confNew := newConfigV6()
|
||||
config, err := quick.New(confNew)
|
||||
c.Assert(err, IsNil)
|
||||
err = config.Load(configFile)
|
||||
c.Assert(err, IsNil)
|
||||
data := config.Data().(*configV5)
|
||||
data := config.Data().(*configV6)
|
||||
|
||||
type aliases struct {
|
||||
name string
|
||||
@@ -152,7 +152,8 @@ func (s *TestSuite) TestNewConfigV5(c *C) {
|
||||
"127.0.0.1:*",
|
||||
"play.minio.io:9000",
|
||||
"dl.minio.io:9000",
|
||||
"s3*.amazonaws.com",
|
||||
"*s3*amazonaws.com",
|
||||
"*storage.googleapis.com",
|
||||
}
|
||||
for _, host := range wantHosts {
|
||||
_, ok := data.Hosts[host]
|
||||
|
||||
Reference in New Issue
Block a user