-
Notifications
You must be signed in to change notification settings - Fork 236
/
main.go
72 lines (62 loc) · 2.16 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
package main
import (
_ "embed"
"flag"
"fmt"
"golang.org/x/term"
"log"
"os"
"syscall"
td2 "github.com/blockpane/tenderduty/v2/td2"
)
//go:embed example-config.yml
var defaultConfig []byte
func main() {
var configFile, chainConfigDirectory, stateFile, encryptedFile, password string
var dumpConfig, encryptConfig, decryptConfig bool
flag.StringVar(&configFile, "f", "config.yml", "configuration file to use, can also be set with the ENV var 'CONFIG'")
flag.StringVar(&encryptedFile, "encrypted-config", "config.yml.asc", "encrypted config file, only valid with -encrypt or -decrypt flag")
flag.StringVar(&password, "password", "", "password to use for encrypting/decrypting the config, if unset will prompt, also can use ENV var 'PASSWORD'")
flag.StringVar(&stateFile, "state", ".tenderduty-state.json", "file for storing state between restarts")
flag.StringVar(&chainConfigDirectory, "cc", "chains.d", "directory containing additional chain specific configurations")
flag.BoolVar(&dumpConfig, "example-config", false, "print the an example config.yml and exit")
flag.BoolVar(&encryptConfig, "encrypt", false, "encrypt the file specified by -f to -encrypted-config")
flag.BoolVar(&decryptConfig, "decrypt", false, "decrypt the file specified by -encrypted-config to -f")
flag.Parse()
if dumpConfig {
fmt.Println(string(defaultConfig))
os.Exit(0)
}
if configFile == "config.yml" && os.Getenv("CONFIG") != "" {
configFile = os.Getenv("CONFIG")
}
if os.Getenv("PASSWORD") != "" {
password = os.Getenv("PASSWORD")
}
if encryptConfig || decryptConfig {
if password == "" {
fmt.Print("Please enter the encryption password: ")
pass, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal(err)
}
fmt.Println("")
password = string(pass)
pass = nil
}
var e error
if encryptConfig {
e = td2.EncryptedConfig(configFile, encryptedFile, password, false)
} else {
e = td2.EncryptedConfig(configFile, encryptedFile, password, true)
}
if e != nil {
log.Fatalln(e)
}
os.Exit(0)
}
err := td2.Run(configFile, stateFile, chainConfigDirectory, &password)
if err != nil {
log.Println(err.Error(), "... exiting.")
}
}