Remove all of the remaining API logic and port it all to the remote.Client type

This commit is contained in:
Dane Everitt
2021-02-01 21:28:46 -08:00
parent 62cbe5e135
commit 98c68142cd
26 changed files with 290 additions and 649 deletions

View File

@@ -1,13 +1,14 @@
package installer
import (
"context"
"encoding/json"
"emperror.dev/errors"
"github.com/asaskevich/govalidator"
"github.com/buger/jsonparser"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/environment"
"github.com/pterodactyl/wings/remote"
"github.com/pterodactyl/wings/server"
)
@@ -15,10 +16,10 @@ type Installer struct {
server *server.Server
}
// Validates the received data to ensure that all of the required fields
// New validates the received data to ensure that all of the required fields
// have been passed along in the request. This should be manually run before
// calling Execute().
func New(data []byte) (*Installer, error) {
func New(ctx context.Context, manager *server.Manager, data []byte) (*Installer, error) {
if !govalidator.IsUUIDv4(getString(data, "uuid")) {
return nil, NewValidationError("uuid provided was not in a valid format")
}
@@ -64,30 +65,27 @@ func New(data []byte) (*Installer, error) {
cfg.Container.Image = getString(data, "container", "image")
c, err := api.New().GetServerConfiguration(cfg.Uuid)
c, err := manager.Client().GetServerConfiguration(ctx, cfg.Uuid)
if err != nil {
if !api.IsRequestError(err) {
if !remote.IsRequestError(err) {
return nil, err
}
return nil, errors.New(err.Error())
}
// Create a new server instance using the configuration we wrote to the disk
// so that everything gets instantiated correctly on the struct.
s, err := server.FromConfiguration(c)
s, err := manager.InitServer(c)
return &Installer{
server: s,
}, err
return &Installer{server: s}, err
}
// Returns the UUID associated with this installer instance.
// Uuid returns the UUID associated with this installer instance.
func (i *Installer) Uuid() string {
return i.server.Id()
}
// Return the server instance.
// Server returns the server instance.
func (i *Installer) Server() *server.Server {
return i.server
}