storj.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. "github.com/seaweedfs/seaweedfs/weed/util"
  11. "os"
  12. )
  13. func init() {
  14. remote_storage.RemoteStorageClientMakers["storj"] = new(StorjRemoteStorageMaker)
  15. }
  16. type StorjRemoteStorageMaker struct{}
  17. func (s StorjRemoteStorageMaker) HasBucket() bool {
  18. return true
  19. }
  20. func (s StorjRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.RemoteStorageClient, error) {
  21. client := &s3RemoteStorageClient{
  22. supportTagging: true,
  23. conf: conf,
  24. }
  25. accessKey := util.Nvl(conf.StorjAccessKey, os.Getenv("AWS_ACCESS_KEY_ID"))
  26. secretKey := util.Nvl(conf.StorjSecretKey, os.Getenv("AWS_SECRET_ACCESS_KEY"))
  27. config := &aws.Config{
  28. Endpoint: aws.String(conf.StorjEndpoint),
  29. Region: aws.String("us-west-2"),
  30. S3ForcePathStyle: aws.Bool(true),
  31. S3DisableContentMD5Validation: aws.Bool(true),
  32. }
  33. if accessKey != "" && secretKey != "" {
  34. config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
  35. }
  36. sess, err := session.NewSession(config)
  37. if err != nil {
  38. return nil, fmt.Errorf("create storj session: %v", err)
  39. }
  40. sess.Handlers.Build.PushFront(skipSha256PayloadSigning)
  41. client.conn = s3.New(sess)
  42. return client, nil
  43. }