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

@@ -9,8 +9,8 @@ import (
"sync"
"github.com/apex/log"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/remote"
)
type AdapterType string
@@ -31,8 +31,8 @@ type ArchiveDetails struct {
}
// ToRequest returns a request object.
func (ad *ArchiveDetails) ToRequest(successful bool) api.BackupRequest {
return api.BackupRequest{
func (ad *ArchiveDetails) ToRequest(successful bool) remote.BackupRequest {
return remote.BackupRequest{
Checksum: ad.Checksum,
ChecksumType: ad.ChecksumType,
Size: ad.Size,
@@ -49,12 +49,15 @@ type Backup struct {
// compatible with a standard .gitignore structure.
Ignore string `json:"ignore"`
client remote.Client
adapter AdapterType
logContext map[string]interface{}
}
// noinspection GoNameStartsWithPackageName
type BackupInterface interface {
// SetClient sets the API request client on the backup interface.
SetClient(c remote.Client)
// Identifier returns the UUID of this backup as tracked by the panel
// instance.
Identifier() string
@@ -84,6 +87,10 @@ type BackupInterface interface {
Restore(reader io.Reader, callback RestoreCallback) error
}
func (b *Backup) SetClient(c remote.Client) {
b.client = c
}
func (b *Backup) Identifier() string {
return b.Uuid
}

View File

@@ -6,6 +6,7 @@ import (
"os"
"github.com/mholt/archiver/v3"
"github.com/pterodactyl/wings/remote"
"github.com/pterodactyl/wings/system"
)
@@ -15,9 +16,10 @@ type LocalBackup struct {
var _ BackupInterface = (*LocalBackup)(nil)
func NewLocal(uuid string, ignore string) *LocalBackup {
func NewLocal(client remote.Client, uuid string, ignore string) *LocalBackup {
return &LocalBackup{
Backup{
client: client,
Uuid: uuid,
Ignore: ignore,
adapter: LocalBackupAdapter,
@@ -27,14 +29,8 @@ func NewLocal(uuid string, ignore string) *LocalBackup {
// LocateLocal finds the backup for a server and returns the local path. This
// will obviously only work if the backup was created as a local backup.
func LocateLocal(uuid string) (*LocalBackup, os.FileInfo, error) {
b := &LocalBackup{
Backup{
Uuid: uuid,
Ignore: "",
},
}
func LocateLocal(client remote.Client, uuid string) (*LocalBackup, os.FileInfo, error) {
b := NewLocal(client, uuid, "")
st, err := os.Stat(b.Path())
if err != nil {
return nil, nil, err

View File

@@ -3,6 +3,7 @@ package backup
import (
"archive/tar"
"compress/gzip"
"context"
"fmt"
"io"
"net/http"
@@ -10,8 +11,8 @@ import (
"strconv"
"github.com/juju/ratelimit"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/remote"
)
type S3Backup struct {
@@ -20,9 +21,10 @@ type S3Backup struct {
var _ BackupInterface = (*S3Backup)(nil)
func NewS3(uuid string, ignore string) *S3Backup {
func NewS3(client remote.Client, uuid string, ignore string) *S3Backup {
return &S3Backup{
Backup{
client: client,
Uuid: uuid,
Ignore: ignore,
adapter: S3BackupAdapter,
@@ -91,7 +93,7 @@ func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) error {
s.log().WithField("size", size).Debug("got size of backup")
s.log().Debug("attempting to get S3 upload urls from Panel...")
urls, err := api.New().GetBackupRemoteUploadURLs(s.Backup.Uuid, size)
urls, err := s.client.GetBackupRemoteUploadURLs(context.Background(), s.Backup.Uuid, size)
if err != nil {
return err
}