From bfff094216facec90308818e7e36ff4e9e0f0771 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 1 Feb 2021 21:32:34 -0800 Subject: [PATCH] Get wings booting properly --- environment/docker/power.go | 1 - remote/servers.go | 20 +++++++++----------- router/router_download.go | 3 ++- server/install.go | 1 - server/listeners.go | 1 - sftp/server.go | 3 +-- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/environment/docker/power.go b/environment/docker/power.go index 9cc8b9e..031e58e 100644 --- a/environment/docker/power.go +++ b/environment/docker/power.go @@ -7,7 +7,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" - "github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/remote" diff --git a/remote/servers.go b/remote/servers.go index e490936..2a3f57c 100644 --- a/remote/servers.go +++ b/remote/servers.go @@ -8,7 +8,6 @@ import ( "emperror.dev/errors" "github.com/apex/log" - "github.com/pterodactyl/wings/api" "golang.org/x/sync/errgroup" ) @@ -147,27 +146,26 @@ func (c *client) ValidateSftpCredentials(ctx context.Context, request SftpAuthRe // getServersPaged returns a subset of servers from the Panel API using the // pagination query parameters. -func (c *client) getServersPaged(ctx context.Context, page, limit int) ([]RawServerData, api.Pagination, error) { +func (c *client) getServersPaged(ctx context.Context, page, limit int) ([]RawServerData, Pagination, error) { + var r struct { + Data []RawServerData `json:"data"` + Meta Pagination `json:"meta"` + } + res, err := c.get(ctx, "/servers", q{ "page": strconv.Itoa(page), "per_page": strconv.Itoa(limit), }) if err != nil { - return nil, api.Pagination{}, err + return nil, r.Meta, err } defer res.Body.Close() if res.HasError() { - return nil, api.Pagination{}, res.Error() - } - - var r struct { - Data []RawServerData `json:"data"` - Meta api.Pagination `json:"meta"` + return nil, r.Meta, res.Error() } if err := res.BindJSON(&r); err != nil { - return nil, api.Pagination{}, err + return nil, r.Meta, err } - return r.Data, r.Meta, nil } \ No newline at end of file diff --git a/router/router_download.go b/router/router_download.go index d72cc48..806cfaf 100644 --- a/router/router_download.go +++ b/router/router_download.go @@ -15,6 +15,7 @@ import ( // Handle a download request for a server backup. func getDownloadBackup(c *gin.Context) { + client := middleware.ExtractApiClient(c) manager := middleware.ExtractManager(c) token := tokens.BackupPayload{} @@ -31,7 +32,7 @@ func getDownloadBackup(c *gin.Context) { return } - b, st, err := backup.LocateLocal(token.BackupUuid) + b, st, err := backup.LocateLocal(client, token.BackupUuid) if err != nil { if errors.Is(err, os.ErrNotExist) { c.AbortWithStatusJSON(http.StatusNotFound, gin.H{ diff --git a/server/install.go b/server/install.go index dd00d3c..766200d 100644 --- a/server/install.go +++ b/server/install.go @@ -17,7 +17,6 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/client" - "github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/remote" diff --git a/server/listeners.go b/server/listeners.go index abeb2c1..4787c9e 100644 --- a/server/listeners.go +++ b/server/listeners.go @@ -7,7 +7,6 @@ import ( "sync" "github.com/apex/log" - "github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/events" diff --git a/sftp/server.go b/sftp/server.go index 6e8b755..ba69a7b 100644 --- a/sftp/server.go +++ b/sftp/server.go @@ -18,7 +18,6 @@ import ( "emperror.dev/errors" "github.com/apex/log" "github.com/pkg/sftp" - "github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/remote" "github.com/pterodactyl/wings/server" @@ -190,7 +189,7 @@ func (c *SFTPServer) passwordCallback(conn ssh.ConnMetadata, pass []byte) (*ssh. resp, err := c.manager.Client().ValidateSftpCredentials(context.Background(), request) if err != nil { - if api.IsInvalidCredentialsError(err) { + if _, ok := err.(*remote.SftpInvalidCredentialsError); ok { logger.Warn("failed to validate user credentials (invalid username or password)") } else { logger.WithField("error", err).Error("encountered an error while trying to validate user credentials")