wings/config/config.go

60 lines
1.5 KiB
Go
Raw Normal View History

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.SetConfigType("yaml")
2017-06-26 19:04:11 +00:00
viper.SetConfigName("config")
}
// Find and read the config file
if err := viper.ReadInConfig(); err != nil {
return err
}
return nil
}
// StoreConfiguration stores the configuration to a specified file
func StoreConfiguration(path string) error {
// TODO: Implement
return nil
}
func setDefaults() {
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-07-06 18:49:36 +00:00
// ContainsAuthKey checks wether the config contains a specified authentication key
func ContainsAuthKey(key string) bool {
for _, k := range viper.GetStringSlice(AuthKey) {
2017-07-06 18:49:36 +00:00
if k == key {
return true
}
}
return false
}