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.

38 lines
1.1 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/session"
  7. "github.com/aws/aws-sdk-go/service/s3"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_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) Make(conf *filer_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  16. client := &s3RemoteStorageClient{
  17. conf: conf,
  18. }
  19. config := &aws.Config{
  20. Endpoint: aws.String(conf.BackblazeEndpoint),
  21. Region: aws.String("us-west-002"),
  22. S3ForcePathStyle: aws.Bool(true),
  23. }
  24. if conf.BackblazeKeyId != "" && conf.BackblazeApplicationKey != "" {
  25. config.Credentials = credentials.NewStaticCredentials(conf.BackblazeKeyId, conf.BackblazeApplicationKey, "")
  26. }
  27. sess, err := session.NewSession(config)
  28. if err != nil {
  29. return nil, fmt.Errorf("create backblaze session: %v", err)
  30. }
  31. client.conn = s3.New(sess)
  32. return client, nil
  33. }