backblaze.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "github.com/aws/aws-sdk-go/service/s3"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/remote_pb"
  9. "github.com/seaweedfs/seaweedfs/weed/remote_storage"
  10. )
  11. func init() {
  12. remote_storage.RemoteStorageClientMakers["b2"] = new(BackBlazeRemoteStorageMaker)
  13. }
  14. type BackBlazeRemoteStorageMaker struct{}
  15. func (s BackBlazeRemoteStorageMaker) HasBucket() bool {
  16. return true
  17. }
  18. func (s BackBlazeRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  19. client := &s3RemoteStorageClient{
  20. supportTagging: false,
  21. conf: conf,
  22. }
  23. config := &aws.Config{
  24. Endpoint: aws.String(conf.BackblazeEndpoint),
  25. Region: aws.String(conf.BackblazeRegion),
  26. S3ForcePathStyle: aws.Bool(true),
  27. S3DisableContentMD5Validation: aws.Bool(true),
  28. }
  29. if conf.BackblazeKeyId != "" && conf.BackblazeApplicationKey != "" {
  30. config.Credentials = credentials.NewStaticCredentials(conf.BackblazeKeyId, conf.BackblazeApplicationKey, "")
  31. }
  32. sess, err := session.NewSession(config)
  33. if err != nil {
  34. return nil, fmt.Errorf("create backblaze session: %v", err)
  35. }
  36. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  37. client.conn = s3.New(sess)
  38. return client, nil
  39. }