Fix configuration file saving to disk using the config command

closes pterodactyl/panel#2135
This commit is contained in:
Dane Everitt 2020-06-29 20:33:54 -07:00
parent 2dad3102e0
commit 05a4730489
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 23 additions and 3 deletions

View File

@ -6,7 +6,6 @@ import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/creasty/defaults"
"github.com/pterodactyl/wings/config"
"github.com/spf13/cobra"
"io/ioutil"
@ -147,8 +146,8 @@ func configureCmdRun(cmd *cobra.Command, args []string) {
b, err := ioutil.ReadAll(res.Body)
cfg := new(config.Configuration)
if err := defaults.Set(cfg); err != nil {
cfg, err := config.NewFromPath(configPath)
if err != nil {
panic(err)
}

View File

@ -186,6 +186,27 @@ func GetJwtAlgorithm() *jwt.HMACSHA {
return _jwtAlgo
}
// Create a new struct and set the path where it should be stored.
func NewFromPath(path string) (*Configuration, error) {
c := new(Configuration)
if err := defaults.Set(c); err != nil {
return c, err
}
c.unsafeSetPath(path)
return c, nil
}
// Sets the path where the configuration file is located on the server. This function should
// not be called except by processes that are generating the configuration such as the configration
// command shipped with this software.
func (c *Configuration) unsafeSetPath(path string) {
c.Lock()
c.path = path
c.Unlock()
}
// Returns the path for this configuration file.
func (c *Configuration) GetPath() string {
return c.path