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.

45 lines
1.4 KiB

3 years ago
  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. supportTagging: false,
  21. conf: conf,
  22. }
  23. config := &aws.Config{
  24. Endpoint: aws.String(conf.BackblazeEndpoint),
  25. Region: aws.String("us-west-002"),
  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. }