Move configuration into root space
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// LoadConfiguration loads the configuration from a specified file
|
||||
func LoadConfiguration(path string) error {
|
||||
if path != "" {
|
||||
viper.SetConfigFile(path)
|
||||
} else {
|
||||
viper.AddConfigPath("./")
|
||||
viper.SetConfigType("yaml")
|
||||
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")
|
||||
}
|
||||
|
||||
// ContainsAuthKey checks wether the config contains a specified authentication key
|
||||
func ContainsAuthKey(key string) bool {
|
||||
for _, k := range viper.GetStringSlice(AuthKey) {
|
||||
if k == key {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const configFile = "../config.example.yml"
|
||||
|
||||
func TestLoadConfiguraiton(t *testing.T) {
|
||||
err := LoadConfiguration(configFile)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "0.0.0.0", viper.GetString(APIHost))
|
||||
}
|
||||
|
||||
func TestContainsAuthKey(t *testing.T) {
|
||||
t.Run("key exists", func(t *testing.T) {
|
||||
LoadConfiguration(configFile)
|
||||
assert.True(t, ContainsAuthKey("somekey"))
|
||||
})
|
||||
|
||||
t.Run("key doesn't exist", func(t *testing.T) {
|
||||
LoadConfiguration(configFile)
|
||||
assert.False(t, ContainsAuthKey("someotherkey"))
|
||||
})
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
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 = "data"
|
||||
|
||||
// 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.cert"
|
||||
// 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"
|
||||
// AuthKey contains a key that will be replaced by something better
|
||||
AuthKey = "authKey"
|
||||
)
|
||||
Reference in New Issue
Block a user