filebase.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/seaweedfs/seaweedfs/weed/pb/remote_pb"
  10. "github.com/seaweedfs/seaweedfs/weed/remote_storage"
  11. "github.com/seaweedfs/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. supportTagging: true,
  24. conf: conf,
  25. }
  26. accessKey := util.Nvl(conf.FilebaseAccessKey, os.Getenv("AWS_ACCESS_KEY_ID"))
  27. secretKey := util.Nvl(conf.FilebaseSecretKey, os.Getenv("AWS_SECRET_ACCESS_KEY"))
  28. config := &aws.Config{
  29. Endpoint: aws.String(conf.FilebaseEndpoint),
  30. Region: aws.String("us-east-1"),
  31. S3ForcePathStyle: aws.Bool(true),
  32. S3DisableContentMD5Validation: aws.Bool(true),
  33. }
  34. if accessKey != "" && secretKey != "" {
  35. config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
  36. }
  37. sess, err := session.NewSession(config)
  38. if err != nil {
  39. return nil, fmt.Errorf("create filebase session: %v", err)
  40. }
  41. sess.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
  42. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  43. client.conn = s3.New(sess)
  44. return client, nil
  45. }