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.

57 lines
1.7 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) Make(conf *remote_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  18. client := &s3RemoteStorageClient{
  19. conf: conf,
  20. }
  21. accessKey := util.Nvl(conf.WasabiAccessKey)
  22. secretKey := util.Nvl(conf.WasabiSecretKey)
  23. config := &aws.Config{
  24. Endpoint: aws.String(conf.WasabiEndpoint),
  25. Region: aws.String(conf.WasabiRegion),
  26. S3ForcePathStyle: aws.Bool(true),
  27. S3DisableContentMD5Validation: aws.Bool(true),
  28. }
  29. if accessKey != "" && secretKey != "" {
  30. config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
  31. }
  32. sess, err := session.NewSession(config)
  33. if err != nil {
  34. return nil, fmt.Errorf("create wasabi session: %v", err)
  35. }
  36. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  37. client.conn = s3.New(sess)
  38. return client, nil
  39. }
  40. var skipSha256PayloadSigning = func(r *request.Request) {
  41. // see https://github.com/ceph/ceph/pull/15965/files
  42. if r.ClientInfo.ServiceID != "S3" {
  43. return
  44. }
  45. if r.Operation.Name == "PutObject" || r.Operation.Name == "UploadPart" {
  46. if len(r.HTTPRequest.Header.Get("X-Amz-Content-Sha256")) == 0 {
  47. r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD")
  48. }
  49. }
  50. }