Beispiel #1
0
func (s *MySuite) TestDeepDiff(c *C) {
	type myStruct struct {
		Version  string
		User     string
		Password string
		Folders  []string
	}
	saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
	config, err := quick.New(&saveMe)
	c.Assert(err, IsNil)
	c.Assert(config, Not(IsNil))

	mismatch := myStruct{"1", "Guest", "nopassword", []string{"Work", "documents", "Music"}}
	newConfig, err := quick.New(&mismatch)
	c.Assert(err, IsNil)
	c.Assert(newConfig, Not(IsNil))

	fields, err := config.DeepDiff(newConfig)
	c.Assert(err, IsNil)
	c.Assert(len(fields), Equals, 2)

	// Uncomment for debugging
	//	for i, field := range fields {
	//		fmt.Printf("DeepDiff[%d]: %s=%v\n", i, field.Name(), field.Value())
	//	}
}
Beispiel #2
0
func (s *MySuite) TestSaveLoad(c *C) {
	defer os.RemoveAll("test.json")
	type myStruct struct {
		Version  string
		User     string
		Password string
		Folders  []string
	}
	saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
	config, err := quick.New(&saveMe)
	c.Assert(err, IsNil)
	c.Assert(config, Not(IsNil))
	err = config.Save("test.json")
	c.Assert(err, IsNil)

	loadMe := myStruct{Version: "1"}
	newConfig, err := quick.New(&loadMe)
	c.Assert(err, IsNil)
	c.Assert(newConfig, Not(IsNil))
	err = newConfig.Load("test.json")
	c.Assert(err, IsNil)

	c.Assert(config.Data(), DeepEquals, newConfig.Data())
	c.Assert(config.Data(), DeepEquals, &loadMe)

	mismatch := myStruct{"1.1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
	c.Assert(newConfig.Data(), Not(DeepEquals), &mismatch)
}
Beispiel #3
0
// getMcConfig - reads configuration file and returns config
func getMcConfig() (*configV5, *probe.Error) {
	if !isMcConfigExists() {
		return nil, errInvalidArgument().Trace()
	}

	configFile, err := getMcConfigPath()
	if err != nil {
		return nil, err.Trace()
	}

	// Cached in private global variable.
	if v := cache.Get(); v != nil { // Use previously cached config.
		return v.(quick.Config).Data().(*configV5), nil
	}

	conf := new(configV5)
	conf.Version = globalMCConfigVersion
	qconf, err := quick.New(conf)
	if err != nil {
		return nil, err.Trace()
	}

	err = qconf.Load(configFile)
	if err != nil {
		return nil, err.Trace()
	}
	cache.Put(qconf)
	return qconf.Data().(*configV5), nil
}
Beispiel #4
0
func migrateSessionV2ToV3() {
	for _, sid := range getSessionIDs() {
		oldSessionV2Header, err := loadSessionV2(sid)
		fatalIf(err.Trace(sid), "Unable to load version ‘1.1.0’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
		if oldSessionV2Header.Version == "3" {
			return
		}
		newSessionV3Header := &sessionV3Header{}
		newSessionV3Header.Version = "3"
		newSessionV3Header.When = oldSessionV2Header.When
		newSessionV3Header.RootPath = oldSessionV2Header.RootPath
		newSessionV3Header.CommandType = oldSessionV2Header.CommandType
		newSessionV3Header.CommandArgs = oldSessionV2Header.CommandArgs
		newSessionV3Header.LastCopied = oldSessionV2Header.LastCopied
		newSessionV3Header.TotalBytes = oldSessionV2Header.TotalBytes
		newSessionV3Header.TotalObjects = oldSessionV2Header.TotalObjects

		qs, err := quick.New(newSessionV3Header)
		fatalIf(err.Trace(sid), "Unable to initialize quick config.")

		sessionFile, err := getSessionFile(sid)
		fatalIf(err.Trace(sid), "Unable to get session file.")

		err = qs.Save(sessionFile)
		fatalIf(err.Trace(sid), "Saving new session file for version ‘3’ failed.")
	}
}
Beispiel #5
0
// removeAlias - remove alias
func removeAlias(alias string) {
	if strings.TrimSpace(alias) == "" {
		fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
	}
	config, err := newConfig()
	fatalIf(err.Trace(), "Failed to initialize ‘quick’ configuration data structure.")

	configPath := mustGetMcConfigPath()
	err = config.Load(configPath)
	fatalIf(err.Trace(configPath), "Unable to load config path")
	if !isValidAliasName(alias) {
		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)
	if _, ok := newConf.Aliases[alias]; !ok {
		fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ does not exist.", alias))
	}
	delete(newConf.Aliases, alias)

	newConfig, err := quick.New(newConf)
	fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
	err = writeConfig(newConfig)
	fatalIf(err.Trace(alias), "Unable to save alias ‘"+alias+"’.")

	Prints("%s\n", AliasMessage{
		op:    "remove",
		Alias: alias,
	})
}
Beispiel #6
0
// Migrate from config ‘1.0.1’ to ‘2’. Drop semantic versioning and move to integer versioning. No other changes.
func migrateConfigV101ToV2() {
	if !isMcConfigExists() {
		return
	}
	mcCfgV101, err := quick.Load(mustGetMcConfigPath(), newConfigV101())
	fatalIf(err.Trace(), "Unable to load config version ‘1.0.1’.")

	// update to newer version
	if mcCfgV101.Version() != "1.0.1" {
		return
	}

	cfgV2 := newConfigV2()

	// Copy aliases.
	for k, v := range mcCfgV101.Data().(*configV101).Aliases {
		cfgV2.Aliases[k] = v
	}

	// Copy hosts.
	for k, hostCfgV101 := range mcCfgV101.Data().(*configV101).Hosts {
		cfgV2.Hosts[k] = hostConfigV2{
			AccessKeyID:     hostCfgV101.AccessKeyID,
			SecretAccessKey: hostCfgV101.SecretAccessKey,
		}
	}

	mcCfgV2, err := quick.New(cfgV2)
	fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘2’.")

	err = mcCfgV2.Save(mustGetMcConfigPath())
	fatalIf(err.Trace(), "Unable to save config version ‘2’.")

	console.Infof("Successfully migrated %s from version ‘1.0.1’ to version ‘2’.\n", mustGetMcConfigPath())
}
Beispiel #7
0
func removeHost(hostGlob string) {
	if strings.TrimSpace(hostGlob) == "" {
		fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
	}
	if strings.TrimSpace(hostGlob) == "dl.minio.io:9000" {
		fatalIf(errDummy().Trace(), "‘"+hostGlob+"’ is reserved hostname and cannot be removed.")
	}
	config, err := newConfig()
	fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")

	configPath := mustGetMcConfigPath()
	err = config.Load(configPath)
	fatalIf(err.Trace(configPath), "Unable to load config path")

	// convert interface{} back to its original struct
	newConf := config.Data().(*configV5)
	if _, ok := newConf.Hosts[hostGlob]; !ok {
		fatalIf(errDummy().Trace(), fmt.Sprintf("Host glob ‘%s’ does not exist.", hostGlob))
	}
	delete(newConf.Hosts, hostGlob)

	newConfig, err := quick.New(newConf)
	fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
	err = writeConfig(newConfig)
	fatalIf(err.Trace(hostGlob), "Unable to save host glob ‘"+hostGlob+"’.")

	printMsg(hostMessage{op: "remove", Host: hostGlob})
}
Beispiel #8
0
// Migrate config version ‘4’ to ‘5’
func migrateConfigV4ToV5() {
	if !isMcConfigExists() {
		return
	}
	mcConfigV4, err := quick.Load(mustGetMcConfigPath(), newConfigV4())
	fatalIf(err.Trace(), "Unable to load mc config V2.")

	// update to newer version
	if mcConfigV4.Version() == "4" {
		confV5 := new(configV5)
		confV5.Aliases = mcConfigV4.Data().(*configV4).Aliases
		confV5.Hosts = make(map[string]hostConfig)
		for host, hostConf := range mcConfigV4.Data().(*configV4).Hosts {
			confV5.Hosts[host] = hostConfig{
				AccessKeyID:     hostConf.AccessKeyID,
				SecretAccessKey: hostConf.SecretAccessKey,
				API:             "S3v4",
			}
		}
		confV5.Version = globalMCConfigVersion

		mcNewConfigV5, err := quick.New(confV5)
		fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘5’.")

		err = mcNewConfigV5.Save(mustGetMcConfigPath())
		fatalIf(err.Trace(), "Unable to save config version ‘5’.")

		console.Infof("Successfully migrated %s from version ‘4’ to version ‘5’.\n", mustGetMcConfigPath())
	}
}
Beispiel #9
0
// newConfig - get new config interface
func newConfig() (config quick.Config, err *probe.Error) {
	config, err = quick.New(newConfigV5())
	if err != nil {
		return nil, err.Trace()
	}
	return config, nil
}
Beispiel #10
0
// Migrate config version ‘6’ to ‘7'. Remove alias map and introduce
// named Host config. Also no more glob match for host config entries.
func migrateConfigV6ToV7() {
	if !isMcConfigExists() {
		return
	}

	mcCfgV6, err := quick.Load(mustGetMcConfigPath(), newConfigV6())
	fatalIf(err.Trace(), "Unable to load mc config V6.")

	if mcCfgV6.Version() != "6" {
		return
	}

	cfgV7 := newConfigV7()
	aliasIndex := 0
	// We dropped alias support in v7. We only need to migrate host configs.
	for host, hostCfgV6 := range mcCfgV6.Data().(*configV6).Hosts {
		if hostCfgV6.AccessKeyID == "YOUR-ACCESS-KEY-ID-HERE" ||
			hostCfgV6.SecretAccessKey == "YOUR-SECRET-ACCESS-KEY-HERE" ||
			hostCfgV6.AccessKeyID == "" ||
			hostCfgV6.SecretAccessKey == "" {
			// Ignore default entries. configV7.loadDefaults() will re-insert them back.
		} else if host == "https://s3.amazonaws.com" {
			// Only one entry can exist for "s3" domain.
			cfgV7.Hosts["s3"] = hostConfigV7{
				URL:       host,
				AccessKey: hostCfgV6.AccessKeyID,
				SecretKey: hostCfgV6.SecretAccessKey,
				API:       hostCfgV6.API,
			}
		} else if host == "https://storage.googleapis.com" {
			// Only one entry can exist for "gcs" domain.
			cfgV7.Hosts["gcs"] = hostConfigV7{
				URL:       host,
				AccessKey: hostCfgV6.AccessKeyID,
				SecretKey: hostCfgV6.SecretAccessKey,
				API:       hostCfgV6.API,
			}
		} else {
			// Assign a generic "cloud1", cloud2..." key
			// for all other entries that has valid keys set.
			alias := fmt.Sprintf("cloud%d", aliasIndex)
			aliasIndex++
			cfgV7.Hosts[alias] = hostConfigV7{
				URL:       host,
				AccessKey: hostCfgV6.AccessKeyID,
				SecretKey: hostCfgV6.SecretAccessKey,
				API:       hostCfgV6.API,
			}
		}
	}
	// Load default settings.
	cfgV7.loadDefaults()
	mcNewCfgV7, err := quick.New(cfgV7)
	fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘7’.")

	err = mcNewCfgV7.Save(mustGetMcConfigPath())
	fatalIf(err.Trace(), "Unable to save config version ‘7’.")

	console.Infof("Successfully migrated %s from version ‘6’ to version ‘7’.\n", mustGetMcConfigPath())
}
Beispiel #11
0
// loadSession - reads session file if exists and re-initiates internal variables
func loadSessionV1(sid string) (*sessionV1, *probe.Error) {
	if !isSessionDirExists() {
		return nil, probe.NewError(errors.New("Session folder does not exist."))
	}

	sessionFile, err := getSessionFileV1(sid)
	if err != nil {
		return nil, err.Trace(sid)
	}

	s := new(sessionV1)
	s.Version = "1.0.0"
	// map of command and files copied
	s.URLs = nil
	s.Lock = new(sync.Mutex)
	s.Files = make(map[string]bool)
	qs, err := quick.New(s)
	if err != nil {
		return nil, err.Trace(s.Version)
	}
	err = qs.Load(sessionFile)
	if err != nil {
		return nil, err.Trace(sessionFile, s.Version)
	}
	return qs.Data().(*sessionV1), nil
}
Beispiel #12
0
// Migrate from config ‘2’ to ‘3’
func migrateConfigV2ToV3() {
	if !isMcConfigExists() {
		return
	}
	mcConfigV2, err := quick.Load(mustGetMcConfigPath(), newConfigV2())
	fatalIf(err.Trace(), "Unable to load mc config V2.")

	// update to newer version
	if mcConfigV2.Version() == "2" {
		confV3 := new(configV3)
		confV3.Aliases = mcConfigV2.Data().(*configV2).Aliases
		confV3.Hosts = make(map[string]struct {
			AccessKeyID     string `json:"access-key-id"`
			SecretAccessKey string `json:"secret-access-key"`
		})
		for host, hostConf := range mcConfigV2.Data().(*configV2).Hosts {
			newHostConf := struct {
				AccessKeyID     string `json:"access-key-id"`
				SecretAccessKey string `json:"secret-access-key"`
			}{}
			newHostConf.AccessKeyID = hostConf.AccessKeyID
			newHostConf.SecretAccessKey = hostConf.SecretAccessKey
			confV3.Hosts[host] = newHostConf
		}
		confV3.Version = "3"

		mcNewConfigV3, err := quick.New(confV3)
		fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘3’.")

		err = mcNewConfigV3.Save(mustGetMcConfigPath())
		fatalIf(err.Trace(), "Unable to save config version ‘3’.")

		console.Infof("Successfully migrated %s from version ‘2’ to version ‘3’.\n", mustGetMcConfigPath())
	}
}
Beispiel #13
0
// Migrate config version ‘4’ to ‘5’. Rename hostConfigV4.Signature  -> hostConfigV5.API.
func migrateConfigV4ToV5() {
	if !isMcConfigExists() {
		return
	}
	mcCfgV4, err := quick.Load(mustGetMcConfigPath(), newConfigV4())
	fatalIf(err.Trace(), "Unable to load mc config V4.")

	// update to newer version
	if mcCfgV4.Version() != "4" {
		return
	}

	cfgV5 := newConfigV5()
	for k, v := range mcCfgV4.Data().(*configV4).Aliases {
		cfgV5.Aliases[k] = v
	}
	for host, hostCfgV4 := range mcCfgV4.Data().(*configV4).Hosts {
		cfgV5.Hosts[host] = hostConfigV5{
			AccessKeyID:     hostCfgV4.AccessKeyID,
			SecretAccessKey: hostCfgV4.SecretAccessKey,
			API:             "v4", // Rename from .Signature to .API
		}
	}

	mcNewCfgV5, err := quick.New(cfgV5)
	fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘5’.")

	err = mcNewCfgV5.Save(mustGetMcConfigPath())
	fatalIf(err.Trace(), "Unable to save config version ‘5’.")

	console.Infof("Successfully migrated %s from version ‘4’ to version ‘5’.\n", mustGetMcConfigPath())
}
Beispiel #14
0
// addAlias - add new aliases
func addAlias(alias, url string) {
	if alias == "" || url == "" {
		fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
	}
	config, err := newConfig()
	fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")

	err = config.Load(mustGetMcConfigPath())
	fatalIf(err.Trace(), "Unable to load config path")

	url = strings.TrimSuffix(url, "/")
	if !strings.HasPrefix(url, "http") {
		fatalIf(errDummy().Trace(), fmt.Sprintf("Invalid alias URL ‘%s’. Valid examples are: http://s3.amazonaws.com, https://yourbucket.example.com.", url))
	}
	if !isValidAliasName(alias) {
		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)
	if oldURL, ok := newConf.Aliases[alias]; ok {
		fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL))
	}
	newConf.Aliases[alias] = url
	newConfig, err := quick.New(newConf)
	fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")

	err = writeConfig(newConfig)
	fatalIf(err.Trace(alias, url), "Unable to save alias ‘"+alias+"’.")

	Prints("%s\n", AliasMessage{
		op:    "add",
		Alias: alias,
		URL:   url,
	})
}
Beispiel #15
0
// Load shareDB entries from disk. Any entries held in memory are reset.
func (s *shareDBV1) Load(filename string) *probe.Error {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	// Check if the db file exist.
	if _, err := os.Stat(filename); err != nil {
		return probe.NewError(err)
	}

	// Initialize and load using quick package.
	qs, err := quick.New(newShareDBV1())
	if err != nil {
		return err.Trace(filename)
	}
	err = qs.Load(filename)
	if err != nil {
		return err.Trace(filename)
	}

	// Copy map over.
	for k, v := range qs.Data().(*shareDBV1).Shares {
		s.Shares[k] = v
	}

	// Filter out expired entries and save changes back to disk.
	s.deleteAllExpired()
	s.save(filename)

	return nil
}
Beispiel #16
0
// Persist share uploads to disk.
func (s shareDBV1) save(filename string) *probe.Error {
	// Initialize a new quick file.
	qs, err := quick.New(s)
	if err != nil {
		return err.Trace(filename)
	}
	return qs.Save(filename).Trace(filename)
}
Beispiel #17
0
// saveBucketsMetadata - save metadata of all buckets
func saveBucketsMetadata(buckets Buckets) *probe.Error {
	qc, err := quick.New(buckets)
	if err != nil {
		return err.Trace()
	}
	if err := qc.Save(bucketsMetadataPath); err != nil {
		return err.Trace()
	}
	return nil
}
Beispiel #18
0
// saveMultipartsSession - save multiparts
func saveMultipartsSession(multiparts Multiparts) *probe.Error {
	qc, err := quick.New(multiparts)
	if err != nil {
		return err.Trace()
	}
	if err := qc.Save(multipartsMetadataPath); err != nil {
		return err.Trace()
	}
	return nil
}
Beispiel #19
0
// Migrate from config version 1.0 to 1.0.1. Populate example entries and save it back.
func migrateConfigV1ToV101() {
	if !isMcConfigExists() {
		return
	}
	mcCfgV1, err := quick.Load(mustGetMcConfigPath(), newConfigV1())
	fatalIf(err.Trace(), "Unable to load config version ‘1’.")

	// If loaded config version does not match 1.0.0, we do nothing.
	if mcCfgV1.Version() != "1.0.0" {
		return
	}

	// 1.0.1 is compatible to 1.0.0. We are just adding new entries.
	cfgV101 := newConfigV101()

	// Copy aliases.
	for k, v := range mcCfgV1.Data().(*configV1).Aliases {
		cfgV101.Aliases[k] = v
	}

	// Copy hosts.
	for k, hostCfgV1 := range mcCfgV1.Data().(*configV1).Hosts {
		cfgV101.Hosts[k] = hostConfigV101{
			AccessKeyID:     hostCfgV1.AccessKeyID,
			SecretAccessKey: hostCfgV1.SecretAccessKey,
		}
	}

	// Example localhost entry.
	if _, ok := cfgV101.Hosts["localhost:*"]; !ok {
		cfgV101.Hosts["localhost:*"] = hostConfigV101{}
	}

	// Example loopback IP entry.
	if _, ok := cfgV101.Hosts["127.0.0.1:*"]; !ok {
		cfgV101.Hosts["127.0.0.1:*"] = hostConfigV101{}
	}

	// Example AWS entry.
	// Look for glob string (not glob match). We used to support glob based key matching earlier.
	if _, ok := cfgV101.Hosts["*.s3*.amazonaws.com"]; !ok {
		cfgV101.Hosts["*.s3*.amazonaws.com"] = hostConfigV101{
			AccessKeyID:     "YOUR-ACCESS-KEY-ID-HERE",
			SecretAccessKey: "YOUR-SECRET-ACCESS-KEY-HERE",
		}
	}

	// Save the new config back to the disk.
	mcCfgV101, err := quick.New(cfgV101)
	fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘1.0.1’.")
	err = mcCfgV101.Save(mustGetMcConfigPath())
	fatalIf(err.Trace(), "Unable to save config version ‘1.0.1’.")

	console.Infof("Successfully migrated %s from version ‘1.0.0’ to version ‘1.0.1’.\n", mustGetMcConfigPath())
}
Beispiel #20
0
func (s *TestSuite) TestNewConfigV4(c *C) {
	root, err := ioutil.TempDir(os.TempDir(), "mc-")
	c.Assert(err, IsNil)
	defer os.RemoveAll(root)

	conf, perr := newConfig()
	c.Assert(perr, IsNil)
	configFile := filepath.Join(root, "config.json")
	perr = conf.Save(configFile)
	c.Assert(perr, IsNil)

	confNew := newConfigV5()
	config, perr := quick.New(confNew)
	c.Assert(perr, IsNil)
	perr = config.Load(configFile)
	c.Assert(perr, IsNil)
	data := config.Data().(*configV5)

	type aliases struct {
		name string
		url  string
	}

	wantAliases := []aliases{
		{
			"s3",
			"https://s3.amazonaws.com",
		},
		{
			"play",
			"https://play.minio.io:9000",
		},
		{
			"localhost",
			"http://localhost:9000",
		},
	}
	for _, alias := range wantAliases {
		url, ok := data.Aliases[alias.name]
		c.Assert(ok, Equals, true)
		c.Assert(url, Equals, alias.url)
	}

	wantHosts := []string{
		"localhost:*",
		"127.0.0.1:*",
		"play.minio.io:9000",
		"dl.minio.io:9000",
		"s3*.amazonaws.com",
	}
	for _, host := range wantHosts {
		_, ok := data.Hosts[host]
		c.Assert(ok, Equals, true)
	}
}
Beispiel #21
0
func saveSharedURLsV2(s *sharedURLsV2) *probe.Error {
	qs, err := quick.New(s)
	if err != nil {
		return err.Trace()
	}
	sharedURLsDataFile, err := getSharedURLsDataFile()
	if err != nil {
		return err.Trace()
	}
	return qs.Save(sharedURLsDataFile).Trace(sharedURLsDataFile)
}
Beispiel #22
0
// Fix config version ‘3’, by removing broken struct tags
func fixConfigV3() {
	if !isMcConfigExists() {
		return
	}
	// brokenConfigV3 broken config between version 3
	type brokenConfigV3 struct {
		Version string
		ACL     string
		Access  string
		Aliases map[string]string
		Hosts   map[string]struct {
			AccessKeyID     string
			SecretAccessKey string
		}
	}
	conf := new(brokenConfigV3)
	conf.Aliases = make(map[string]string)
	conf.Hosts = make(map[string]struct {
		AccessKeyID     string
		SecretAccessKey string
	})

	mcConfigV3, err := quick.Load(mustGetMcConfigPath(), conf)
	fatalIf(err.Trace(), "Unable to load config.")

	// 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
		confV3.Hosts = make(map[string]struct {
			AccessKeyID     string `json:"access-key-id"`
			SecretAccessKey string `json:"secret-access-key"`
		})
		for host, hostConf := range mcConfigV3.Data().(*brokenConfigV3).Hosts {
			newHostConf := struct {
				AccessKeyID     string `json:"access-key-id"`
				SecretAccessKey string `json:"secret-access-key"`
			}{}
			newHostConf.AccessKeyID = hostConf.AccessKeyID
			newHostConf.SecretAccessKey = hostConf.SecretAccessKey
			confV3.Hosts[host] = newHostConf
		}
		confV3.Version = "3"

		mcNewConfigV3, err := quick.New(confV3)
		fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘3’.")

		err = mcNewConfigV3.Save(mustGetMcConfigPath())
		fatalIf(err.Trace(), "Unable to save config version ‘3’.")

		console.Infof("Successfully fixed %s broken config for version ‘3’.\n", mustGetMcConfigPath())
	}
}
Beispiel #23
0
// If the host key does not have http(s), fix it.
func fixConfigV6ForHosts() {
	if !isMcConfigExists() {
		return
	}

	brokenMcCfgV6, err := quick.Load(mustGetMcConfigPath(), newConfigV6())
	fatalIf(err.Trace(), "Unable to load config.")

	if brokenMcCfgV6.Version() != "6" {
		return
	}

	newCfgV6 := newConfigV6()
	isMutated := false

	// Copy aliases.
	for k, v := range brokenMcCfgV6.Data().(*configV6).Aliases {
		newCfgV6.Aliases[k] = v
	}

	url := new(client.URL)
	// Copy hosts.
	for host, hostCfgV6 := range brokenMcCfgV6.Data().(*configV6).Hosts {
		// Already fixed - Copy and move on.
		if strings.HasPrefix(host, "https") || strings.HasPrefix(host, "http") {
			newCfgV6.Hosts[host] = hostCfgV6
			continue
		}

		// If host entry does not contain "http(s)", introduce a new entry and delete the old one.
		if host == "s3.amazonaws.com" || host == "storage.googleapis.com" ||
			host == "localhost:9000" || host == "127.0.0.1:9000" ||
			host == "play.minio.io:9000" || host == "dl.minio.io:9000" {
			console.Infoln("Found broken host entries, replacing " + host + " with https://" + host + ".")
			url.Host = host
			url.Scheme = "https"
			url.SchemeSeparator = "://"
			newCfgV6.Hosts[url.String()] = hostCfgV6
			isMutated = true
			continue
		}
	}

	if isMutated {
		// Save the new config back to the disk.
		mcCfgV6, err := quick.New(newCfgV6)
		fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘v6’.")

		err = mcCfgV6.Save(mustGetMcConfigPath())
		fatalIf(err.Trace(), "Unable to save config version ‘v6’.")
	}
}
Beispiel #24
0
// loadBucketsMetadata load buckets metadata file
func loadBucketsMetadata() (*Buckets, *probe.Error) {
	buckets := &Buckets{}
	buckets.Version = "1"
	buckets.Metadata = make(map[string]*BucketMetadata)
	qc, err := quick.New(buckets)
	if err != nil {
		return nil, err.Trace()
	}
	if err := qc.Load(bucketsMetadataPath); err != nil {
		return nil, err.Trace()
	}
	return qc.Data().(*Buckets), nil
}
Beispiel #25
0
// loadMultipartsSession load multipart session file
func loadMultipartsSession() (*Multiparts, *probe.Error) {
	multiparts := &Multiparts{}
	multiparts.Version = "1"
	multiparts.ActiveSession = make(map[string]*MultipartSession)
	qc, err := quick.New(multiparts)
	if err != nil {
		return nil, err.Trace()
	}
	if err := qc.Load(multipartsMetadataPath); err != nil {
		return nil, err.Trace()
	}
	return qc.Data().(*Multiparts), nil
}
Beispiel #26
0
// SaveConfig save xl config
func SaveConfig(a *Config) *probe.Error {
	xlConfigPath, err := getXLConfigPath()
	if err != nil {
		return err.Trace()
	}
	qc, err := quick.New(a)
	if err != nil {
		return err.Trace()
	}
	if err := qc.Save(xlConfigPath); err != nil {
		return err.Trace()
	}
	return nil
}
Beispiel #27
0
// saveConfigV7 - saves an updated config.
func saveConfigV7(cfgV7 *configV7) *probe.Error {
	cfgMutex.Lock()
	defer cfgMutex.Unlock()

	qs, err := quick.New(cfgV7)
	if err != nil {
		return err.Trace()
	}

	// update the cache.
	cacheCfgV7 = cfgV7

	return qs.Save(mustGetMcConfigPath()).Trace(mustGetMcConfigPath())
}
Beispiel #28
0
// SaveMultipartsSession - save multiparts
func SaveMultipartsSession(multiparts *Multiparts) *probe.Error {
	fsMultipartsConfigPath, err := getFSMultipartsSessionConfigPath()
	if err != nil {
		return err.Trace()
	}
	qc, err := quick.New(multiparts)
	if err != nil {
		return err.Trace()
	}
	if err := qc.Save(fsMultipartsConfigPath); err != nil {
		return err.Trace()
	}
	return nil
}
Beispiel #29
0
// SaveConfig save auth config
func SaveConfig(a *AuthConfig) *probe.Error {
	authConfigFile, err := getAuthConfigFile()
	if err != nil {
		return err.Trace()
	}
	qc, err := quick.New(a)
	if err != nil {
		return err.Trace()
	}
	if err := qc.Save(authConfigFile); err != nil {
		return err.Trace()
	}
	return nil
}
Beispiel #30
0
// SaveBucketsMetadata - save metadata of all buckets
func SaveBucketsMetadata(buckets *Buckets) *probe.Error {
	fsBucketsConfigPath, err := getFSBucketsConfigPath()
	if err != nil {
		return err.Trace()
	}
	qc, err := quick.New(buckets)
	if err != nil {
		return err.Trace()
	}
	if err := qc.Save(fsBucketsConfigPath); err != nil {
		return err.Trace()
	}
	return nil
}