Cleanup server sync logic to work in a single consistent format (#101)

* Cleanup server sync logic to work in a single consistent format

Previously we had a mess of a function trying to update server details from a patch request. This change just centralizes everything to a single Sync() call when a server needs to update itself.

We can also eventually update the panel (in V2) to not hit the patch endpoint, rather it can just be a generic endpoint that is hit after a server is updated on the Panel that tells Wings to re-sync the data to get the environment changes on the fly.

The changes I made to the patch function currently act like that, with a slightly fragile 2 second wait to let the panel persist the changes since I don't want this to be a breaking change on that end.

* Remove legacy server patch endpoint; replace with simpler sync endpoint
This commit is contained in:
Dane Everitt
2021-08-29 13:37:18 -07:00
committed by GitHub
parent d4a8f25cc6
commit 5764894a5e
5 changed files with 73 additions and 171 deletions

View File

@@ -6,11 +6,11 @@ import (
"github.com/pterodactyl/wings/remote"
"github.com/pterodactyl/wings/router/middleware"
"github.com/pterodactyl/wings/server"
wserver "github.com/pterodactyl/wings/server"
)
// Configure configures the routing infrastructure for this daemon instance.
func Configure(m *server.Manager, client remote.Client) *gin.Engine {
func Configure(m *wserver.Manager, client remote.Client) *gin.Engine {
gin.SetMode("release")
router := gin.New()
@@ -63,7 +63,6 @@ func Configure(m *server.Manager, client remote.Client) *gin.Engine {
server.Use(middleware.RequireAuthorization(), middleware.ServerExists())
{
server.GET("", getServer)
server.PATCH("", patchServer)
server.DELETE("", deleteServer)
server.GET("/logs", getServerLogs)
@@ -71,6 +70,7 @@ func Configure(m *server.Manager, client remote.Client) *gin.Engine {
server.POST("/commands", postServerCommands)
server.POST("/install", postServerInstall)
server.POST("/reinstall", postServerReinstall)
server.POST("/sync", postServerSync)
server.POST("/ws/deny", postServerDenyWSTokens)
// This archive request causes the archive to start being created

View File

@@ -1,7 +1,6 @@
package router
import (
"bytes"
"context"
"net/http"
"os"
@@ -10,7 +9,6 @@ import (
"emperror.dev/errors"
"github.com/apex/log"
"github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/router/downloader"
"github.com/pterodactyl/wings/router/middleware"
"github.com/pterodactyl/wings/router/tokens"
@@ -130,21 +128,18 @@ func postServerCommands(c *gin.Context) {
c.Status(http.StatusNoContent)
}
// Updates information about a server internally.
func patchServer(c *gin.Context) {
// postServerSync will accept a POST request and trigger a re-sync of the given
// server against the Panel. This can be manually triggered when needed by an
// external system, or triggered by the Panel itself when modifications are made
// to the build of a server internally.
func postServerSync(c *gin.Context) {
s := ExtractServer(c)
buf := bytes.Buffer{}
buf.ReadFrom(c.Request.Body)
if err := s.UpdateDataStructure(buf.Bytes()); err != nil {
NewServerError(err, s).Abort(c)
return
if err := s.Sync(); err != nil {
WithError(c, err)
} else {
c.Status(http.StatusNoContent)
}
s.SyncWithEnvironment()
c.Status(http.StatusNoContent)
}
// Performs a server installation in a background thread.