mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
c08ac536ed
* disable md5, sha256 checking to avoid reading one chunk twice * single threaded upload to avoid chunk swapping (to be enhanced later)
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package s3_backend
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
"github.com/aws/aws-sdk-go/service/s3"
|
|
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
|
)
|
|
|
|
var (
|
|
s3Sessions = make(map[string]s3iface.S3API)
|
|
sessionsLock sync.RWMutex
|
|
)
|
|
|
|
func getSession(region string) (s3iface.S3API, bool) {
|
|
sessionsLock.RLock()
|
|
defer sessionsLock.RUnlock()
|
|
|
|
sess, found := s3Sessions[region]
|
|
return sess, found
|
|
}
|
|
|
|
func createSession(awsAccessKeyId, awsSecretAccessKey, region, endpoint string) (s3iface.S3API, error) {
|
|
|
|
sessionsLock.Lock()
|
|
defer sessionsLock.Unlock()
|
|
|
|
if t, found := s3Sessions[region]; found {
|
|
return t, nil
|
|
}
|
|
|
|
config := &aws.Config{
|
|
Region: aws.String(region),
|
|
Endpoint: aws.String(endpoint),
|
|
S3ForcePathStyle: aws.Bool(true),
|
|
S3DisableContentMD5Validation: aws.Bool(true),
|
|
}
|
|
if awsAccessKeyId != "" && awsSecretAccessKey != "" {
|
|
config.Credentials = credentials.NewStaticCredentials(awsAccessKeyId, awsSecretAccessKey, "")
|
|
}
|
|
|
|
sess, err := session.NewSession(config)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("create aws session in region %s: %v", region, err)
|
|
}
|
|
|
|
t := s3.New(sess)
|
|
|
|
s3Sessions[region] = t
|
|
|
|
return t, nil
|
|
|
|
}
|
|
|
|
func deleteFromS3(sess s3iface.S3API, sourceBucket string, sourceKey string) (err error) {
|
|
_, err = sess.DeleteObject(&s3.DeleteObjectInput{
|
|
Bucket: aws.String(sourceBucket),
|
|
Key: aws.String(sourceKey),
|
|
})
|
|
return err
|
|
}
|