More abstract support for backups & misc code cleanup in that area

This commit is contained in:
Dane Everitt
2020-04-26 16:43:18 -07:00
parent 1e2da95d26
commit 91d12ab9a7
5 changed files with 106 additions and 40 deletions

View File

@@ -7,7 +7,7 @@ import (
)
const (
LocalBackupAdapter = "local"
LocalBackupAdapter = "wings"
S3BackupAdapter = "s3"
)
@@ -30,6 +30,23 @@ func (r *Request) NewLocalBackup() (*LocalBackup, error) {
}, nil
}
// Generates a new S3 backup struct.
func (r *Request) NewS3Backup() (*S3Backup, error) {
if r.Adapter != S3BackupAdapter {
return nil, errors.New(fmt.Sprintf("cannot create s3 backup using [%s] adapter", r.Adapter))
}
if len(r.PresignedUrl) == 0 {
return nil, errors.New("a valid presigned S3 upload URL must be provided to use the [s3] adapter")
}
return &S3Backup{
Uuid: r.Uuid,
IgnoredFiles: r.IgnoredFiles,
PresignedUrl: r.PresignedUrl,
}, nil
}
type Backup interface {
// Returns the UUID of this backup as tracked by the panel instance.
Identifier() string
@@ -38,6 +55,9 @@ type Backup interface {
// implementation is.
Backup(*IncludedFiles, string) error
// Returns the ignored files for this backup instance.
Ignored() []string
// Returns a SHA256 checksum for the generated backup.
Checksum() ([]byte, error)
@@ -51,6 +71,9 @@ type Backup interface {
// Returns details about the archive.
Details() *ArchiveDetails
// Removes a backup file.
Remove() error
}
type ArchiveDetails struct {

View File

@@ -138,6 +138,10 @@ func (b *LocalBackup) Details() *ArchiveDetails {
}
}
func (b *LocalBackup) Ignored() []string {
return b.IgnoredFiles
}
// Ensures that the local backup destination for files exists.
func (b *LocalBackup) ensureLocalBackupLocation() error {
d := config.Get().System.BackupDirectory

View File

@@ -8,6 +8,12 @@ type S3Backup struct {
// An array of files to ignore when generating this backup. This should be
// compatible with a standard .gitignore structure.
IgnoredFiles []string
// The pre-signed upload endpoint for the generated backup. This must be
// provided otherwise this request will fail. This allows us to keep all
// of the keys off the daemon instances and the panel can handle generating
// the credentials for us.
PresignedUrl string
}
var _ Backup = (*S3Backup)(nil)
@@ -35,3 +41,11 @@ func (s *S3Backup) Path() string {
func (s *S3Backup) Details() *ArchiveDetails {
return &ArchiveDetails{}
}
func (s *S3Backup) Ignored() []string {
return s.IgnoredFiles
}
func (s *S3Backup) Remove() error {
return nil
}