1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-20 18:23:29 +00:00

Make the S3 backend compatible with minio

This commit is contained in:
Gilbert Chen
2017-07-11 13:45:06 -04:00
parent 0aa122609a
commit f8764a5a79
3 changed files with 12 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ type S3Storage struct {
// CreateS3Storage creates a amazon s3 storage object. // CreateS3Storage creates a amazon s3 storage object.
func CreateS3Storage(regionName string, endpoint string, bucketName string, storageDir string, 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 := "" token := ""
@@ -53,7 +53,9 @@ func CreateS3Storage(regionName string, endpoint string, bucketName string, stor
Region: aws.String(regionName), Region: aws.String(regionName),
Credentials: auth, Credentials: auth,
Endpoint: aws.String(endpoint), Endpoint: aws.String(endpoint),
} S3ForcePathStyle: aws.Bool(isMinioCompatible),
DisableSSL: aws.Bool(isMinioCompatible),
}
if len(storageDir) > 0 && storageDir[len(storageDir) - 1] != '/' { if len(storageDir) > 0 && storageDir[len(storageDir) - 1] != '/' {
storageDir += "/" storageDir += "/"

View File

@@ -293,7 +293,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
SavePassword(preference, "ssh_password", password) SavePassword(preference, "ssh_password", password)
} }
return sftpStorage return sftpStorage
} else if matched[1] == "s3" { } else if matched[1] == "s3" || matched[1] == "minio" {
// urlRegex := regexp.MustCompile(`^(\w+)://([\w\-]+@)?([^/]+)(/(.+))?`) // 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) accessKey := GetPassword(preference, "s3_id", "Enter S3 Access Key ID:", true, resetPassword)
secretKey := GetPassword(preference, "s3_secret", "Enter S3 Secret Access Key:", 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 { if err != nil {
LOG_ERROR("STORAGE_CREATE", "Failed to load the S3 storage at %s: %v", storageURL, err) LOG_ERROR("STORAGE_CREATE", "Failed to load the S3 storage at %s: %v", storageURL, err)
return nil return nil

View File

@@ -65,13 +65,15 @@ func loadStorage(localStoragePath string, threads int) (Storage, error) {
port, _ := strconv.Atoi(storage["port"]) port, _ := strconv.Atoi(storage["port"])
return CreateSFTPStorageWithPassword(storage["server"], port, storage["username"], storage["directory"], storage["password"], threads) return CreateSFTPStorageWithPassword(storage["server"], port, storage["username"], storage["directory"], storage["password"], threads)
} else if testStorageName == "s3" { } 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" { } else if testStorageName == "dropbox" {
return CreateDropboxStorage(storage["token"], storage["directory"], threads) return CreateDropboxStorage(storage["token"], storage["directory"], threads)
} else if testStorageName == "b2" { } else if testStorageName == "b2" {
return CreateB2Storage(storage["account"], storage["key"], storage["bucket"], threads) return CreateB2Storage(storage["account"], storage["key"], storage["bucket"], threads)
} else if testStorageName == "gcs-s3" { } 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" { } else if testStorageName == "gcs" {
return CreateGCSStorage(storage["token_file"], storage["bucket"], storage["directory"], threads) return CreateGCSStorage(storage["token_file"], storage["bucket"], storage["directory"], threads)
} else if testStorageName == "gcs-sa" { } else if testStorageName == "gcs-sa" {