mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Remove global custom config path variables, use get/set methods instead
This commit is contained in:
parent
893782ffab
commit
da8b9fd112
@ -39,6 +39,9 @@ type Config struct {
|
|||||||
|
|
||||||
// getAuthConfigPath get donut config file path
|
// getAuthConfigPath get donut config file path
|
||||||
func getAuthConfigPath() (string, error) {
|
func getAuthConfigPath() (string, error) {
|
||||||
|
if customConfigPath != "" {
|
||||||
|
return customConfigPath, nil
|
||||||
|
}
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", iodine.New(err, nil)
|
return "", iodine.New(err, nil)
|
||||||
@ -47,21 +50,20 @@ func getAuthConfigPath() (string, error) {
|
|||||||
return authConfigPath, nil
|
return authConfigPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE - this is not thread safe use it carefully, currently its purpose is only for testing purposes.
|
// customConfigPath not accessed from outside only allowed through get/set methods
|
||||||
var CustomConfigPath string
|
var customConfigPath string
|
||||||
|
|
||||||
|
// SetAuthConfigPath - set custom auth config path
|
||||||
|
func SetAuthConfigPath(configPath string) {
|
||||||
|
customConfigPath = configPath
|
||||||
|
}
|
||||||
|
|
||||||
// SaveConfig save donut config
|
// SaveConfig save donut config
|
||||||
func SaveConfig(a *Config) error {
|
func SaveConfig(a *Config) error {
|
||||||
var authConfigPath string
|
authConfigPath, err := getAuthConfigPath()
|
||||||
var err error
|
|
||||||
if CustomConfigPath != "" {
|
|
||||||
authConfigPath = CustomConfigPath
|
|
||||||
} else {
|
|
||||||
authConfigPath, err = getAuthConfigPath()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
qc, err := quick.New(a)
|
qc, err := quick.New(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
@ -74,16 +76,10 @@ func SaveConfig(a *Config) error {
|
|||||||
|
|
||||||
// LoadConfig load donut config
|
// LoadConfig load donut config
|
||||||
func LoadConfig() (*Config, error) {
|
func LoadConfig() (*Config, error) {
|
||||||
var authConfigPath string
|
authConfigPath, err := getAuthConfigPath()
|
||||||
var err error
|
|
||||||
if CustomConfigPath != "" {
|
|
||||||
authConfigPath = CustomConfigPath
|
|
||||||
} else {
|
|
||||||
authConfigPath, err = getAuthConfigPath()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
a := &Config{}
|
a := &Config{}
|
||||||
a.Version = "0.0.1"
|
a.Version = "0.0.1"
|
||||||
a.Users = make(map[string]*User)
|
a.Users = make(map[string]*User)
|
||||||
|
@ -26,6 +26,9 @@ import (
|
|||||||
|
|
||||||
// getDonutConfigPath get donut config file path
|
// getDonutConfigPath get donut config file path
|
||||||
func getDonutConfigPath() (string, error) {
|
func getDonutConfigPath() (string, error) {
|
||||||
|
if customConfigPath != "" {
|
||||||
|
return customConfigPath, nil
|
||||||
|
}
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", iodine.New(err, nil)
|
return "", iodine.New(err, nil)
|
||||||
@ -34,21 +37,20 @@ func getDonutConfigPath() (string, error) {
|
|||||||
return donutConfigPath, nil
|
return donutConfigPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE - this is not thread safe use it carefully, currently its purpose is only for testing purposes.
|
// internal variable only accessed via get/set methods
|
||||||
var CustomConfigPath string
|
var customConfigPath string
|
||||||
|
|
||||||
|
// SetDonutConfigPath - set custom donut config path
|
||||||
|
func SetDonutConfigPath(configPath string) {
|
||||||
|
customConfigPath = configPath
|
||||||
|
}
|
||||||
|
|
||||||
// SaveConfig save donut config
|
// SaveConfig save donut config
|
||||||
func SaveConfig(a *Config) error {
|
func SaveConfig(a *Config) error {
|
||||||
var donutConfigPath string
|
donutConfigPath, err := getDonutConfigPath()
|
||||||
var err error
|
|
||||||
if CustomConfigPath != "" {
|
|
||||||
donutConfigPath = CustomConfigPath
|
|
||||||
} else {
|
|
||||||
donutConfigPath, err = getDonutConfigPath()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
qc, err := quick.New(a)
|
qc, err := quick.New(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
@ -61,16 +63,10 @@ func SaveConfig(a *Config) error {
|
|||||||
|
|
||||||
// LoadConfig load donut config
|
// LoadConfig load donut config
|
||||||
func LoadConfig() (*Config, error) {
|
func LoadConfig() (*Config, error) {
|
||||||
var donutConfigPath string
|
donutConfigPath, err := getDonutConfigPath()
|
||||||
var err error
|
|
||||||
if CustomConfigPath != "" {
|
|
||||||
donutConfigPath = CustomConfigPath
|
|
||||||
} else {
|
|
||||||
donutConfigPath, err = getDonutConfigPath()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
a := &Config{}
|
a := &Config{}
|
||||||
a.Version = "0.0.1"
|
a.Version = "0.0.1"
|
||||||
qc, err := quick.New(a)
|
qc, err := quick.New(a)
|
||||||
|
@ -66,7 +66,7 @@ func (s *MyDonutSuite) SetUpSuite(c *C) {
|
|||||||
conf.DonutName = "test"
|
conf.DonutName = "test"
|
||||||
conf.NodeDiskMap = createTestNodeDiskMap(root)
|
conf.NodeDiskMap = createTestNodeDiskMap(root)
|
||||||
conf.MaxSize = 100000
|
conf.MaxSize = 100000
|
||||||
CustomConfigPath = filepath.Join(root, "donut.json")
|
SetDonutConfigPath(filepath.Join(root, "donut.json"))
|
||||||
err = SaveConfig(conf)
|
err = SaveConfig(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func (s *MyCacheSuite) SetUpSuite(c *C) {
|
|||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
s.root = root
|
s.root = root
|
||||||
|
|
||||||
CustomConfigPath = filepath.Join(root, "donut.json")
|
SetDonutConfigPath(filepath.Join(root, "donut.json"))
|
||||||
dc, err = New()
|
dc, err = New()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
@ -46,15 +46,6 @@ const (
|
|||||||
yyyymmdd = "20060102"
|
yyyymmdd = "20060102"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ignoredHeaders = map[string]bool{
|
|
||||||
"Authorization": true,
|
|
||||||
"Content-Type": true,
|
|
||||||
"Accept-Encoding": true,
|
|
||||||
"Content-Length": true,
|
|
||||||
"User-Agent": true,
|
|
||||||
"Connection": true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// sumHMAC calculate hmac between two input byte array
|
// sumHMAC calculate hmac between two input byte array
|
||||||
func sumHMAC(key []byte, data []byte) []byte {
|
func sumHMAC(key []byte, data []byte) []byte {
|
||||||
hash := hmac.New(sha256.New, key)
|
hash := hmac.New(sha256.New, key)
|
||||||
|
@ -51,7 +51,7 @@ func (s *MyAPIDonutCacheSuite) SetUpSuite(c *C) {
|
|||||||
conf := &donut.Config{}
|
conf := &donut.Config{}
|
||||||
conf.Version = "0.0.1"
|
conf.Version = "0.0.1"
|
||||||
conf.MaxSize = 100000
|
conf.MaxSize = 100000
|
||||||
donut.CustomConfigPath = filepath.Join(root, "donut.json")
|
donut.SetDonutConfigPath(filepath.Join(root, "donut.json"))
|
||||||
err = donut.SaveConfig(conf)
|
err = donut.SaveConfig(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func (s *MyAPIDonutSuite) SetUpSuite(c *C) {
|
|||||||
conf.DonutName = "test"
|
conf.DonutName = "test"
|
||||||
conf.NodeDiskMap = createTestNodeDiskMap(root)
|
conf.NodeDiskMap = createTestNodeDiskMap(root)
|
||||||
conf.MaxSize = 100000
|
conf.MaxSize = 100000
|
||||||
donut.CustomConfigPath = filepath.Join(root, "donut.json")
|
donut.SetDonutConfigPath(filepath.Join(root, "donut.json"))
|
||||||
err = donut.SaveConfig(conf)
|
err = donut.SaveConfig(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) {
|
|||||||
conf.DonutName = "test"
|
conf.DonutName = "test"
|
||||||
conf.NodeDiskMap = createTestNodeDiskMap(root)
|
conf.NodeDiskMap = createTestNodeDiskMap(root)
|
||||||
conf.MaxSize = 100000
|
conf.MaxSize = 100000
|
||||||
donut.CustomConfigPath = filepath.Join(root, "donut.json")
|
donut.SetDonutConfigPath(filepath.Join(root, "donut.json"))
|
||||||
err = donut.SaveConfig(conf)
|
err = donut.SaveConfig(conf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) {
|
|||||||
s.accessKeyID = string(accessKeyID)
|
s.accessKeyID = string(accessKeyID)
|
||||||
s.secretAccessKey = string(secretAccessKey)
|
s.secretAccessKey = string(secretAccessKey)
|
||||||
|
|
||||||
auth.CustomConfigPath = filepath.Join(root, "users.json")
|
auth.SetAuthConfigPath(filepath.Join(root, "users.json"))
|
||||||
err = auth.SaveConfig(authConf)
|
err = auth.SaveConfig(authConf)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user