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.

62 lines
1.8 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/request"
  7. "github.com/aws/aws-sdk-go/aws/session"
  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. )
  13. func init() {
  14. remote_storage.RemoteStorageClientMakers["wasabi"] = new(WasabiRemoteStorageMaker)
  15. }
  16. type WasabiRemoteStorageMaker struct{}
  17. func (s WasabiRemoteStorageMaker) HasBucket() bool {
  18. return true
  19. }
  20. func (s WasabiRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  21. client := &s3RemoteStorageClient{
  22. supportTagging: true,
  23. conf: conf,
  24. }
  25. accessKey := util.Nvl(conf.WasabiAccessKey)
  26. secretKey := util.Nvl(conf.WasabiSecretKey)
  27. config := &aws.Config{
  28. Endpoint: aws.String(conf.WasabiEndpoint),
  29. Region: aws.String(conf.WasabiRegion),
  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 wasabi session: %v", err)
  39. }
  40. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  41. client.conn = s3.New(sess)
  42. return client, nil
  43. }
  44. var skipSha256PayloadSigning = func(r *request.Request) {
  45. // see https://github.com/ceph/ceph/pull/15965/files
  46. if r.ClientInfo.ServiceID != "S3" {
  47. return
  48. }
  49. if r.Operation.Name == "PutObject" || r.Operation.Name == "UploadPart" {
  50. if len(r.HTTPRequest.Header.Get("X-Amz-Content-Sha256")) == 0 {
  51. r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD")
  52. }
  53. }
  54. }