This repository was archived by the owner on Feb 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (46 loc) · 1.39 KB
/
Copy pathmain.go
File metadata and controls
56 lines (46 loc) · 1.39 KB
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
package main
import (
"log"
"os"
"os/signal"
"time"
"github.com/jessevdk/go-flags"
"github.com/thecoderstudio/apollo-agent/api"
"github.com/thecoderstudio/apollo-agent/logging"
"github.com/thecoderstudio/apollo-agent/net"
)
var opts struct {
Host string `short:"h" long:"host" description:"Host address" required:"true"`
AgentID string `long:"agent-id" description:"Apollo agent id" required:"true"`
Secret string `long:"secret" description:"Apollo OAuth client secret" required:"true"`
Shell string `long:"shell" description:"Path to shell" default:"/bin/bash"`
ReconnectInterval int `short:"i" long:"reconnect-interval" description:"Interval in seconds between reconnection attempts" default:"5"`
}
func main() {
log.SetFlags(0)
parseArguments()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
host := net.GetHostFromURLString(opts.Host)
if host == "" {
logging.Critical("No valid host given")
return
}
middleware, err := api.CreateMiddleware(host, opts.AgentID, opts.Secret, opts.Shell, &interrupt)
if err != nil {
logging.Critical(err)
return
}
reconnectInterval := time.Duration(opts.ReconnectInterval) * time.Second
err = middleware.Start(reconnectInterval)
if err != nil {
logging.Critical(err)
return
}
}
func parseArguments() {
_, err := flags.Parse(&opts)
if err != nil {
panic(err)
}
}