Remove all of the remaining API logic and port it all to the remote.Client type
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user