mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-06-28 15:41:13 +08:00
cloud tier: support for Alibaba Cloud OSS (#6466)
This commit is contained in:
parent
ca4dca14d8
commit
5452405a81
@ -2,12 +2,13 @@ package s3_backend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -39,6 +40,7 @@ type S3BackendStorage struct {
|
|||||||
bucket string
|
bucket string
|
||||||
endpoint string
|
endpoint string
|
||||||
storageClass string
|
storageClass string
|
||||||
|
forcePathStyle bool
|
||||||
conn s3iface.S3API
|
conn s3iface.S3API
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,11 +53,12 @@ func newS3BackendStorage(configuration backend.StringProperties, configPrefix st
|
|||||||
s.bucket = configuration.GetString(configPrefix + "bucket")
|
s.bucket = configuration.GetString(configPrefix + "bucket")
|
||||||
s.endpoint = configuration.GetString(configPrefix + "endpoint")
|
s.endpoint = configuration.GetString(configPrefix + "endpoint")
|
||||||
s.storageClass = configuration.GetString(configPrefix + "storage_class")
|
s.storageClass = configuration.GetString(configPrefix + "storage_class")
|
||||||
|
s.forcePathStyle = util.ParseBool(configuration.GetString(configPrefix+"force_path_style"), true)
|
||||||
if s.storageClass == "" {
|
if s.storageClass == "" {
|
||||||
s.storageClass = "STANDARD_IA"
|
s.storageClass = "STANDARD_IA"
|
||||||
}
|
}
|
||||||
|
|
||||||
s.conn, err = createSession(s.aws_access_key_id, s.aws_secret_access_key, s.region, s.endpoint)
|
s.conn, err = createSession(s.aws_access_key_id, s.aws_secret_access_key, s.region, s.endpoint, s.forcePathStyle)
|
||||||
|
|
||||||
glog.V(0).Infof("created backend storage s3.%s for region %s bucket %s", s.id, s.region, s.bucket)
|
glog.V(0).Infof("created backend storage s3.%s for region %s bucket %s", s.id, s.region, s.bucket)
|
||||||
return
|
return
|
||||||
@ -69,6 +72,7 @@ func (s *S3BackendStorage) ToProperties() map[string]string {
|
|||||||
m["bucket"] = s.bucket
|
m["bucket"] = s.bucket
|
||||||
m["endpoint"] = s.endpoint
|
m["endpoint"] = s.endpoint
|
||||||
m["storage_class"] = s.storageClass
|
m["storage_class"] = s.storageClass
|
||||||
|
m["force_path_style"] = util.BoolToString(s.forcePathStyle)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@ package s3_backend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/request"
|
"github.com/aws/aws-sdk-go/aws/request"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
@ -26,7 +27,7 @@ func getSession(region string) (s3iface.S3API, bool) {
|
|||||||
return sess, found
|
return sess, found
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSession(awsAccessKeyId, awsSecretAccessKey, region, endpoint string) (s3iface.S3API, error) {
|
func createSession(awsAccessKeyId, awsSecretAccessKey, region, endpoint string, forcePathStyle bool) (s3iface.S3API, error) {
|
||||||
|
|
||||||
sessionsLock.Lock()
|
sessionsLock.Lock()
|
||||||
defer sessionsLock.Unlock()
|
defer sessionsLock.Unlock()
|
||||||
@ -38,7 +39,7 @@ func createSession(awsAccessKeyId, awsSecretAccessKey, region, endpoint string)
|
|||||||
config := &aws.Config{
|
config := &aws.Config{
|
||||||
Region: aws.String(region),
|
Region: aws.String(region),
|
||||||
Endpoint: aws.String(endpoint),
|
Endpoint: aws.String(endpoint),
|
||||||
S3ForcePathStyle: aws.Bool(true),
|
S3ForcePathStyle: aws.Bool(forcePathStyle),
|
||||||
S3DisableContentMD5Validation: aws.Bool(true),
|
S3DisableContentMD5Validation: aws.Bool(true),
|
||||||
}
|
}
|
||||||
if awsAccessKeyId != "" && awsSecretAccessKey != "" {
|
if awsAccessKeyId != "" && awsSecretAccessKey != "" {
|
||||||
|
@ -28,6 +28,18 @@ func ParseUint64(text string, defaultValue uint64) uint64 {
|
|||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseBool(s string, defaultValue bool) bool {
|
||||||
|
value, err := strconv.ParseBool(s)
|
||||||
|
if err != nil {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func BoolToString(b bool) string {
|
||||||
|
return strconv.FormatBool(b)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
|
func ParseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
|
||||||
if !strings.HasPrefix(entryPath, "http://") && !strings.HasPrefix(entryPath, "https://") {
|
if !strings.HasPrefix(entryPath, "http://") && !strings.HasPrefix(entryPath, "https://") {
|
||||||
entryPath = "http://" + entryPath
|
entryPath = "http://" + entryPath
|
||||||
|
Loading…
Reference in New Issue
Block a user