feat(sol): UDP + HTTP listener
This commit is contained in:
59
main.go
Normal file
59
main.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"wol-sol-agent/auth"
|
||||
"wol-sol-agent/config"
|
||||
"wol-sol-agent/server"
|
||||
"wol-sol-agent/utils"
|
||||
|
||||
"git.secnex.io/secnex/masterlog"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Load()
|
||||
pseudonymizer := masterlog.NewPseudonymizerFromString(utils.GetStringFromEnv("MASTERLOG_PSEUDONYMIZER", "high-secure-secret"))
|
||||
masterlog.SetPseudonymizer(pseudonymizer)
|
||||
masterlog.SetLevel(masterlog.Level(utils.GetIntFromEnv("MASTERLOG_LEVEL", int(masterlog.LevelInfo))))
|
||||
masterlog.AddSensitiveFields("AUTH_USER", "AUTH_PASS")
|
||||
masterlog.Info("Authentication enabled")
|
||||
|
||||
authenticator := auth.New(cfg.AuthUser, cfg.AuthPass)
|
||||
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
// Use os.Interrupt which works on all platforms (Windows, Linux, macOS)
|
||||
signal.Notify(sigChan, os.Interrupt)
|
||||
|
||||
udpServer := server.NewUDPServer(cfg.SOLPort, authenticator)
|
||||
udpDone := make(chan bool)
|
||||
go udpServer.Start(udpDone)
|
||||
|
||||
var apiDone chan bool
|
||||
if cfg.APIEnabled {
|
||||
apiServer := server.NewAPIServer(cfg.APIPort, authenticator)
|
||||
apiDone = make(chan bool)
|
||||
go apiServer.Start(apiDone)
|
||||
}
|
||||
|
||||
masterlog.Info("Starting servers", map[string]interface{}{
|
||||
"SOL_PORT": cfg.SOLPort,
|
||||
"API_PORT": cfg.APIPort,
|
||||
"API_ENABLED": cfg.APIEnabled,
|
||||
})
|
||||
|
||||
<-sigChan
|
||||
masterlog.Info("Shutting down", map[string]interface{}{
|
||||
"SOL_PORT": cfg.SOLPort,
|
||||
"API_PORT": cfg.APIPort,
|
||||
"API_ENABLED": cfg.APIEnabled,
|
||||
})
|
||||
|
||||
close(udpDone)
|
||||
if apiDone != nil {
|
||||
close(apiDone)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
Reference in New Issue
Block a user