You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

  1. package s3
  2. import (
  3. "fmt"
  4. "github.com/aws/aws-sdk-go/aws"
  5. "github.com/aws/aws-sdk-go/aws/credentials"
  6. "github.com/aws/aws-sdk-go/aws/session"
  7. "github.com/aws/aws-sdk-go/service/s3"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. "github.com/chrislusf/seaweedfs/weed/remote_storage"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. "os"
  12. )
  13. func init() {
  14. remote_storage.RemoteStorageClientMakers["aliyun"] = new(AliyunRemoteStorageMaker)
  15. }
  16. type AliyunRemoteStorageMaker struct{}
  17. func (s AliyunRemoteStorageMaker) Make(conf *filer_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  18. client := &s3RemoteStorageClient{
  19. conf: conf,
  20. }
  21. accessKey := util.Nvl(conf.AliyunAccessKey, os.Getenv("ALICLOUD_ACCESS_KEY_ID"))
  22. secretKey := util.Nvl(conf.AliyunSecretKey, os.Getenv("ALICLOUD_ACCESS_KEY_SECRET"))
  23. config := &aws.Config{
  24. Endpoint: aws.String(conf.AliyunEndpoint),
  25. Region: aws.String(conf.AliyunRegion),
  26. S3ForcePathStyle: aws.Bool(false),
  27. }
  28. if accessKey != "" && secretKey != "" {
  29. config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
  30. }
  31. sess, err := session.NewSession(config)
  32. if err != nil {
  33. return nil, fmt.Errorf("create aliyun session: %v", err)
  34. }
  35. client.conn = s3.New(sess)
  36. return client, nil
  37. }