-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathstart.go
112 lines (85 loc) · 2.54 KB
/
start.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"github.com/nsmithuk/local-kms/src"
"github.com/nsmithuk/local-kms/src/config"
log "github.com/sirupsen/logrus"
"os"
"path/filepath"
)
var (
Version string
GitCommit string
)
func main() {
logger := log.New()
logger.SetFormatter(&log.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05.000",
})
//---
if Version == "" {
Version = "Version Unknown"
}
if GitCommit == "" {
GitCommit = "Commit Hash Unknown"
}
logger.Infof("Local KMS %s (%s)", Version, GitCommit)
//---
accountId := os.Getenv("KMS_ACCOUNT_ID")
if accountId == "" {
// Environment variables should now all be prefixed with KMS_. Support for variables without this prefix will be removed in v4.
accountId = os.Getenv("ACCOUNT_ID")
if accountId != "" {
logger.Warn("The environment variable ACCOUNT_ID has been deprecated and will be removed in v4. Use KMS_ACCOUNT_ID instead.")
}
}
if accountId == "" {
accountId = "111122223333"
}
config.AWSAccountId = accountId
region := os.Getenv("KMS_REGION")
if region == "" {
// Environment variables should now all be prefixed with KMS_. Support for variables without this prefix will be removed in v4.
region = os.Getenv("REGION")
if region != "" {
logger.Warn("The environment variable REGION has been deprecated and will be removed in v4. Use KMS_REGION instead.")
}
}
if region == "" {
region = "eu-west-2"
}
config.AWSRegion = region
dataPath := os.Getenv("KMS_DATA_PATH")
if dataPath == "" {
// Environment variables should now all be prefixed with KMS_. Support for variables without this prefix will be removed in v4.
dataPath = os.Getenv("DATA_PATH")
if dataPath != "" {
logger.Warn("The environment variable DATA_PATH has been deprecated and will be removed in v4. Use KMS_DATA_PATH instead.")
}
}
if dataPath == "" {
dataPath = "/tmp/local-kms"
}
config.DatabasePath, _ = filepath.Abs(dataPath)
//-------------------------------
// Seed
seedPath := os.Getenv("KMS_SEED_PATH")
if seedPath == "" {
// Environment variables should now all be prefixed with KMS_. Support for variables without this prefix will be removed in v4.
seedPath = os.Getenv("SEED_PATH")
if seedPath != "" {
logger.Warn("The environment variable SEED_PATH has been deprecated and will be removed in v4. Use KMS_SEED_PATH instead.")
}
}
if seedPath == "" {
seedPath = "/init/seed.yaml"
}
//-------------------------------
// Run
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
src.Run(port, seedPath)
}