-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
93 lines (80 loc) · 2.34 KB
/
main.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
package main
import (
"flag"
"fmt"
"os"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/bnb-chain/greenfield-challenger/app"
"github.com/bnb-chain/greenfield-challenger/config"
"github.com/bnb-chain/greenfield-challenger/logging"
)
func initFlags() {
flag.String(config.FlagConfigPath, "", "config file path")
flag.String(config.FlagConfigType, "", "config type, local_private_key or aws_private_key")
flag.String(config.FlagConfigAwsRegion, "", "aws region")
flag.String(config.FlagConfigAwsSecretKey, "", "aws secret key")
flag.String(config.FlagConfigPrivateKey, "", "challenger private key")
flag.String(config.FlagConfigBlsPrivateKey, "", "challenger bls private key")
flag.String(config.FlagConfigDbPass, "", "challenger db password")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
err := viper.BindPFlags(pflag.CommandLine)
if err != nil {
panic(err)
}
}
func printUsage() {
fmt.Print("usage: ./greenfield-challenger --config-type local --config-path configFile\n")
fmt.Print("usage: ./greenfield-challenger --config-type aws --aws-region awsRegion --aws-secret-key awsSecretKey\n")
}
func main() {
var (
cfg *config.Config
configType, configFilePath string
)
initFlags()
configType = viper.GetString(config.FlagConfigType)
if configType == "" {
configType = os.Getenv(config.ConfigType)
}
if configType != config.AWSConfig && configType != config.LocalConfig {
printUsage()
return
}
if configType == config.AWSConfig {
awsSecretKey := viper.GetString(config.FlagConfigAwsSecretKey)
if awsSecretKey == "" {
printUsage()
return
}
awsRegion := viper.GetString(config.FlagConfigAwsRegion)
if awsRegion == "" {
printUsage()
return
}
configContent, err := config.GetSecret(awsSecretKey, awsRegion)
if err != nil {
fmt.Printf("get aws config error, err=%+v", err.Error())
return
}
cfg = config.ParseConfigFromJson(configContent)
} else {
configFilePath = viper.GetString(config.FlagConfigPath)
if configFilePath == "" {
configFilePath = os.Getenv(config.ConfigFilePath)
if configFilePath == "" {
printUsage()
return
}
}
cfg = config.ParseConfigFromFile(configFilePath)
}
if cfg == nil {
fmt.Println("failed to get configuration")
return
}
logging.InitLogger(&cfg.LogConfig)
app.NewApp(cfg).Start()
select {}
}