diff --git a/pkg/auth/config.go b/pkg/auth/config.go index b1e184df0..7613d54f8 100644 --- a/pkg/auth/config.go +++ b/pkg/auth/config.go @@ -39,6 +39,9 @@ type Config struct { // getAuthConfigPath get donut config file path func getAuthConfigPath() (string, error) { + if customConfigPath != "" { + return customConfigPath, nil + } u, err := user.Current() if err != nil { return "", iodine.New(err, nil) @@ -47,20 +50,19 @@ func getAuthConfigPath() (string, error) { return authConfigPath, nil } -// NOTE - this is not thread safe use it carefully, currently its purpose is only for testing purposes. -var CustomConfigPath string +// customConfigPath not accessed from outside only allowed through get/set methods +var customConfigPath string + +// SetAuthConfigPath - set custom auth config path +func SetAuthConfigPath(configPath string) { + customConfigPath = configPath +} // SaveConfig save donut config func SaveConfig(a *Config) error { - var authConfigPath string - var err error - if CustomConfigPath != "" { - authConfigPath = CustomConfigPath - } else { - authConfigPath, err = getAuthConfigPath() - if err != nil { - return iodine.New(err, nil) - } + authConfigPath, err := getAuthConfigPath() + if err != nil { + return iodine.New(err, nil) } qc, err := quick.New(a) if err != nil { @@ -74,15 +76,9 @@ func SaveConfig(a *Config) error { // LoadConfig load donut config func LoadConfig() (*Config, error) { - var authConfigPath string - var err error - if CustomConfigPath != "" { - authConfigPath = CustomConfigPath - } else { - authConfigPath, err = getAuthConfigPath() - if err != nil { - return nil, iodine.New(err, nil) - } + authConfigPath, err := getAuthConfigPath() + if err != nil { + return nil, iodine.New(err, nil) } a := &Config{} a.Version = "0.0.1" diff --git a/pkg/donut/config.go b/pkg/donut/config.go index 20d6c5787..255753976 100644 --- a/pkg/donut/config.go +++ b/pkg/donut/config.go @@ -26,6 +26,9 @@ import ( // getDonutConfigPath get donut config file path func getDonutConfigPath() (string, error) { + if customConfigPath != "" { + return customConfigPath, nil + } u, err := user.Current() if err != nil { return "", iodine.New(err, nil) @@ -34,20 +37,19 @@ func getDonutConfigPath() (string, error) { return donutConfigPath, nil } -// NOTE - this is not thread safe use it carefully, currently its purpose is only for testing purposes. -var CustomConfigPath string +// internal variable only accessed via get/set methods +var customConfigPath string + +// SetDonutConfigPath - set custom donut config path +func SetDonutConfigPath(configPath string) { + customConfigPath = configPath +} // SaveConfig save donut config func SaveConfig(a *Config) error { - var donutConfigPath string - var err error - if CustomConfigPath != "" { - donutConfigPath = CustomConfigPath - } else { - donutConfigPath, err = getDonutConfigPath() - if err != nil { - return iodine.New(err, nil) - } + donutConfigPath, err := getDonutConfigPath() + if err != nil { + return iodine.New(err, nil) } qc, err := quick.New(a) if err != nil { @@ -61,15 +63,9 @@ func SaveConfig(a *Config) error { // LoadConfig load donut config func LoadConfig() (*Config, error) { - var donutConfigPath string - var err error - if CustomConfigPath != "" { - donutConfigPath = CustomConfigPath - } else { - donutConfigPath, err = getDonutConfigPath() - if err != nil { - return nil, iodine.New(err, nil) - } + donutConfigPath, err := getDonutConfigPath() + if err != nil { + return nil, iodine.New(err, nil) } a := &Config{} a.Version = "0.0.1" diff --git a/pkg/donut/donut-v1_test.go b/pkg/donut/donut-v1_test.go index f3a4e2de4..80fe565e3 100644 --- a/pkg/donut/donut-v1_test.go +++ b/pkg/donut/donut-v1_test.go @@ -66,7 +66,7 @@ func (s *MyDonutSuite) SetUpSuite(c *C) { conf.DonutName = "test" conf.NodeDiskMap = createTestNodeDiskMap(root) conf.MaxSize = 100000 - CustomConfigPath = filepath.Join(root, "donut.json") + SetDonutConfigPath(filepath.Join(root, "donut.json")) err = SaveConfig(conf) c.Assert(err, IsNil) diff --git a/pkg/donut/donut-v2_test.go b/pkg/donut/donut-v2_test.go index 27706dbf9..5c835de0d 100644 --- a/pkg/donut/donut-v2_test.go +++ b/pkg/donut/donut-v2_test.go @@ -44,7 +44,7 @@ func (s *MyCacheSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.root = root - CustomConfigPath = filepath.Join(root, "donut.json") + SetDonutConfigPath(filepath.Join(root, "donut.json")) dc, err = New() c.Assert(err, IsNil) diff --git a/pkg/donut/signature-v4.go b/pkg/donut/signature-v4.go index af5be5ddc..ab942dcd9 100644 --- a/pkg/donut/signature-v4.go +++ b/pkg/donut/signature-v4.go @@ -46,15 +46,6 @@ const ( 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 func sumHMAC(key []byte, data []byte) []byte { hash := hmac.New(sha256.New, key) diff --git a/pkg/server/api_donut_cache_test.go b/pkg/server/api_donut_cache_test.go index 6bd063342..6e3cb04cf 100644 --- a/pkg/server/api_donut_cache_test.go +++ b/pkg/server/api_donut_cache_test.go @@ -51,7 +51,7 @@ func (s *MyAPIDonutCacheSuite) SetUpSuite(c *C) { conf := &donut.Config{} conf.Version = "0.0.1" conf.MaxSize = 100000 - donut.CustomConfigPath = filepath.Join(root, "donut.json") + donut.SetDonutConfigPath(filepath.Join(root, "donut.json")) err = donut.SaveConfig(conf) c.Assert(err, IsNil) diff --git a/pkg/server/api_donut_test.go b/pkg/server/api_donut_test.go index 063f78163..d16abe89c 100644 --- a/pkg/server/api_donut_test.go +++ b/pkg/server/api_donut_test.go @@ -70,7 +70,7 @@ func (s *MyAPIDonutSuite) SetUpSuite(c *C) { conf.DonutName = "test" conf.NodeDiskMap = createTestNodeDiskMap(root) conf.MaxSize = 100000 - donut.CustomConfigPath = filepath.Join(root, "donut.json") + donut.SetDonutConfigPath(filepath.Join(root, "donut.json")) err = donut.SaveConfig(conf) c.Assert(err, IsNil) diff --git a/pkg/server/api_signature_v4_test.go b/pkg/server/api_signature_v4_test.go index 1cab50c79..889ac4a7d 100644 --- a/pkg/server/api_signature_v4_test.go +++ b/pkg/server/api_signature_v4_test.go @@ -59,7 +59,7 @@ func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) { conf.DonutName = "test" conf.NodeDiskMap = createTestNodeDiskMap(root) conf.MaxSize = 100000 - donut.CustomConfigPath = filepath.Join(root, "donut.json") + donut.SetDonutConfigPath(filepath.Join(root, "donut.json")) err = donut.SaveConfig(conf) c.Assert(err, IsNil) @@ -78,7 +78,7 @@ func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) { s.accessKeyID = string(accessKeyID) s.secretAccessKey = string(secretAccessKey) - auth.CustomConfigPath = filepath.Join(root, "users.json") + auth.SetAuthConfigPath(filepath.Join(root, "users.json")) err = auth.SaveConfig(authConf) c.Assert(err, IsNil)