config: use constants with config keys instead of struct as its easier to handle
This commit is contained in:
@@ -9,6 +9,8 @@ type Config struct {
|
||||
// Debug enables debug mode
|
||||
Debug bool `mapstructure:"debug"`
|
||||
|
||||
DataPath string `mapstructure:"dataPath"`
|
||||
|
||||
// Web contains the settings of the api webserver
|
||||
Web struct {
|
||||
// ListenHost is the host address to bind the api webserver to
|
||||
@@ -49,8 +51,6 @@ type Config struct {
|
||||
|
||||
// Sftp contains information on the integrated sftp server
|
||||
Sftp struct {
|
||||
// Path is the base path of the sftp server
|
||||
Path string `mapstructure:"path"`
|
||||
// Port is the port to bind the sftp server to
|
||||
Port int16 `mapstructure:"port"`
|
||||
} `mapstructure:"sftp"`
|
||||
@@ -80,6 +80,7 @@ type Config struct {
|
||||
AuthKeys []string `mapstructure:"authKeys"`
|
||||
}
|
||||
|
||||
var configPath string
|
||||
var config *Config
|
||||
|
||||
// LoadConfiguration loads the configuration from a specified file
|
||||
@@ -96,26 +97,38 @@ func LoadConfiguration(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
config = new(Config)
|
||||
if err := viper.Unmarshal(config); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StoreConfiguration stores the configuration to a specified file
|
||||
func StoreConfiguration(path string) error {
|
||||
// TODO: Implement
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get returns the configuration
|
||||
func Get() *Config {
|
||||
return config
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
// ContainsAuthKey checks wether the config contains a specified authentication key
|
||||
func (c *Config) ContainsAuthKey(key string) bool {
|
||||
for _, k := range c.AuthKeys {
|
||||
func ContainsAuthKey(key string) bool {
|
||||
for _, k := range viper.GetStringSlice(AuthKeys) {
|
||||
if k == key {
|
||||
return true
|
||||
}
|
||||
|
||||
66
config/keys.go
Normal file
66
config/keys.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package config
|
||||
|
||||
const (
|
||||
// Debug is a boolean value that enables debug mode
|
||||
Debug = "debug"
|
||||
|
||||
// DataPath is a string containing the path where data should
|
||||
// be stored on the system
|
||||
DataPath = "datapath"
|
||||
|
||||
// APIHost is a string containing the interface ip address
|
||||
// on what the api should listen on
|
||||
APIHost = "api.host"
|
||||
// APIPort is an integer containing the port the api should
|
||||
// listen on
|
||||
APIPort = "api.port"
|
||||
// SSLEnabled is a boolean that states whether ssl should be enabled or not
|
||||
SSLEnabled = "api.ssl.enabled"
|
||||
// SSLGenerateLetsencrypt is a boolean that enables automatic SSL certificate
|
||||
// creation with letsencrypt
|
||||
SSLGenerateLetsencrypt = "api.ssl.letsencrypt"
|
||||
// SSLCertificate is a string containing the location of
|
||||
// a ssl certificate to use
|
||||
SSLCertificate = "api.ssl.certificate"
|
||||
// SSLKey is a string containing the location of the key
|
||||
// for the ssl certificate
|
||||
SSLKey = "api.ssl.key"
|
||||
// UploadsMaximumSize is an integer that sets the maximum size for
|
||||
// file uploads through the api in Kilobytes
|
||||
UploadsMaximumSize = "api.uploads.maximumSize"
|
||||
|
||||
// DockerSocket is a string containing the path to the docker socket
|
||||
DockerSocket = "docker.socket"
|
||||
// DockerAutoupdateImages is a boolean that enables automatic
|
||||
// docker image updates on every server install
|
||||
DockerAutoupdateImages = "docker.autoupdateImages"
|
||||
// DockerNetworkInterface is a string containing the network interface
|
||||
// to use for the wings docker network
|
||||
DockerNetworkInterface = "docker.networkInterface"
|
||||
// DockerTimezonePath is a string containing the path to the timezone
|
||||
// file that should be mounted into all containers
|
||||
DockerTimezonePath = "docker.timezonePath"
|
||||
|
||||
// SftpHost is a string containing the interface ip address on
|
||||
// which the sftp server should be listening
|
||||
SftpHost = "sftp.host"
|
||||
// SftpPort is an integer containing the port the sftp servers hould
|
||||
// be listening on
|
||||
SftpPort = "sftp.port"
|
||||
|
||||
// Remote is a string containing the url to the Pterodactyl panel
|
||||
// wings should send updates to
|
||||
Remote = "remote"
|
||||
|
||||
// LogPath is a string containing the path where logfiles should be
|
||||
// stored
|
||||
LogPath = "log.path"
|
||||
// LogLevel is a string containing the log level
|
||||
LogLevel = "log.level"
|
||||
// LogDeleteAfterDays is an integer containing the amounts of days
|
||||
// logs should be stored. They will be deleted after. If set to 0
|
||||
// logs will be stored indefinitely.
|
||||
LogDeleteAfterDays = "log.deleteAfterDays"
|
||||
// AuthKeys contains an array of auth keys that will be replaced by something better
|
||||
AuthKeys = "authkeys"
|
||||
)
|
||||
Reference in New Issue
Block a user