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
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
.idea/*
|
||||||
|
|
||||||
# Test binary, build with `go test -c`
|
# Test binary, build with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
/logs/*
|
/logs/*
|
||||||
|
|
||||||
# ignore configuration file
|
# ignore configuration file
|
||||||
/config.json
|
/config.yml
|
||||||
|
|
||||||
# Ignore Vagrant stuff
|
# Ignore Vagrant stuff
|
||||||
/.vagrant
|
/.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"
|
"github.com/Pterodactyl/wings/control"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configFile = "_testdata/config.json"
|
const configFile = "_testdata/config.yml"
|
||||||
|
|
||||||
func TestAuthHandler(t *testing.T) {
|
func TestAuthHandler(t *testing.T) {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
|
@ -7,7 +7,7 @@ func (api *API) registerServerRoutes() {
|
||||||
api.router.POST("/servers", AuthHandler("c:create"), handlePostServers)
|
api.router.POST("/servers", AuthHandler("c:create"), handlePostServers)
|
||||||
api.router.GET("/servers/:server", AuthHandler("s:get"), handleGetServer)
|
api.router.GET("/servers/:server", AuthHandler("s:get"), handleGetServer)
|
||||||
api.router.PATCH("/servers/:server", AuthHandler("s:config"), handlePatchServer)
|
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/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall)
|
||||||
api.router.POST("/servers/:server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild)
|
api.router.POST("/servers/:server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild)
|
||||||
|
|
|
@ -20,7 +20,7 @@ var RootCommand = &cobra.Command{
|
||||||
var configPath string
|
var configPath string
|
||||||
|
|
||||||
func init() {
|
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
|
// Execute registers the RootCommand
|
||||||
|
|
|
@ -34,7 +34,5 @@
|
||||||
"level": "info",
|
"level": "info",
|
||||||
"deleteAfterDays": 100
|
"deleteAfterDays": 100
|
||||||
},
|
},
|
||||||
"authKeys": [
|
"authKey": "somekey"
|
||||||
"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)
|
viper.SetConfigFile(path)
|
||||||
} else {
|
} else {
|
||||||
viper.AddConfigPath("./")
|
viper.AddConfigPath("./")
|
||||||
|
viper.SetConfigType("yaml")
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ func setDefaults() {
|
||||||
|
|
||||||
// ContainsAuthKey checks wether the config contains a specified authentication key
|
// ContainsAuthKey checks wether the config contains a specified authentication key
|
||||||
func ContainsAuthKey(key string) bool {
|
func ContainsAuthKey(key string) bool {
|
||||||
for _, k := range viper.GetStringSlice(AuthKeys) {
|
for _, k := range viper.GetStringSlice(AuthKey) {
|
||||||
if k == key {
|
if k == key {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configFile = "../config.example.json"
|
const configFile = "../config.yml.example"
|
||||||
|
|
||||||
func TestLoadConfiguraiton(t *testing.T) {
|
func TestLoadConfiguraiton(t *testing.T) {
|
||||||
err := LoadConfiguration(configFile)
|
err := LoadConfiguration(configFile)
|
||||||
|
|
|
@ -21,7 +21,7 @@ const (
|
||||||
SSLGenerateLetsencrypt = "api.ssl.letsencrypt"
|
SSLGenerateLetsencrypt = "api.ssl.letsencrypt"
|
||||||
// SSLCertificate is a string containing the location of
|
// SSLCertificate is a string containing the location of
|
||||||
// a ssl certificate to use
|
// a ssl certificate to use
|
||||||
SSLCertificate = "api.ssl.certificate"
|
SSLCertificate = "api.ssl.cert"
|
||||||
// SSLKey is a string containing the location of the key
|
// SSLKey is a string containing the location of the key
|
||||||
// for the ssl certificate
|
// for the ssl certificate
|
||||||
SSLKey = "api.ssl.key"
|
SSLKey = "api.ssl.key"
|
||||||
|
@ -61,6 +61,6 @@ const (
|
||||||
// logs should be stored. They will be deleted after. If set to 0
|
// logs should be stored. They will be deleted after. If set to 0
|
||||||
// logs will be stored indefinitely.
|
// logs will be stored indefinitely.
|
||||||
LogDeleteAfterDays = "log.deleteAfterDays"
|
LogDeleteAfterDays = "log.deleteAfterDays"
|
||||||
// AuthKeys contains an array of auth keys that will be replaced by something better
|
// AuthKey contains a key that will be replaced by something better
|
||||||
AuthKeys = "authkeys"
|
AuthKey = "authKey"
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package tools
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
|
"github.com/lestrrat/go-file-rotatelogs"
|
||||||
"github.com/rifflock/lfshook"
|
"github.com/rifflock/lfshook"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user