You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
6.3 KiB
277 lines
6.3 KiB
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
|
||
|
"github.com/minio/minio/pkg/quick"
|
||
|
)
|
||
|
|
||
|
/////////////////// Config V1 ///////////////////
|
||
|
type configV1 struct {
|
||
|
Version string `json:"version"`
|
||
|
AccessKeyID string `json:"accessKeyId"`
|
||
|
SecretAccessKey string `json:"secretAccessKey"`
|
||
|
}
|
||
|
|
||
|
// loadConfigV1 load config
|
||
9 years ago
|
func loadConfigV1() (*configV1, error) {
|
||
9 years ago
|
configPath, err := getConfigPath()
|
||
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
|
configFile := filepath.Join(configPath, "fsUsers.json")
|
||
9 years ago
|
if _, err = os.Stat(configFile); err != nil {
|
||
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
c := &configV1{}
|
||
|
c.Version = "1"
|
||
|
qc, err := quick.New(c)
|
||
9 years ago
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
|
if err := qc.Load(configFile); err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
return c, nil
|
||
9 years ago
|
}
|
||
|
|
||
|
/////////////////// Config V2 ///////////////////
|
||
|
type configV2 struct {
|
||
|
Version string `json:"version"`
|
||
|
Credentials struct {
|
||
|
AccessKeyID string `json:"accessKeyId"`
|
||
|
SecretAccessKey string `json:"secretAccessKey"`
|
||
|
Region string `json:"region"`
|
||
|
} `json:"credentials"`
|
||
|
MongoLogger struct {
|
||
|
Addr string `json:"addr"`
|
||
|
DB string `json:"db"`
|
||
|
Collection string `json:"collection"`
|
||
|
} `json:"mongoLogger"`
|
||
|
SyslogLogger struct {
|
||
|
Network string `json:"network"`
|
||
|
Addr string `json:"addr"`
|
||
|
} `json:"syslogLogger"`
|
||
|
FileLogger struct {
|
||
|
Filename string `json:"filename"`
|
||
|
} `json:"fileLogger"`
|
||
|
}
|
||
|
|
||
|
// loadConfigV2 load config version '2'.
|
||
9 years ago
|
func loadConfigV2() (*configV2, error) {
|
||
9 years ago
|
configFile, err := getConfigFile()
|
||
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
if _, err = os.Stat(configFile); err != nil {
|
||
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
c := &configV2{}
|
||
|
c.Version = "2"
|
||
|
qc, err := quick.New(c)
|
||
9 years ago
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
|
if err := qc.Load(configFile); err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
return c, nil
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
/////////////////// Config V3 ///////////////////
|
||
|
|
||
|
// backendV3 type.
|
||
|
type backendV3 struct {
|
||
|
Type string `json:"type"`
|
||
|
Disk string `json:"disk,omitempty"`
|
||
|
Disks []string `json:"disks,omitempty"`
|
||
|
}
|
||
|
|
||
|
// loggerV3 type.
|
||
|
type loggerV3 struct {
|
||
|
Console struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Level string `json:"level"`
|
||
|
}
|
||
|
File struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Filename string `json:"fileName"`
|
||
|
Level string `json:"level"`
|
||
|
}
|
||
|
Syslog struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Addr string `json:"address"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"syslog"`
|
||
|
// Add new loggers here.
|
||
|
}
|
||
|
|
||
|
// configV3 server configuration version '3'.
|
||
|
type configV3 struct {
|
||
|
Version string `json:"version"`
|
||
|
|
||
|
// Backend configuration.
|
||
|
Backend backendV3 `json:"backend"`
|
||
|
|
||
|
// http Server configuration.
|
||
|
Addr string `json:"address"`
|
||
|
|
||
|
// S3 API configuration.
|
||
|
Credential credential `json:"credential"`
|
||
|
Region string `json:"region"`
|
||
|
|
||
|
// Additional error logging configuration.
|
||
|
Logger loggerV3 `json:"logger"`
|
||
|
}
|
||
|
|
||
|
// loadConfigV3 load config version '3'.
|
||
9 years ago
|
func loadConfigV3() (*configV3, error) {
|
||
9 years ago
|
configFile, err := getConfigFile()
|
||
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
if _, err = os.Stat(configFile); err != nil {
|
||
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
c := &configV3{}
|
||
|
c.Version = "3"
|
||
|
qc, err := quick.New(c)
|
||
9 years ago
|
if err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
|
if err := qc.Load(configFile); err != nil {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
return c, nil
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// logger type representing version '4' logger config.
|
||
9 years ago
|
type loggerV4 struct {
|
||
|
Console struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"console"`
|
||
|
File struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Filename string `json:"fileName"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"file"`
|
||
|
Syslog struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Addr string `json:"address"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"syslog"`
|
||
|
}
|
||
|
|
||
|
// configV4 server configuration version '4'.
|
||
|
type configV4 struct {
|
||
|
Version string `json:"version"`
|
||
|
|
||
|
// S3 API configuration.
|
||
|
Credential credential `json:"credential"`
|
||
|
Region string `json:"region"`
|
||
|
|
||
|
// Additional error logging configuration.
|
||
|
Logger loggerV4 `json:"logger"`
|
||
|
}
|
||
|
|
||
|
// loadConfigV4 load config version '4'.
|
||
|
func loadConfigV4() (*configV4, error) {
|
||
|
configFile, err := getConfigFile()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if _, err = os.Stat(configFile); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
c := &configV4{}
|
||
|
c.Version = "4"
|
||
|
qc, err := quick.New(c)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := qc.Load(configFile); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return c, nil
|
||
|
}
|
||
9 years ago
|
|
||
|
// logger type representing version '5' logger config.
|
||
|
type loggerV5 struct {
|
||
|
Console struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"console"`
|
||
|
File struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Filename string `json:"fileName"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"file"`
|
||
|
Syslog struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Addr string `json:"address"`
|
||
|
Level string `json:"level"`
|
||
|
} `json:"syslog"`
|
||
|
AMQP struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Level string `json:"level"`
|
||
|
URL string `json:"url"`
|
||
|
Exchange string `json:"exchange"`
|
||
8 years ago
|
RoutingKey string `json:"routingKey"`
|
||
9 years ago
|
ExchangeType string `json:"exchangeType"`
|
||
|
Mandatory bool `json:"mandatory"`
|
||
|
Immediate bool `json:"immediate"`
|
||
|
Durable bool `json:"durable"`
|
||
|
Internal bool `json:"internal"`
|
||
|
NoWait bool `json:"noWait"`
|
||
|
AutoDeleted bool `json:"autoDeleted"`
|
||
|
} `json:"amqp"`
|
||
|
ElasticSearch struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Level string `json:"level"`
|
||
|
URL string `json:"url"`
|
||
|
Index string `json:"index"`
|
||
|
} `json:"elasticsearch"`
|
||
|
Redis struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Level string `json:"level"`
|
||
|
Addr string `json:"address"`
|
||
|
Password string `json:"password"`
|
||
|
Key string `json:"key"`
|
||
|
} `json:"redis"`
|
||
|
}
|
||
|
|
||
|
// configV5 server configuration version '5'.
|
||
|
type configV5 struct {
|
||
|
Version string `json:"version"`
|
||
|
|
||
|
// S3 API configuration.
|
||
|
Credential credential `json:"credential"`
|
||
|
Region string `json:"region"`
|
||
|
|
||
|
// Additional error logging configuration.
|
||
|
Logger loggerV5 `json:"logger"`
|
||
|
}
|
||
|
|
||
|
// loadConfigV5 load config version '5'.
|
||
|
func loadConfigV5() (*configV5, error) {
|
||
|
configFile, err := getConfigFile()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if _, err = os.Stat(configFile); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
c := &configV5{}
|
||
|
c.Version = "5"
|
||
|
qc, err := quick.New(c)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := qc.Load(configFile); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return c, nil
|
||
|
}
|