2017-06-18 22:01:44 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2017-07-06 18:49:36 +00:00
|
|
|
// LoadConfiguration loads the configuration from a specified file
|
|
|
|
func LoadConfiguration(path string) error {
|
|
|
|
if path != "" {
|
|
|
|
viper.SetConfigFile(path)
|
2017-06-26 19:04:11 +00:00
|
|
|
} else {
|
|
|
|
viper.AddConfigPath("./")
|
|
|
|
viper.SetConfigName("config")
|
|
|
|
}
|
|
|
|
|
2017-06-18 22:01:44 +00:00
|
|
|
// Find and read the config file
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-31 18:13:01 +00:00
|
|
|
// StoreConfiguration stores the configuration to a specified file
|
|
|
|
func StoreConfiguration(path string) error {
|
|
|
|
// TODO: Implement
|
|
|
|
|
|
|
|
return nil
|
2017-06-26 09:07:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 22:01:44 +00:00
|
|
|
func setDefaults() {
|
2017-08-31 18:13:01 +00:00
|
|
|
viper.SetDefault(Debug, false)
|
|
|
|
viper.SetDefault(DataPath, "./data")
|
|
|
|
viper.SetDefault(APIHost, "0.0.0.0")
|
|
|
|
viper.SetDefault(APIPort, 8080)
|
|
|
|
viper.SetDefault(SSLEnabled, false)
|
|
|
|
viper.SetDefault(SSLGenerateLetsencrypt, false)
|
|
|
|
viper.SetDefault(UploadsMaximumSize, 100000)
|
|
|
|
viper.SetDefault(DockerSocket, "/var/run/docker.sock")
|
|
|
|
viper.SetDefault(DockerAutoupdateImages, true)
|
|
|
|
viper.SetDefault(DockerNetworkInterface, "127.18.0.0")
|
|
|
|
viper.SetDefault(DockerTimezonePath, "/etc/timezone")
|
|
|
|
viper.SetDefault(SftpHost, "0.0.0.0")
|
|
|
|
viper.SetDefault(SftpPort, "2202")
|
|
|
|
viper.SetDefault(LogPath, "./logs")
|
|
|
|
viper.SetDefault(LogLevel, "info")
|
|
|
|
viper.SetDefault(LogDeleteAfterDays, "30")
|
2017-06-18 22:01:44 +00:00
|
|
|
}
|
2017-07-06 18:49:36 +00:00
|
|
|
|
|
|
|
// ContainsAuthKey checks wether the config contains a specified authentication key
|
2017-08-31 18:13:01 +00:00
|
|
|
func ContainsAuthKey(key string) bool {
|
|
|
|
for _, k := range viper.GetStringSlice(AuthKeys) {
|
2017-07-06 18:49:36 +00:00
|
|
|
if k == key {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|