Fix configuration file saving to disk using the config command
closes pterodactyl/panel#2135
This commit is contained in:
parent
2dad3102e0
commit
05a4730489
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/AlecAivazis/survey/v2/terminal"
|
"github.com/AlecAivazis/survey/v2/terminal"
|
||||||
"github.com/creasty/defaults"
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -147,8 +146,8 @@ func configureCmdRun(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(res.Body)
|
b, err := ioutil.ReadAll(res.Body)
|
||||||
|
|
||||||
cfg := new(config.Configuration)
|
cfg, err := config.NewFromPath(configPath)
|
||||||
if err := defaults.Set(cfg); err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,27 @@ func GetJwtAlgorithm() *jwt.HMACSHA {
|
||||||
return _jwtAlgo
|
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.
|
// Returns the path for this configuration file.
|
||||||
func (c *Configuration) GetPath() string {
|
func (c *Configuration) GetPath() string {
|
||||||
return c.path
|
return c.path
|
||||||
|
|
Loading…
Reference in New Issue
Block a user