Change to using yml for configuration files

This commit is contained in:
Dane Everitt 2017-09-30 17:25:04 -05:00
parent 5ed3bb2a0c
commit 256c566dfe
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
13 changed files with 70 additions and 18 deletions

3
.gitignore vendored
View File

@ -3,6 +3,7 @@
*.dll
*.so
*.dylib
.idea/*
# Test binary, build with `go test -c`
*.test
@ -20,7 +21,7 @@
/logs/*
# ignore configuration file
/config.json
/config.yml
# Ignore Vagrant stuff
/.vagrant

View File

@ -1,5 +0,0 @@
{
"authKeys": [
"existingkey"
]
}

1
api/_testdata/config.yml Normal file
View File

@ -0,0 +1 @@
authKey: 'existingkey'

View File

@ -12,7 +12,7 @@ import (
"github.com/Pterodactyl/wings/control"
)
const configFile = "_testdata/config.json"
const configFile = "_testdata/config.yml"
func TestAuthHandler(t *testing.T) {
gin.SetMode(gin.ReleaseMode)

View File

@ -7,7 +7,7 @@ func (api *API) registerServerRoutes() {
api.router.POST("/servers", AuthHandler("c:create"), handlePostServers)
api.router.GET("/servers/:server", AuthHandler("s:get"), handleGetServer)
api.router.PATCH("/servers/:server", AuthHandler("s:config"), handlePatchServer)
api.router.DELETE("/servers/:server", AuthHandler("g:server:delete"), handleDeleteServer)
//api.router.DELETE("/servers/:server", AuthHandler("g:server:delete"), handleDeleteServer)
api.router.POST("/servers/:server/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall)
api.router.POST("/servers/:server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild)

View File

@ -20,7 +20,7 @@ var RootCommand = &cobra.Command{
var configPath string
func init() {
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.json", "Allows to set the path of the configuration file.")
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
}
// Execute registers the RootCommand

View File

@ -34,7 +34,5 @@
"level": "info",
"deleteAfterDays": 100
},
"authKeys": [
"somekey"
]
"authKey": "somekey"
}

28
config.yml Normal file
View File

@ -0,0 +1,28 @@
debug: true
data: '/srv/daemon-data'
api:
host: '0.0.0.0'
port: 8080
ssl:
enabled: false
cert: ''
key: ''
uploads:
maximumSize: 150000000
docker:
socket: '/var/run/docker.sock'
autoupdateImages: true
networkInterface: '172.18.0.1'
timezonePath: '/etc/timezone'
sftp:
host: '0.0.0.0'
port: 2022
query:
killOnFail: false
failLimit: 5
remote: 'http://pterodactyl.app'
log:
path: './logs/'
level: 'debug'
deleteAfterDays: 10
authKey: 'test123'

28
config.yml.example Normal file
View File

@ -0,0 +1,28 @@
debug: false
data: '/srv/daemon-data'
api:
host: '0.0.0.0'
port: 8080
ssl:
enabled: false
cert: ''
key: ''
uploads:
maximumSize: 150000000
docker:
socket: '/var/run/docker.sock'
autoupdateImages: true
networkInterface: '172.18.0.1'
timezonePath: '/etc/timezone'
sftp:
host: '0.0.0.0'
port: 2022
query:
killOnFail: true
failLimit: 5
remote: 'http://example.com'
log:
path: './logs/'
level: 'info'
deleteAfterDays: 10
authKey: 'test123'

View File

@ -10,6 +10,7 @@ func LoadConfiguration(path string) error {
viper.SetConfigFile(path)
} else {
viper.AddConfigPath("./")
viper.SetConfigType("yaml")
viper.SetConfigName("config")
}
@ -49,7 +50,7 @@ func setDefaults() {
// ContainsAuthKey checks wether the config contains a specified authentication key
func ContainsAuthKey(key string) bool {
for _, k := range viper.GetStringSlice(AuthKeys) {
for _, k := range viper.GetStringSlice(AuthKey) {
if k == key {
return true
}

View File

@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
)
const configFile = "../config.example.json"
const configFile = "../config.yml.example"
func TestLoadConfiguraiton(t *testing.T) {
err := LoadConfiguration(configFile)

View File

@ -21,7 +21,7 @@ const (
SSLGenerateLetsencrypt = "api.ssl.letsencrypt"
// SSLCertificate is a string containing the location of
// a ssl certificate to use
SSLCertificate = "api.ssl.certificate"
SSLCertificate = "api.ssl.cert"
// SSLKey is a string containing the location of the key
// for the ssl certificate
SSLKey = "api.ssl.key"
@ -61,6 +61,6 @@ const (
// 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"
// AuthKey contains a key that will be replaced by something better
AuthKey = "authKey"
)

View File

@ -3,7 +3,7 @@ package tools
import (
"time"
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
"github.com/lestrrat/go-file-rotatelogs"
"github.com/rifflock/lfshook"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"