-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
64 lines (51 loc) · 1.4 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
package main
import (
"flag"
"fmt"
"net"
"os"
"github.com/aau-network-security/haaukins-agent/internal/agent"
pb "github.com/aau-network-security/haaukins-agent/pkg/proto"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"google.golang.org/grpc"
)
const (
defaultConfigFile = "config/config.yml"
)
var (
version = "dev"
compileDate = "unknown"
)
func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
confFilePtr := flag.String("config", defaultConfigFile, "configuration file")
flag.Parse()
log.Info().Str("version", version).Str("compileDate", compileDate).Msg("Starting HAAUKINS Agent...")
c, err := agent.NewConfigFromFile(*confFilePtr)
if err != nil {
log.Fatal().Err(err).Msgf("unable to read configuration file: %s", *confFilePtr)
return
}
a, err := agent.New(c)
if err != nil {
log.Fatal().Err(err).Msg("unable to create daemon")
return
}
listenAddress := fmt.Sprintf("%s:%d", c.ListeningIp, c.GrpcPort)
lis, err := net.Listen("tcp", listenAddress)
if err != nil {
log.Fatal().Msgf("failed to listen: %v", err)
}
opts := []grpc.ServerOption{}
go func() {
a.RunGuacProxy()
}()
gRPCServer := a.NewGRPCServer(opts...)
pb.RegisterAgentServer(gRPCServer, a)
log.Info().Msg("server is waiting for clients")
if err := gRPCServer.Serve(lis); err != nil {
log.Fatal().Err(err).Msg("failed to serve")
}
}