Skip to content
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
23 changes: 20 additions & 3 deletions src/duplicacy_s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,31 @@ type S3Storage struct {
numberOfThreads int
}

// CreateS3Storage creates a amazon s3 storage object.
// CreateS3Storage creates an Amazon S3 storage object.
func CreateS3Storage(regionName string, endpoint string, bucketName string, storageDir string,
accessKey string, secretKey string, threads int,
isSSLSupported bool, isMinioCompatible bool) (storage *S3Storage, err error) {
isSSLSupported bool, isMinioCompatible bool, options ...interface{}) (storage *S3Storage, err error) {

// Default values for optional parameters
token := ""
noSignRequest := false

// Process optional parameters
for _, option := range options {
switch v := option.(type) {
case string:
token = v
case bool:
noSignRequest = v
}
}

auth := credentials.NewStaticCredentials(accessKey, secretKey, token)
var auth *credentials.Credentials
if noSignRequest {
auth = credentials.AnonymousCredentials
} else {
auth = credentials.NewStaticCredentials(accessKey, secretKey, token)
}

if regionName == "" && endpoint == "" {
defaultRegionConfig := &aws.Config{
Expand Down
26 changes: 23 additions & 3 deletions src/duplicacy_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
SavePassword(preference, "ssh_password", password)
}
return sftpStorage
} else if matched[1] == "s3" || matched[1] == "s3c" || matched[1] == "minio" || matched[1] == "minios" {
} else if matched[1] == "s3" || matched[1] == "s3c" || matched[1] == "minio" || matched[1] == "minios" || matched[1] == "s3-anon" {

// urlRegex := regexp.MustCompile(`^(\w+)://([\w\-]+@)?([^/]+)(/(.+))?`)

Expand All @@ -479,10 +479,29 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
bucket = bucket[:firstSlash]
}

var err error

if matched[1] == "s3-anon" {
isMinioCompatible := false
isSSLSupported := true
accessKey := ""
secretKey := ""
token := ""
noSignRequest := true
storage, err = CreateS3Storage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads, isSSLSupported, isMinioCompatible, token, noSignRequest)
if err != nil {
LOG_ERROR("STORAGE_CREATE", "Failed to load the S3 storage at %s: %v", storageURL, err)
return nil
}

return storage
}

accessKey := GetPassword(preference, "s3_id", "Enter S3 Access Key ID:", true, resetPassword)
secretKey := GetPassword(preference, "s3_secret", "Enter S3 Secret Access Key:", true, resetPassword)
token := GetPassword(preference, "s3_token", "Enter S3 Token (optional):", true, resetPassword)

var err error
noSignRequest := false

if matched[1] == "s3c" {
storage, err = CreateS3CStorage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads)
Expand All @@ -493,14 +512,15 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
} else {
isMinioCompatible := (matched[1] == "minio" || matched[1] == "minios")
isSSLSupported := (matched[1] == "s3" || matched[1] == "minios")
storage, err = CreateS3Storage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads, isSSLSupported, isMinioCompatible)
storage, err = CreateS3Storage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads, isSSLSupported, isMinioCompatible, token, noSignRequest)
if err != nil {
LOG_ERROR("STORAGE_CREATE", "Failed to load the S3 storage at %s: %v", storageURL, err)
return nil
}
}
SavePassword(preference, "s3_id", accessKey)
SavePassword(preference, "s3_secret", secretKey)
SavePassword(preference, "s3_token", token)

return storage

Expand Down