mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
484ba91b08
Migrate to new config format v4. ``` { "version": "4", "credential": { "accessKey": "WLGDGYAQYIGI833EV05A", "secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF" }, "region": "us-east-1", "logger": { "console": { "enable": true, "level": "fatal" }, "file": { "enable": false, "fileName": "", "level": "error" }, "syslog": { "enable": false, "address": "", "level": "debug" } } } ``` This patch also updates [minio cli spec](./minio.md)
148 lines
4.3 KiB
Go
148 lines
4.3 KiB
Go
/*
|
||
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||
*
|
||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
* you may not use this file except in compliance with the License.
|
||
* You may obtain a copy of the License at
|
||
*
|
||
* http://www.apache.org/licenses/LICENSE-2.0
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software
|
||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
* See the License for the specific language governing permissions and
|
||
* limitations under the License.
|
||
*/
|
||
|
||
package main
|
||
|
||
import (
|
||
"errors"
|
||
"os"
|
||
"path/filepath"
|
||
|
||
"github.com/minio/mc/pkg/console"
|
||
"github.com/minio/minio/pkg/probe"
|
||
"github.com/minio/minio/pkg/quick"
|
||
)
|
||
|
||
func migrateConfig() {
|
||
// Purge all configs with version '1'.
|
||
purgeV1()
|
||
// Migrate version '2' to '3'.
|
||
migrateV2ToV3()
|
||
// Migrate version '3' to '4'.
|
||
migrateV3ToV4()
|
||
}
|
||
|
||
// Version '1' is not supported anymore and deprecated, safe to delete.
|
||
func purgeV1() {
|
||
cv1, err := loadConfigV1()
|
||
if err != nil {
|
||
if os.IsNotExist(err.ToGoError()) {
|
||
return
|
||
}
|
||
}
|
||
fatalIf(err.Trace(), "Unable to load config version ‘1’.", nil)
|
||
|
||
if cv1.Version == "1" {
|
||
console.Println("Unsupported config version ‘1’ found, removed successfully.")
|
||
/// Purge old fsUsers.json file
|
||
configPath, err := getConfigPath()
|
||
fatalIf(err.Trace(), "Unable to retrieve config path.", nil)
|
||
|
||
configFile := filepath.Join(configPath, "fsUsers.json")
|
||
os.RemoveAll(configFile)
|
||
}
|
||
fatalIf(probe.NewError(errors.New("")), "Unexpected version found ‘"+cv1.Version+"’, cannot migrate.", nil)
|
||
}
|
||
|
||
// Version '2' to '3' config migration adds new fields and re-orders
|
||
// previous fields. Simplifies config for future additions.
|
||
func migrateV2ToV3() {
|
||
cv2, err := loadConfigV2()
|
||
if err != nil {
|
||
if os.IsNotExist(err.ToGoError()) {
|
||
return
|
||
}
|
||
}
|
||
fatalIf(err.Trace(), "Unable to load config version ‘2’.", nil)
|
||
if cv2.Version != "2" {
|
||
return
|
||
}
|
||
srvConfig := &configV3{}
|
||
srvConfig.Version = "3"
|
||
srvConfig.Addr = ":9000"
|
||
srvConfig.Credential = credential{
|
||
AccessKeyID: cv2.Credentials.AccessKeyID,
|
||
SecretAccessKey: cv2.Credentials.SecretAccessKey,
|
||
}
|
||
srvConfig.Region = cv2.Credentials.Region
|
||
srvConfig.Logger.Console = consoleLogger{
|
||
Enable: true,
|
||
Level: "fatal",
|
||
}
|
||
flogger := fileLogger{}
|
||
flogger.Level = "error"
|
||
if cv2.FileLogger.Filename != "" {
|
||
flogger.Enable = true
|
||
flogger.Filename = cv2.FileLogger.Filename
|
||
}
|
||
srvConfig.Logger.File = flogger
|
||
|
||
slogger := syslogLogger{}
|
||
slogger.Level = "debug"
|
||
if cv2.SyslogLogger.Addr != "" {
|
||
slogger.Enable = true
|
||
slogger.Addr = cv2.SyslogLogger.Addr
|
||
}
|
||
srvConfig.Logger.Syslog = slogger
|
||
|
||
qc, err := quick.New(srvConfig)
|
||
fatalIf(err.Trace(), "Unable to initialize config.", nil)
|
||
|
||
configFile, err := getConfigFile()
|
||
fatalIf(err.Trace(), "Unable to get config file.", nil)
|
||
|
||
// Migrate the config.
|
||
err = qc.Save(configFile)
|
||
fatalIf(err.Trace(), "Migrating from version ‘"+cv2.Version+"’ to ‘"+srvConfig.Version+"’ failed.", nil)
|
||
|
||
console.Println("Migration from version ‘" + cv2.Version + "’ to ‘" + srvConfig.Version + "’ completed successfully.")
|
||
}
|
||
|
||
// Version '3' to '4' migrates config, removes previous fields related
|
||
// to backend types and server address. This change further simplifies
|
||
// the config for future additions.
|
||
func migrateV3ToV4() {
|
||
cv3, err := loadConfigV3()
|
||
if err != nil {
|
||
if os.IsNotExist(err.ToGoError()) {
|
||
return
|
||
}
|
||
}
|
||
fatalIf(err.Trace(), "Unable to load config version ‘3’.", nil)
|
||
if cv3.Version != "3" {
|
||
return
|
||
}
|
||
|
||
// Save only the new fields, ignore the rest.
|
||
srvConfig := &serverConfigV4{}
|
||
srvConfig.Version = globalMinioConfigVersion
|
||
srvConfig.Credential = cv3.Credential
|
||
srvConfig.Region = cv3.Region
|
||
srvConfig.Logger.Console = cv3.Logger.Console
|
||
srvConfig.Logger.File = cv3.Logger.File
|
||
srvConfig.Logger.Syslog = cv3.Logger.Syslog
|
||
|
||
qc, err := quick.New(srvConfig)
|
||
fatalIf(err.Trace(), "Unable to initialize the quick config.", nil)
|
||
configFile, err := getConfigFile()
|
||
fatalIf(err.Trace(), "Unable to get config file.", nil)
|
||
|
||
err = qc.Save(configFile)
|
||
fatalIf(err.Trace(), "Migrating from version ‘"+cv3.Version+"’ to ‘"+srvConfig.Version+"’ failed.", nil)
|
||
|
||
console.Println("Migration from version ‘" + cv3.Version + "’ to ‘" + srvConfig.Version + "’ completed successfully.")
|
||
}
|