-
Notifications
You must be signed in to change notification settings - Fork 14
/
s3.go
90 lines (75 loc) · 2.48 KB
/
s3.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package registry
import (
"errors"
"github.com/coretrix/hitrix/pkg/entity"
"github.com/coretrix/hitrix/service"
s3 "github.com/coretrix/hitrix/service/component/amazon/storage"
"github.com/coretrix/hitrix/service/component/app"
"github.com/coretrix/hitrix/service/component/config"
"github.com/latolukasz/orm"
"github.com/sarulabs/di"
)
func ServiceDefinitionAmazonS3(bucketsMapping map[string]uint64) *service.Definition {
ORMRegistryContainer = append(ORMRegistryContainer, func(registry *orm.Registry) {
registry.RegisterEntity(&entity.S3BucketCounterEntity{})
})
return &service.Definition{
Name: service.AmazonS3Service,
Global: true,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
appService := ctn.Get(service.AppService).(*app.App)
disableSSL := false
if val, ok := configService.Bool("amazon_s3.disable_ssl"); ok && val {
disableSSL = true
}
endpoint, ok := configService.String("amazon_s3.endpoint")
if !ok {
return nil, errors.New("missing endpoint")
}
accessKeyID, ok := configService.String("amazon_s3.access_key_id")
if !ok {
return nil, errors.New("missing access_key_id")
}
secretAccessKey, ok := configService.String("amazon_s3.secret_access_key")
if !ok {
return nil, errors.New("missing secret_access_key")
}
region, ok := configService.String("amazon_s3.region")
if !ok {
return nil, errors.New("missing region")
}
urlPrefix, ok := configService.String("amazon_s3.url_prefix")
if !ok {
return nil, errors.New("missing url_prefix")
}
domain, ok := configService.String("amazon_s3.domain")
if !ok {
return nil, errors.New("missing domain")
}
bucketsConfigDefinitions, ok := configService.Get("amazon_s3.buckets")
if !ok {
return nil, errors.New("missing buckets")
}
bucketsConfigDefinitionsMap := map[string]map[string]string{}
for k, v := range bucketsConfigDefinitions.(map[interface{}]interface{}) {
bucketsConfigDefinitionsInnerMap := map[string]string{}
for k1, v1 := range v.(map[interface{}]interface{}) {
bucketsConfigDefinitionsInnerMap[k1.(string)] = v1.(string)
}
bucketsConfigDefinitionsMap[k.(string)] = bucketsConfigDefinitionsInnerMap
}
return s3.NewAmazonS3(
endpoint,
accessKeyID,
secretAccessKey,
bucketsMapping,
bucketsConfigDefinitionsMap,
region,
disableSSL,
urlPrefix,
domain,
appService.Mode), nil
},
}
}