diff --git a/azure/folder.go b/azure/folder.go index 30b6cce..47ea7af 100644 --- a/azure/folder.go +++ b/azure/folder.go @@ -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 diff --git a/fs/folder.go b/fs/folder.go index 07e2715..9751b00 100644 --- a/fs/folder.go +++ b/fs/folder.go @@ -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) { diff --git a/gcs/folder.go b/gcs/folder.go index 799733a..e726a41 100644 --- a/gcs/folder.go +++ b/gcs/folder.go @@ -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) diff --git a/memory/folder.go b/memory/folder.go index dfec73c..02b15fb 100644 --- a/memory/folder.go +++ b/memory/folder.go @@ -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 @@ -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") +} \ No newline at end of file diff --git a/s3/folder.go b/s3/folder.go index 00a3f4d..dc10b20 100644 --- a/s3/folder.go +++ b/s3/folder.go @@ -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{ diff --git a/s3/session.go b/s3/session.go index df9d551..4c68e9a 100644 --- a/s3/session.go +++ b/s3/session.go @@ -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" @@ -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 { diff --git a/sh/folder.go b/sh/folder.go index 73d7df4..a8b3536 100644 --- a/sh/folder.go +++ b/sh/folder.go @@ -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") +} \ No newline at end of file diff --git a/storage/folder.go b/storage/folder.go index aaee6d0..c318279 100644 --- a/storage/folder.go +++ b/storage/folder.go @@ -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 { diff --git a/swift/folder.go b/swift/folder.go index af61aaa..cfc7097 100644 --- a/swift/folder.go +++ b/swift/folder.go @@ -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)