-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathmain.go
111 lines (86 loc) · 2.27 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
109
110
111
package main
import (
"os"
"os/signal"
"runtime"
"syscall"
"github.com/aquasecurity/postee/v2/router"
"github.com/aquasecurity/postee/v2/webserver"
"github.com/spf13/cobra"
"github.com/aquasecurity/postee/v2/log"
)
const (
URL = "0.0.0.0:8082"
TLS = "0.0.0.0:8445"
URL_USAGE = "The socket to bind to, specified using host:port."
TLS_USAGE = "The TLS socket to bind to, specified using host:port."
// CFG_USAGE = "The folder which contains alert configuration files."
// CFG_FOLDER = "/config/"
CFG_FILE = "/config/cfg.yaml"
CFG_USAGE = "The alert configuration file."
)
var (
url = ""
tls = ""
cfgfile = ""
)
var rootCmd = &cobra.Command{
Use: "webhooksrv",
Short: "Aqua Container Security Webhook server\n",
Long: "Aqua Container Security Webhook server\n",
}
func init() {
rootCmd.Flags().StringVar(&url, "url", URL, URL_USAGE)
rootCmd.Flags().StringVar(&tls, "tls", TLS, TLS_USAGE)
rootCmd.Flags().StringVar(&cfgfile, "cfgfile", CFG_FILE, CFG_USAGE)
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
rootCmd.Run = func(cmd *cobra.Command, args []string) {
if os.Getenv("AQUAALERT_URL") != "" {
url = os.Getenv("AQUAALERT_URL")
}
if os.Getenv("POSTEE_HTTP") != "" {
url = os.Getenv("POSTEE_HTTP")
}
if os.Getenv("AQUAALERT_TLS") != "" {
tls = os.Getenv("AQUAALERT_TLS")
}
if os.Getenv("POSTEE_HTTPS") != "" {
tls = os.Getenv("POSTEE_HTTPS")
}
if os.Getenv("AQUAALERT_CFG") != "" {
cfgfile = os.Getenv("AQUAALERT_CFG")
}
if os.Getenv("POSTEE_CFG") != "" {
cfgfile = os.Getenv("POSTEE_CFG")
}
postgresUrl := os.Getenv("POSTGRES_URL")
pathToDb := os.Getenv("PATH_TO_DB")
err := router.Instance().ApplyFileCfg(cfgfile, postgresUrl, pathToDb, false)
if err != nil {
log.Logger.Fatalf("Can't start alert manager: %v", err)
return
}
defer router.Instance().Terminate()
go webserver.Instance().Start(url, tls)
defer webserver.Instance().Terminate()
Daemonize()
}
err := rootCmd.Execute()
if err != nil {
log.Logger.Fatalf("Can't start command: %v", err)
return
}
}
func Daemonize() {
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
log.Logger.Info(sig)
done <- true
}()
<-done
}