wasabi.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. conf: conf,
  23. }
  24. accessKey := util.Nvl(conf.WasabiAccessKey)
  25. secretKey := util.Nvl(conf.WasabiSecretKey)
  26. config := &aws.Config{
  27. Endpoint: aws.String(conf.WasabiEndpoint),
  28. Region: aws.String(conf.WasabiRegion),
  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 wasabi session: %v", err)
  38. }
  39. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  40. client.conn = s3.New(sess)
  41. return client, nil
  42. }
  43. var skipSha256PayloadSigning = func(r *request.Request) {
  44. // see https://github.com/ceph/ceph/pull/15965/files
  45. if r.ClientInfo.ServiceID != "S3" {
  46. return
  47. }
  48. if r.Operation.Name == "PutObject" || r.Operation.Name == "UploadPart" {
  49. if len(r.HTTPRequest.Header.Get("X-Amz-Content-Sha256")) == 0 {
  50. r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD")
  51. }
  52. }
  53. }