-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
69 lines (61 loc) · 1.43 KB
/
config.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
package common
import (
"encoding/json"
"io"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
// Config is representation of the configuration data
type Config struct {
Account Account
Accounts map[string]Account
AccountsMap map[string]string
CacheExpireTime string
CachePurgeTime string
ImageCache *S3Cache
ListenAddress string
LogLevel string
Org string
Token string
Version Version
}
// Account is the configuration for an individual account
type Account struct {
Akid string
Endpoint string
ExternalID string
Region string
Role string
Secret string
}
// Version carries around the API version information
type Version struct {
Version string
VersionPrerelease string
BuildStamp string
GitHash string
}
type S3Cache struct {
Bucket string
Endpoint string
Region string
Akid string
Secret string
Prefix string
HashingToken string
AccessLog *AccessLog
}
// AccessLog is the configuration for a bucket's access log
type AccessLog struct {
Bucket string
Prefix string
}
// ReadConfig decodes the configuration from an io Reader
func ReadConfig(r io.Reader) (Config, error) {
var c Config
log.Infoln("Reading configuration")
if err := json.NewDecoder(r).Decode(&c); err != nil {
return c, errors.Wrap(err, "unable to decode JSON message")
}
return c, nil
}