-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastores.go
38 lines (31 loc) · 964 Bytes
/
datastores.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
}