Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CopyObject functionality #52

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions azure/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
return nil
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
return NewFolderError(nil, "Not implemented")
}

func (folder *Folder) DeleteObjects(objectRelativePaths []string) error {
for _, objectRelativePath := range objectRelativePaths {
//Delete blob using blobURL obtained from full path to blob
Expand Down
4 changes: 4 additions & 0 deletions fs/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
return nil
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
return NewError(nil, "Not implemented")
}

func OpenFileWithDir(filePath string) (*os.File, error) {
file, err := os.Create(filePath)
if os.IsNotExist(err) {
Expand Down
4 changes: 4 additions & 0 deletions gcs/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
return nil
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
return NewError(nil, "Not implemented")
}

func (folder *Folder) joinPath(one string, another string) string {
if folder.normalizePrefix {
return storage.JoinPath(one, another)
Expand Down
8 changes: 8 additions & 0 deletions memory/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func NewFolder(path string, storage *Storage) *Folder {
return &Folder{path, storage}
}

func NewError(err error, format string, args ...interface{}) storage.Error {
return storage.NewError(err, "Memory", format, args...)
}

func (folder *Folder) Exists(objectRelativePath string) (bool, error) {
_, exists := folder.Storage.Load(folder.path + objectRelativePath)
return exists, nil
Expand Down Expand Up @@ -81,3 +85,7 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
folder.Storage.Store(objectPath, *bytes.NewBuffer(data))
return nil
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
return NewError(nil, "Not implemented")
}
18 changes: 18 additions & 0 deletions s3/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
return folder.uploader.upload(*folder.Bucket, folder.Path+name, content)
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
if exists, err := folder.Exists(objectRelativePath); !exists {
if err == nil {
return NewFolderError(nil, "object do not exists")
} else {
return err
}
}
source := *folder.Bucket + "/" + baseBackupPath + objectRelativePath
dst := baseBackupPath + dstObject
input := &s3.CopyObjectInput{CopySource: &source, Bucket: folder.Bucket, Key: &dst}
_, err := folder.S3API.CopyObject(input)
if err != nil {
return err
}
return nil
}

func (folder *Folder) ReadObject(objectRelativePath string) (io.ReadCloser, error) {
objectPath := folder.Path + objectRelativePath
input := &s3.GetObjectInput{
Expand Down
16 changes: 16 additions & 0 deletions s3/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -89,6 +90,21 @@ func getDefaultConfig(settings map[string]string) *aws.Config {
config := defaults.Get().Config.WithRegion(settings[RegionSetting])
config = request.WithRetryer(config, client.DefaultRetryer{NumMaxRetries: MaxRetries})

provider := &credentials.StaticProvider{Value: credentials.Value{
AccessKeyID: getFirstSettingOf(settings, []string{AccessKeyIdSetting, AccessKeySetting}),
SecretAccessKey: getFirstSettingOf(settings, []string{SecretAccessKeySetting, SecretKeySetting}),
SessionToken: settings[SessionTokenSetting],
}}
providers := make([]credentials.Provider, 0)
providers = append(providers, provider)
providers = append(providers, defaults.CredProviders(config, defaults.Handlers())...)
newCredentials := credentials.NewCredentials(&credentials.ChainProvider{
VerboseErrors: aws.BoolValue(config.CredentialsChainVerboseErrors),
Providers: providers,
})

config = config.WithCredentials(newCredentials)

if logLevel, ok := settings[LogLevel]; ok {
config = config.WithLogLevel(func(s string) aws.LogLevelType {
switch s {
Expand Down
4 changes: 4 additions & 0 deletions sh/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,7 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
}
return nil
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
return NewFolderError(nil, "Not implemented")
}
2 changes: 2 additions & 0 deletions storage/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Folder interface {
ReadObject(objectRelativePath string) (io.ReadCloser, error)

PutObject(name string, content io.Reader) error

CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error
}

func DeleteObjectsWhere(folder Folder, confirm bool, filter func(object1 Object) bool) error {
Expand Down
4 changes: 4 additions & 0 deletions swift/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (folder *Folder) PutObject(name string, content io.Reader) error {
return nil
}

func (folder *Folder) CopyObject(baseBackupPath string, objectRelativePath string, dstObject string) error {
return NewError(nil, "Not implemented")
}

func (folder *Folder) DeleteObjects(objectRelativePaths []string) error {
for _, objectRelativePath := range objectRelativePaths {
path := storage.JoinPath(folder.path, objectRelativePath)
Expand Down