backblaze.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/chrislusf/seaweedfs/weed/pb/remote_pb"
  9. "github.com/chrislusf/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. conf: conf,
  21. }
  22. config := &aws.Config{
  23. Endpoint: aws.String(conf.BackblazeEndpoint),
  24. Region: aws.String("us-west-002"),
  25. S3ForcePathStyle: aws.Bool(true),
  26. S3DisableContentMD5Validation: aws.Bool(true),
  27. }
  28. if conf.BackblazeKeyId != "" && conf.BackblazeApplicationKey != "" {
  29. config.Credentials = credentials.NewStaticCredentials(conf.BackblazeKeyId, conf.BackblazeApplicationKey, "")
  30. }
  31. sess, err := session.NewSession(config)
  32. if err != nil {
  33. return nil, fmt.Errorf("create backblaze session: %v", err)
  34. }
  35. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  36. client.conn = s3.New(sess)
  37. return client, nil
  38. }