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.

51 lines
1.6 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. v4 "github.com/aws/aws-sdk-go/aws/signer/v4"
  8. "github.com/aws/aws-sdk-go/service/s3"
  9. "github.com/chrislusf/seaweedfs/weed/pb/remote_pb"
  10. "github.com/chrislusf/seaweedfs/weed/remote_storage"
  11. "github.com/chrislusf/seaweedfs/weed/util"
  12. "os"
  13. )
  14. func init() {
  15. remote_storage.RemoteStorageClientMakers["filebase"] = new(FilebaseRemoteStorageMaker)
  16. }
  17. type FilebaseRemoteStorageMaker struct{}
  18. func (s FilebaseRemoteStorageMaker) HasBucket() bool {
  19. return true
  20. }
  21. func (s FilebaseRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  22. client := &s3RemoteStorageClient{
  23. conf: conf,
  24. }
  25. accessKey := util.Nvl(conf.FilebaseAccessKey, os.Getenv("AWS_ACCESS_KEY_ID"))
  26. secretKey := util.Nvl(conf.FilebaseSecretKey, os.Getenv("AWS_SECRET_ACCESS_KEY"))
  27. config := &aws.Config{
  28. Endpoint: aws.String(conf.FilebaseEndpoint),
  29. Region: aws.String("us-east-1"),
  30. S3ForcePathStyle: aws.Bool(true),
  31. S3DisableContentMD5Validation: aws.Bool(true),
  32. }
  33. if accessKey != "" && secretKey != "" {
  34. config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
  35. }
  36. sess, err := session.NewSession(config)
  37. if err != nil {
  38. return nil, fmt.Errorf("create filebase session: %v", err)
  39. }
  40. sess.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
  41. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  42. client.conn = s3.New(sess)
  43. return client, nil
  44. }