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.

49 lines
1.4 KiB

3 years ago
  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/remote_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["tencent"] = new(TencentRemoteStorageMaker)
  15. }
  16. type TencentRemoteStorageMaker struct{}
  17. func (s TencentRemoteStorageMaker) HasBucket() bool {
  18. return true
  19. }
  20. func (s TencentRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  21. client := &s3RemoteStorageClient{
  22. conf: conf,
  23. }
  24. accessKey := util.Nvl(conf.TencentSecretId, os.Getenv("COS_SECRETID"))
  25. secretKey := util.Nvl(conf.TencentSecretKey, os.Getenv("COS_SECRETKEY"))
  26. config := &aws.Config{
  27. Endpoint: aws.String(conf.TencentEndpoint),
  28. Region: aws.String("us-west-2"),
  29. S3ForcePathStyle: aws.Bool(true),
  30. S3DisableContentMD5Validation: aws.Bool(true),
  31. }
  32. if accessKey != "" && secretKey != "" {
  33. config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
  34. }
  35. sess, err := session.NewSession(config)
  36. if err != nil {
  37. return nil, fmt.Errorf("create tencent session: %v", err)
  38. }
  39. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  40. client.conn = s3.New(sess)
  41. return client, nil
  42. }