-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
108 lines (98 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"log"
"os"
"strconv"
"github.com/urfave/cli/v2"
)
func runServer(c *cli.Context) error {
cnf := nodeConfig{
id: c.String("id"),
tlsVersion: getTLSVersion(c.String("tls-version")),
port: uint16(c.Int("port")),
token: c.String("token"),
dockerPath: c.String("docker-path"),
logLevel: c.String("log-level"),
}
if c.String("management-ips") != "" {
cnf.setMangementIPs(c.String("management-ips"))
}
if !c.Bool("no-write-env") {
err := cnf.writeEnv()
if err != nil {
panic(err)
}
}
app := newHTTPServer(&cnf)
return app.ListenTLS(
"0.0.0.0:"+strconv.Itoa(int(cnf.port)),
cnf.dockerPath+"/cert/fullchain.pem",
cnf.dockerPath+"/cert/privkey.pem",
)
}
func main() {
app := cli.NewApp()
app.Usage = "htm-node"
app.EnableBashCompletion = true
app.Commands = []*cli.Command{
{
Name: "run",
Usage: "Run protection server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "ID",
Required: true,
EnvVars: []string{"ASM_HTM_NODE_ID"},
},
&cli.StringFlag{
Name: "token",
Usage: "Token",
Required: true,
EnvVars: []string{"ASM_HTM_NODE_TOKEN"},
},
&cli.StringFlag{
Name: "tls-version",
Usage: "TLS Version",
Value: tlsVersionIntermediate,
EnvVars: []string{"ASM_HTM_NODE_TLS_VERSION"},
},
&cli.StringFlag{
Name: "management-ips",
Usage: "List management server IP addressess",
Value: "127.0.0.1",
EnvVars: []string{"ASM_HTM_MANAGEMENT_IP"},
},
&cli.IntFlag{
Name: "port",
Usage: "Port",
Value: 9199,
EnvVars: []string{"ASM_HTM_NODE_PORT"},
},
&cli.StringFlag{
Name: "docker-path",
Usage: "HTM docker path",
Value: "/opt/htm-docker",
EnvVars: []string{"ASM_HTM_NODE_DOCKER_PATH"},
},
&cli.BoolFlag{
Name: "no-write-env",
Usage: "Do not write environment variable on start",
Value: false,
EnvVars: []string{"ASM_HTM_WRITE_ENV"},
},
&cli.StringFlag{
Name: "log-level",
Usage: "Could be one of `panic`, `fatal`, `error`, `warn`, `info`, `debug` or `trace`",
Value: "warn",
EnvVars: []string{"ASM_HTM_NODE_LOG_LEVEL"},
},
},
Action: runServer,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}