Change to using yml for configuration files
This commit is contained in:
parent
5ed3bb2a0c
commit
256c566dfe
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -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
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"authKeys": [
|
||||
"existingkey"
|
||||
]
|
||||
}
|
1
api/_testdata/config.yml
Normal file
1
api/_testdata/config.yml
Normal file
|
@ -0,0 +1 @@
|
|||
authKey: 'existingkey'
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,7 +34,5 @@
|
|||
"level": "info",
|
||||
"deleteAfterDays": 100
|
||||
},
|
||||
"authKeys": [
|
||||
"somekey"
|
||||
]
|
||||
"authKey": "somekey"
|
||||
}
|
||||
|
|
28
config.yml
Normal file
28
config.yml
Normal 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
28
config.yml.example
Normal 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'
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user