-
Notifications
You must be signed in to change notification settings - Fork 14
/
stores.go
73 lines (62 loc) · 2.21 KB
/
stores.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"errors"
"fmt"
"github.com/go-kit/kit/log"
"github.com/monax/hoard/v7/config"
"github.com/monax/hoard/v7/stores"
"github.com/monax/hoard/v7/stores/cloud"
"github.com/monax/hoard/v7/stores/ipfs"
)
func StoreFromStorageConfig(storageConfig *config.Storage, logger log.Logger) (stores.NamedStore, error) {
addressEncoding, err := stores.GetAddressEncoding(storageConfig.AddressEncoding)
if err != nil {
return nil, err
}
switch storageConfig.StorageType {
case config.Memory, config.Unspecified:
return stores.NewMemoryStore(), nil
case config.Filesystem:
fsConf := storageConfig.FileSystemConfig
if fsConf == nil {
return nil, errors.New("filesystem storage configuration must be " +
"supplied to use the filesystem storage backend")
}
if fsConf.RootDirectory == "" {
return nil, errors.New("rootDirectory key must be non-empty in " + "filesystem storage")
}
return stores.NewFileSystemStore(fsConf.RootDirectory, addressEncoding)
case config.IPFS:
ipfsConf := storageConfig.IPFSConfig
if ipfsConf == nil {
return nil, errors.New("IPFS storage configuration must be " +
"supplied to use the filesystem storage backend")
}
if ipfsConf.RemoteAPI == "" {
return nil, errors.New("http api url must be non-empty in " +
"ipfs storage config")
}
return ipfs.NewStore(ipfsConf.RemoteAPI, addressEncoding)
case config.AWS:
awsConf := storageConfig.Cloud
if awsConf == nil {
return nil, errors.New("aws configuration must be supplied")
}
return cloud.NewStore(cloud.AWS, awsConf.Bucket, awsConf.Prefix, awsConf.Region, addressEncoding, logger)
case config.Azure:
azureConf := storageConfig.Cloud
if azureConf == nil {
return nil, errors.New("azure configuration must be supplied")
}
return cloud.NewStore(cloud.Azure, azureConf.Bucket, azureConf.Prefix, azureConf.Region, addressEncoding, logger)
case config.GCP:
gcpConf := storageConfig.Cloud
if gcpConf == nil {
return nil, errors.New("gcp configuration must be supplied")
}
return cloud.NewStore(cloud.GCP, gcpConf.Bucket, gcpConf.Prefix, gcpConf.Region, addressEncoding, logger)
default:
return nil, fmt.Errorf("did not recognise storage type '%s'",
storageConfig.StorageType)
}
}