Add support for modifying daemon configuration on-the-fly

This commit is contained in:
Dane Everitt
2020-04-11 16:17:46 -07:00
parent 03045c94be
commit 083bea5504
5 changed files with 52 additions and 15 deletions

View File

@@ -30,6 +30,7 @@ func Configure() *gin.Engine {
// All of the routes beyond this mount will use an authorization middleware
// and will not be accessible without the correct Authorization header provided.
protected := router.Use(AuthorizationMiddleware)
protected.POST("/api/update", postUpdateConfiguration)
protected.GET("/api/system", getSystemInformation)
protected.GET("/api/servers", getAllServers)
protected.POST("/api/servers", postCreateServer)

View File

@@ -3,6 +3,7 @@ package router
import (
"bytes"
"github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/installer"
"github.com/pterodactyl/wings/server"
"github.com/pterodactyl/wings/system"
@@ -63,3 +64,25 @@ func postCreateServer(c *gin.Context) {
c.Status(http.StatusAccepted)
}
// Updates the running configuration for this daemon instance.
func postUpdateConfiguration(c *gin.Context) {
// A backup of the configuration for error purposes.
ccopy := *config.Get()
// A copy of the configuration we're using to bind the data recevied into.
cfg := *config.Get()
c.BindJSON(&cfg)
config.Set(&cfg)
if err := config.Get().WriteToDisk(); err != nil {
// If there was an error writing to the disk, revert back to the configuration we had
// before this code was run.
config.Set(&ccopy)
TrackedError(err).AbortWithServerError(c)
return
}
c.Status(http.StatusNoContent)
}