Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AWS STS Tokens in S3 Backend #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion src/duplicacy_s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions src/duplicacy_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,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\-]+@)?([^/]+)(/(.+))?`)

Expand Down Expand Up @@ -492,7 +492,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
Expand Down