From 7321c6aa45f7019d41fdc411bc38549ecca99fd6 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 29 Aug 2021 13:52:19 -0700 Subject: [PATCH] Remove unused and complicated installer logic --- CHANGELOG.md | 1 + installer/installer.go | 49 +++--------------------------------------- 2 files changed, 4 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f9fa1..c919557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Simplifed the logic powering server updates to only pull information from the Panel rather than trying to accept updated values. All parts of Wings needing the most up-to-date server details should call `Server#Sync()` to fetch the latest stored build information. ### Removed +* Removes complicated (and unused) logic during the server installation process that was a hold-over from legacy Wings architectures. * Removes the `PATCH /api/servers/:server` endpoint — if you were previously using this API call it should be replaced with `POST /api/servers/:server/sync`. ## v1.4.7 diff --git a/installer/installer.go b/installer/installer.go index a4e1e7d..c34bdef 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -2,13 +2,11 @@ package installer import ( "context" - "encoding/json" "emperror.dev/errors" "github.com/asaskevich/govalidator" "github.com/buger/jsonparser" - "github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/remote" "github.com/pterodactyl/wings/server" ) @@ -21,53 +19,12 @@ type Installer struct { // have been passed along in the request. This should be manually run before // calling Execute(). func New(ctx context.Context, manager *server.Manager, data []byte) (*Installer, error) { - if !govalidator.IsUUIDv4(getString(data, "uuid")) { + uuid := getString(data, "uuid") + if !govalidator.IsUUIDv4(uuid) { return nil, NewValidationError("uuid provided was not in a valid format") } - cfg := &server.Configuration{ - Uuid: getString(data, "uuid"), - Suspended: false, - Invocation: getString(data, "invocation"), - SkipEggScripts: getBoolean(data, "skip_egg_scripts"), - StartOnCompletion: getBoolean(data, "start_on_completion"), - Build: environment.Limits{ - MemoryLimit: getInt(data, "build", "memory"), - Swap: getInt(data, "build", "swap"), - IoWeight: uint16(getInt(data, "build", "io")), - CpuLimit: getInt(data, "build", "cpu"), - DiskSpace: getInt(data, "build", "disk"), - Threads: getString(data, "build", "threads"), - }, - CrashDetectionEnabled: true, - } - - cfg.Allocations.DefaultMapping.Ip = getString(data, "allocations", "default", "ip") - cfg.Allocations.DefaultMapping.Port = int(getInt(data, "allocations", "default", "port")) - - // Unmarshal the environment variables from the request into the server struct. - if b, _, _, err := jsonparser.Get(data, "environment"); err != nil { - return nil, errors.WithStackIf(err) - } else { - cfg.EnvVars = make(environment.Variables) - if err := json.Unmarshal(b, &cfg.EnvVars); err != nil { - return nil, errors.WrapIf(err, "installer: could not unmarshal environment variables for server") - } - } - - // Unmarshal the allocation mappings from the request into the server struct. - if b, _, _, err := jsonparser.Get(data, "allocations", "mappings"); err != nil { - return nil, errors.WithStackIf(err) - } else { - cfg.Allocations.Mappings = make(map[string][]int) - if err := json.Unmarshal(b, &cfg.Allocations.Mappings); err != nil { - return nil, errors.Wrap(err, "installer: could not unmarshal allocation mappings") - } - } - - cfg.Container.Image = getString(data, "container", "image") - - c, err := manager.Client().GetServerConfiguration(ctx, cfg.Uuid) + c, err := manager.Client().GetServerConfiguration(ctx, uuid) if err != nil { if !remote.IsRequestError(err) { return nil, errors.WithStackIf(err)