1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 17:22:21 +08:00
Files
kubo/repo/fsrepo/datastores.go
Tommi Virtanen 8f2d820412 S3 datastore support
To test it, set up an S3 bucket (in an AWS region that is not US
Standard, for read-after-write consistency), run `ipfs init`, then
edit `~/.ipfs/config` to say

      "Datastore": {
        "Type": "s3",
        "Region": "us-west-1",
        "Bucket": "mahbukkit",
        "ACL": "private"
      },

with the right values. Set `AWS_ACCESS_KEY_ID` and
`AWS_SECRET_ACCESS_KEY` in the environment and you should be able to
run `ipfs add` and `ipfs cat` and see the bucket be populated.

No automated tests exist, unfortunately. S3 is thorny to simulate.

License: MIT
Signed-off-by: Tommi Virtanen <tv@eagain.net>
2016-01-12 08:22:55 -08:00

39 lines
964 B
Go

package fsrepo
import (
"fmt"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/aws"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/s3"
repo "github.com/ipfs/go-ipfs/repo"
config "github.com/ipfs/go-ipfs/repo/config"
"github.com/ipfs/go-ipfs/thirdparty/s3-datastore"
)
func openS3Datastore(params config.S3Datastore) (repo.Datastore, error) {
// TODO support credentials files
auth, err := aws.EnvAuth()
if err != nil {
return nil, err
}
region := aws.GetRegion(params.Region)
if region.Name == "" {
return nil, fmt.Errorf("unknown AWS region: %q", params.Region)
}
if params.Bucket == "" {
return nil, fmt.Errorf("invalid S3 bucket: %q", params.Bucket)
}
client := s3.New(auth, region)
// There are too many gophermucking s3datastores in my
// gophermucking source.
return &s3datastore.S3Datastore{
Client: client,
Bucket: params.Bucket,
ACL: s3.ACL(params.ACL),
}, nil
}