diff --git a/cmd/root.go b/cmd/root.go index d992e19..ffbf96f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -169,7 +169,7 @@ func rootCmdRun(*cobra.Command, []string) { // Just for some nice log output. for _, s := range server.GetServers().All() { - log.WithField("server", s.Uuid).Info("loaded configuration for server") + log.WithField("server", s.Id()).Info("loaded configuration for server") } // Create a new WaitGroup that limits us to 4 servers being bootstrapped at a time diff --git a/installer/installer.go b/installer/installer.go index 6ca95fd..92ba655 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -89,7 +89,7 @@ func New(data []byte) (*Installer, error) { // Returns the UUID associated with this installer instance. func (i *Installer) Uuid() string { - return i.server.Uuid + return i.server.Id() } // Return the server instance. diff --git a/router/middleware.go b/router/middleware.go index 45c50f8..102d1aa 100644 --- a/router/middleware.go +++ b/router/middleware.go @@ -48,7 +48,7 @@ func AuthorizationMiddleware(c *gin.Context) { // Helper function to fetch a server out of the servers collection stored in memory. func GetServer(uuid string) *server.Server { return server.GetServers().Find(func(s *server.Server) bool { - return uuid == s.Uuid + return uuid == s.Id() }) } diff --git a/router/router_server.go b/router/router_server.go index d8c47a4..ac2bf60 100644 --- a/router/router_server.go +++ b/router/router_server.go @@ -200,9 +200,9 @@ func deleteServer(c *gin.Context) { } }(s.Filesystem.Path()) - var uuid = s.Uuid + var uuid = s.Id() server.GetServers().Remove(func(s2 *server.Server) bool { - return s2.Uuid == uuid + return s2.Id() == uuid }) // Deallocate the reference to this server. diff --git a/router/router_transfer.go b/router/router_transfer.go index 0a1778f..cf3bece 100644 --- a/router/router_transfer.go +++ b/router/router_transfer.go @@ -98,33 +98,33 @@ func postServerArchive(c *gin.Context) { start := time.Now() if err := server.Archiver.Archive(); err != nil { - zap.S().Errorw("failed to get archive for server", zap.String("server", s.Uuid), zap.Error(err)) + zap.S().Errorw("failed to get archive for server", zap.String("server", server.Id()), zap.Error(err)) return } zap.S().Debugw( "successfully created archive for server", - zap.String("server", server.Uuid), + zap.String("server", server.Id()), zap.Duration("time", time.Now().Sub(start).Round(time.Microsecond)), ) r := api.NewRequester() - rerr, err := r.SendArchiveStatus(server.Uuid, true) + rerr, err := r.SendArchiveStatus(server.Id(), true) if rerr != nil || err != nil { if err != nil { - zap.S().Errorw("failed to notify panel with archive status", zap.String("server", server.Uuid), zap.Error(err)) + zap.S().Errorw("failed to notify panel with archive status", zap.String("server", server.Id()), zap.Error(err)) return } zap.S().Errorw( "panel returned an error when sending the archive status", - zap.String("server", server.Uuid), + zap.String("server", server.Id()), zap.Error(errors.New(rerr.String())), ) return } - zap.S().Debugw("successfully notified panel about archive status", zap.String("server", server.Uuid)) + zap.S().Debugw("successfully notified panel about archive status", zap.String("server", server.Id())) }(s) c.Status(http.StatusAccepted) diff --git a/server/archiver.go b/server/archiver.go index d10dfce..d177d76 100644 --- a/server/archiver.go +++ b/server/archiver.go @@ -23,7 +23,7 @@ func (a *Archiver) ArchivePath() string { // ArchiveName returns the name of the server's archive. func (a *Archiver) ArchiveName() string { - return a.Server.Uuid + ".tar.gz" + return a.Server.Id() + ".tar.gz" } // Exists returns a boolean based off if the archive exists. diff --git a/server/install.go b/server/install.go index 6a7805e..5974ab9 100644 --- a/server/install.go +++ b/server/install.go @@ -70,7 +70,7 @@ func (s *Server) Reinstall() error { // Internal installation function used to simplify reporting back to the Panel. func (s *Server) internalInstall() error { - script, rerr, err := api.NewRequester().GetInstallationScript(s.Uuid) + script, rerr, err := api.NewRequester().GetInstallationScript(s.Id()) if err != nil || rerr != nil { if err != nil { return err @@ -170,7 +170,7 @@ func (s *Server) AbortInstallation() { // Removes the installer container for the server. func (ip *InstallationProcess) RemoveContainer() { - err := ip.client.ContainerRemove(ip.context, ip.Server.Uuid+"_installer", types.ContainerRemoveOptions{ + err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", types.ContainerRemoveOptions{ RemoveVolumes: true, Force: true, }) @@ -313,7 +313,7 @@ func (ip *InstallationProcess) BeforeExecute() (string, error) { Force: true, } - if err := ip.client.ContainerRemove(ip.context, ip.Server.Uuid+"_installer", opts); err != nil { + if err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", opts); err != nil { if !client.IsErrNotFound(err) { e = append(e, err) } @@ -333,7 +333,7 @@ func (ip *InstallationProcess) BeforeExecute() (string, error) { // Returns the log path for the installation process. func (ip *InstallationProcess) GetLogPath() string { - return filepath.Join(config.Get().System.GetInstallLogPath(), ip.Server.Uuid+".log") + return filepath.Join(config.Get().System.GetInstallLogPath(), ip.Server.Id()+".log") } // Cleans up after the execution of the installation process. This grabs the logs from the @@ -369,7 +369,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error { | | Details | ------------------------------ - Server UUID: {{.Server.Uuid}} + Server UUID: {{.Server.Id()}} Container Image: {{.Script.ContainerImage}} Container Entrypoint: {{.Script.Entrypoint}} @@ -448,7 +448,7 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) { } ip.Server.Log().WithField("install_script", installPath+"/install.sh").Info("creating install container for server process") - r, err := ip.client.ContainerCreate(ip.context, conf, hostConf, nil, ip.Server.Uuid+"_installer") + r, err := ip.client.ContainerCreate(ip.context, conf, hostConf, nil, ip.Server.Id()+"_installer") if err != nil { return "", errors.WithStack(err) } @@ -516,7 +516,7 @@ func (ip *InstallationProcess) StreamOutput(id string) error { func (s *Server) SyncInstallState(successful bool) error { r := api.NewRequester() - rerr, err := r.SendInstallationStatus(s.Uuid, successful) + rerr, err := r.SendInstallationStatus(s.Id(), successful) if rerr != nil || err != nil { if err != nil { return errors.WithStack(err) diff --git a/server/server.go b/server/server.go index 6e10f1a..e07a340 100644 --- a/server/server.go +++ b/server/server.go @@ -20,11 +20,6 @@ type Server struct { // writing the configuration to the disk. sync.RWMutex - // The unique identifier for the server that should be used when referencing - // it against the Panel API (and internally). This will be used when naming - // docker containers as well as in log output. - Uuid string `json:"-"` - // Maintains the configuration for the server. This is the data that gets returned by the Panel // such as build settings and container images. cfg Configuration @@ -99,7 +94,7 @@ eloop: } func (s *Server) Log() *log.Entry { - return log.WithField("server", s.Uuid) + return log.WithField("server", s.Id()) } // Syncs the state of the server on the Panel with Wings. This ensures that we're always @@ -159,7 +154,7 @@ func (s *Server) CreateEnvironment() error { // Gets the process configuration data for the server. func (s *Server) GetProcessConfiguration() (*api.ServerConfigurationResponse, *api.RequestError, error) { - return api.NewRequester().GetServerConfiguration(s.Uuid) + return api.NewRequester().GetServerConfiguration(s.Id()) } // Helper function that can receieve a power action and then process the diff --git a/server/state.go b/server/state.go index 5ff4ab9..c47c4e6 100644 --- a/server/state.go +++ b/server/state.go @@ -47,7 +47,7 @@ func saveServerStates() error { // Get the states of all servers on the daemon. states := map[string]string{} for _, s := range GetServers().All() { - states[s.Uuid] = s.GetState() + states[s.Id()] = s.GetState() } // Convert the map to a json object. diff --git a/server/update.go b/server/update.go index 5d9a211..7ab63ba 100644 --- a/server/update.go +++ b/server/update.go @@ -23,7 +23,7 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error { // Don't allow obviously corrupted data to pass through into this function. If the UUID // doesn't match something has gone wrong and the API is attempting to meld this server // instance into a totally different one, which would be bad. - if src.Uuid != "" && s.Uuid != "" && src.Uuid != s.Uuid { + if src.Uuid != "" && s.Id() != "" && src.Uuid != s.Id() { return errors.New("attempting to merge a data stack with an invalid UUID") } @@ -95,7 +95,6 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error { // Update the configuration once we have a lock on the configuration object. s.cfg = c - s.Uuid = c.Uuid if background { go s.runBackgroundActions() diff --git a/sftp/server.go b/sftp/server.go index 8a9f243..44617a8 100644 --- a/sftp/server.go +++ b/sftp/server.go @@ -49,7 +49,7 @@ func Initialize(config *config.Configuration) error { func validatePath(fs sftp_server.FileSystem, p string) (string, error) { s := server.GetServers().Find(func(server *server.Server) bool { - return server.Uuid == fs.UUID + return server.Id() == fs.UUID }) if s == nil { @@ -61,7 +61,7 @@ func validatePath(fs sftp_server.FileSystem, p string) (string, error) { func validateDiskSpace(fs sftp_server.FileSystem) bool { s := server.GetServers().Find(func(server *server.Server) bool { - return server.Uuid == fs.UUID + return server.Id() == fs.UUID }) if s == nil { @@ -105,7 +105,7 @@ func validateCredentials(c sftp_server.AuthenticationRequest) (*sftp_server.Auth } s := server.GetServers().Find(func(server *server.Server) bool { - return server.Uuid == resp.Server + return server.Id() == resp.Server }) if s == nil {