From f8764a5a79067f9e57a3c577cbe8c3a7a319f4ab Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Tue, 11 Jul 2017 13:45:06 -0400 Subject: [PATCH] Make the S3 backend compatible with minio --- src/duplicacy_s3storage.go | 6 ++++-- src/duplicacy_storage.go | 6 ++++-- src/duplicacy_storage_test.go | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/duplicacy_s3storage.go b/src/duplicacy_s3storage.go index b4bb76e..c9d0525 100644 --- a/src/duplicacy_s3storage.go +++ b/src/duplicacy_s3storage.go @@ -23,7 +23,7 @@ type S3Storage struct { // CreateS3Storage creates a amazon s3 storage object. func CreateS3Storage(regionName string, endpoint string, bucketName string, storageDir string, - accessKey string, secretKey string, threads int) (storage *S3Storage, err error) { + accessKey string, secretKey string, threads int, isMinioCompatible bool) (storage *S3Storage, err error) { token := "" @@ -53,7 +53,9 @@ func CreateS3Storage(regionName string, endpoint string, bucketName string, stor Region: aws.String(regionName), Credentials: auth, Endpoint: aws.String(endpoint), - } + S3ForcePathStyle: aws.Bool(isMinioCompatible), + DisableSSL: aws.Bool(isMinioCompatible), + } if len(storageDir) > 0 && storageDir[len(storageDir) - 1] != '/' { storageDir += "/" diff --git a/src/duplicacy_storage.go b/src/duplicacy_storage.go index 0d15c21..4f145e5 100644 --- a/src/duplicacy_storage.go +++ b/src/duplicacy_storage.go @@ -293,7 +293,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor SavePassword(preference, "ssh_password", password) } return sftpStorage - } else if matched[1] == "s3" { + } else if matched[1] == "s3" || matched[1] == "minio" { // urlRegex := regexp.MustCompile(`^(\w+)://([\w\-]+@)?([^/]+)(/(.+))?`) @@ -319,7 +319,9 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor accessKey := GetPassword(preference, "s3_id", "Enter S3 Access Key ID:", true, resetPassword) secretKey := GetPassword(preference, "s3_secret", "Enter S3 Secret Access Key:", true, resetPassword) - s3Storage, err := CreateS3Storage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads) + isMinioCompatible := matched[1] == "minio" + + s3Storage, err := CreateS3Storage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads, isMinioCompatible) if err != nil { LOG_ERROR("STORAGE_CREATE", "Failed to load the S3 storage at %s: %v", storageURL, err) return nil diff --git a/src/duplicacy_storage_test.go b/src/duplicacy_storage_test.go index 194b6bd..2b06c3b 100644 --- a/src/duplicacy_storage_test.go +++ b/src/duplicacy_storage_test.go @@ -65,13 +65,15 @@ func loadStorage(localStoragePath string, threads int) (Storage, error) { port, _ := strconv.Atoi(storage["port"]) return CreateSFTPStorageWithPassword(storage["server"], port, storage["username"], storage["directory"], storage["password"], threads) } else if testStorageName == "s3" { - return CreateS3Storage(storage["region"], storage["endpoint"], storage["bucket"], storage["directory"], storage["access_key"], storage["secret_key"], threads) + return CreateS3Storage(storage["region"], storage["endpoint"], storage["bucket"], storage["directory"], storage["access_key"], storage["secret_key"], threads, false) + } else if testStorageName == "minio" { + return CreateS3Storage(storage["region"], storage["endpoint"], storage["bucket"], storage["directory"], storage["access_key"], storage["secret_key"], threads, true) } else if testStorageName == "dropbox" { return CreateDropboxStorage(storage["token"], storage["directory"], threads) } else if testStorageName == "b2" { return CreateB2Storage(storage["account"], storage["key"], storage["bucket"], threads) } else if testStorageName == "gcs-s3" { - return CreateS3Storage(storage["region"], storage["endpoint"], storage["bucket"], storage["directory"], storage["access_key"], storage["secret_key"], threads) + return CreateS3Storage(storage["region"], storage["endpoint"], storage["bucket"], storage["directory"], storage["access_key"], storage["secret_key"], threads, false) } else if testStorageName == "gcs" { return CreateGCSStorage(storage["token_file"], storage["bucket"], storage["directory"], threads) } else if testStorageName == "gcs-sa" {