Correctly handle updating server data
This commit is contained in:
		
							parent
							
								
									d583c1d53e
								
							
						
					
					
						commit
						189289ad5f
					
				| 
						 | 
					@ -2,7 +2,8 @@ package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/mcuadros/go-defaults"
 | 
						"github.com/creasty/defaults"
 | 
				
			||||||
 | 
						"github.com/pkg/errors"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
	"gopkg.in/yaml.v2"
 | 
						"gopkg.in/yaml.v2"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
| 
						 | 
					@ -189,8 +190,6 @@ func (c *Configuration) SetDefaults() {
 | 
				
			||||||
		Sftp:         &SftpConfiguration{},
 | 
							Sftp:         &SftpConfiguration{},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	defaults.SetDefaults(c.System.Sftp)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// By default the internal webserver should bind to all interfaces and
 | 
						// By default the internal webserver should bind to all interfaces and
 | 
				
			||||||
	// be served on port 8080.
 | 
						// be served on port 8080.
 | 
				
			||||||
	c.Api = &ApiConfiguration{
 | 
						c.Api = &ApiConfiguration{
 | 
				
			||||||
| 
						 | 
					@ -222,9 +221,10 @@ func (c *Configuration) SetDefaults() {
 | 
				
			||||||
			Interfaces: &dockerNetworkInterfaces{},
 | 
								Interfaces: &dockerNetworkInterfaces{},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defaults.SetDefaults(c.Docker)
 | 
					
 | 
				
			||||||
	defaults.SetDefaults(c.Docker.Network)
 | 
						if err := defaults.Set(c); err != nil {
 | 
				
			||||||
	defaults.SetDefaults(c.Docker.Network.Interfaces)
 | 
							zap.S().Warnw("error setting defaults for configuration", zap.Error(errors.WithStack(err)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Reads the configuration from the provided file and returns the configuration
 | 
					// Reads the configuration from the provided file and returns the configuration
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| 
						 | 
					@ -35,7 +35,6 @@ require (
 | 
				
			||||||
	github.com/imdario/mergo v0.3.8
 | 
						github.com/imdario/mergo v0.3.8
 | 
				
			||||||
	github.com/julienschmidt/httprouter v1.2.0
 | 
						github.com/julienschmidt/httprouter v1.2.0
 | 
				
			||||||
	github.com/magiconair/properties v1.8.1
 | 
						github.com/magiconair/properties v1.8.1
 | 
				
			||||||
	github.com/mcuadros/go-defaults v1.1.0
 | 
					 | 
				
			||||||
	github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
 | 
						github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
 | 
				
			||||||
	github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee
 | 
						github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee
 | 
				
			||||||
	github.com/onsi/ginkgo v1.8.0 // indirect
 | 
						github.com/onsi/ginkgo v1.8.0 // indirect
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| 
						 | 
					@ -74,8 +74,6 @@ github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
 | 
				
			||||||
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
 | 
					github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
 | 
				
			||||||
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
 | 
					github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
 | 
				
			||||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 | 
					github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 | 
				
			||||||
github.com/mcuadros/go-defaults v1.1.0 h1:K0LgSNfsSUrbEHR7HgfZpOHVWYsPnYh/dKTA7pGeZ/I=
 | 
					 | 
				
			||||||
github.com/mcuadros/go-defaults v1.1.0/go.mod h1:vl9cJiNIIHISQeboDhZBUCiCOa3GkeioLe3Y95NXF6Y=
 | 
					 | 
				
			||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
 | 
					github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
 | 
				
			||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
 | 
					github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
 | 
				
			||||||
github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee h1:IquUs3fIykn10zWDIyddanhpTqBvAHMaPnFhQuyYw5U=
 | 
					github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee h1:IquUs3fIykn10zWDIyddanhpTqBvAHMaPnFhQuyYw5U=
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ func New(data []byte) (*Installer, error) {
 | 
				
			||||||
		Uuid:       getString(data, "uuid"),
 | 
							Uuid:       getString(data, "uuid"),
 | 
				
			||||||
		Suspended:  false,
 | 
							Suspended:  false,
 | 
				
			||||||
		State:      server.ProcessOfflineState,
 | 
							State:      server.ProcessOfflineState,
 | 
				
			||||||
		Invocation: "",
 | 
							Invocation: getString(data, "invocation"),
 | 
				
			||||||
		EnvVars:    make(map[string]string),
 | 
							EnvVars:    make(map[string]string),
 | 
				
			||||||
		Build: server.BuildSettings{
 | 
							Build: server.BuildSettings{
 | 
				
			||||||
			MemoryLimit: getInt(data, "build", "memory"),
 | 
								MemoryLimit: getInt(data, "build", "memory"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/mcuadros/go-defaults"
 | 
						"github.com/creasty/defaults"
 | 
				
			||||||
	"github.com/patrickmn/go-cache"
 | 
						"github.com/patrickmn/go-cache"
 | 
				
			||||||
	"github.com/pkg/errors"
 | 
						"github.com/pkg/errors"
 | 
				
			||||||
	"github.com/pterodactyl/wings/api"
 | 
						"github.com/pterodactyl/wings/api"
 | 
				
			||||||
| 
						 | 
					@ -211,9 +211,8 @@ func (s *Server) Init() {
 | 
				
			||||||
func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, error) {
 | 
					func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, error) {
 | 
				
			||||||
	s := new(Server)
 | 
						s := new(Server)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	defaults.SetDefaults(s)
 | 
						if err := defaults.Set(s); err != nil {
 | 
				
			||||||
	s.CrashDetection = CrashDetection{
 | 
							return nil, err
 | 
				
			||||||
		Enabled: true,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s.Init()
 | 
						s.Init()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package server
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"github.com/buger/jsonparser"
 | 
						"github.com/buger/jsonparser"
 | 
				
			||||||
 | 
						"github.com/creasty/defaults"
 | 
				
			||||||
	"github.com/imdario/mergo"
 | 
						"github.com/imdario/mergo"
 | 
				
			||||||
	"github.com/pkg/errors"
 | 
						"github.com/pkg/errors"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
| 
						 | 
					@ -29,6 +30,11 @@ func (s *Server) UpdateDataStructure(data []byte) error {
 | 
				
			||||||
		return errors.New("attempting to merge a data stack with an invalid UUID")
 | 
							return errors.New("attempting to merge a data stack with an invalid UUID")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Set the default values in the interface that we unmarshaled into.
 | 
				
			||||||
 | 
						if err := defaults.Set(&src); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Merge the new data object that we have received with the existing server data object
 | 
						// Merge the new data object that we have received with the existing server data object
 | 
				
			||||||
	// and then save it to the disk so it is persistent.
 | 
						// and then save it to the disk so it is persistent.
 | 
				
			||||||
	if err := mergo.Merge(s, src, mergo.WithOverride); err != nil {
 | 
						if err := mergo.Merge(s, src, mergo.WithOverride); err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user