1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-06 00:03:38 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Philipp Bandow
10845e93f6 Merge e0e4cbf7e2 into 065ae50868 2024-12-19 15:03:46 +01:00
Gilbert Chen
065ae50868 Improve parsing logic for swift storage URLs that contain multiple '@'
Parse the storage URL first, then use a regex to ensure the server name is
correctly identified starting after the final '@'.
2024-12-19 08:54:22 -05:00
Philipp Bandow
e0e4cbf7e2 Add support for AWS STS Tokens in S3 Backend 2021-05-27 23:03:52 +02:00
3 changed files with 25 additions and 10 deletions

View File

@@ -33,8 +33,13 @@ type S3Storage struct {
func CreateS3Storage(regionName string, endpoint string, bucketName string, storageDir string,
accessKey string, secretKey string, threads int,
isSSLSupported bool, isMinioCompatible bool) (storage *S3Storage, err error) {
return CreateS3StorageWithToken(regionName, endpoint, bucketName, storageDir, accessKey, secretKey, "", threads, isSSLSupported, isMinioCompatible)
}
token := ""
// CreatesS3StorageWithToken create an amazon s3 storage object using an optional security token.
func CreateS3StorageWithToken(regionName string, endpoint string, bucketName string, storageDir string,
accessKey string, secretKey string, token string, threads int,
isSSLSupported bool, isMinioCompatible bool) (storage *S3Storage, err error) {
auth := credentials.NewStaticCredentials(accessKey, secretKey, token)

View File

@@ -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-token" {
// urlRegex := regexp.MustCompile(`^(\w+)://([\w\-]+@)?([^/]+)(/(.+))?`)
@@ -493,7 +493,12 @@ 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)
if matched[1] == "s3-token" {
token := GetPassword(preference, "s3_token", "Enter S3 Token (Optional):", true, resetPassword)
storage, err = CreateS3StorageWithToken(region, endpoint, bucket, storageDir, accessKey, secretKey, token, threads, isSSLSupported, isMinioCompatible)
} else {
storage, err = CreateS3Storage(region, endpoint, bucket, storageDir, accessKey, secretKey, threads, isSSLSupported, isMinioCompatible)
}
if err != nil {
LOG_ERROR("STORAGE_CREATE", "Failed to load the S3 storage at %s: %v", storageURL, err)
return nil

View File

@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"time"
"regexp"
"github.com/ncw/swift/v2"
)
@@ -42,13 +43,6 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw
}
}
// Take out the user name if there is one
if strings.Contains(storageURL, "@") {
userAndURL := strings.Split(storageURL, "@")
arguments["user"] = userAndURL[0]
storageURL = userAndURL[1]
}
// The version is used to split authURL and container/path
versions := []string{"/v1/", "/v1.0/", "/v2/", "/v2.0/", "/v3/", "/v3.0/", "/v4/", "/v4.0/"}
storageDir := ""
@@ -60,6 +54,17 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw
}
}
// Take out the user name if there is one
if strings.Contains(storageURL, "@") {
// Use regex to split the username and the rest of the URL
lineRegex := regexp.MustCompile(`^(.+)@([^@]+)$`)
match := lineRegex.FindStringSubmatch(storageURL)
if match != nil {
arguments["user"] = match[1]
storageURL = match[2]
}
}
// If no container/path is specified, find them from the arguments
if storageDir == "" {
storageDir = arguments["storage_dir"]