mirror of
https://github.com/dragonheim/gagent.git
synced 2025-01-18 09:36:28 -08:00
Updated to clear errors captured by gosec.
This commit is contained in:
parent
27045c94d6
commit
749bd6557e
6 changed files with 49 additions and 30 deletions
4
go.mod
4
go.mod
|
@ -13,6 +13,6 @@ require (
|
|||
github.com/pebbe/zmq4 v1.2.7
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/slayer/autorestart v0.0.0-20170706172704-7bc8d250279b
|
||||
github.com/zclconf/go-cty v1.8.3
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
github.com/zclconf/go-cty v1.9.1
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
)
|
||||
|
|
8
go.sum
8
go.sum
|
@ -132,8 +132,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+
|
|||
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
|
||||
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
|
||||
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
|
||||
github.com/zclconf/go-cty v1.8.3 h1:48gwZXrdSADU2UW9eZKHprxAI7APZGW9XmExpJpSjT0=
|
||||
github.com/zclconf/go-cty v1.8.3/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
|
||||
github.com/zclconf/go-cty v1.9.1 h1:viqrgQwFl5UpSxc046qblj78wZXVDFnSOufaOTER+cc=
|
||||
github.com/zclconf/go-cty v1.9.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
|
||||
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -170,8 +170,8 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
|
@ -86,10 +86,10 @@ func sendAgent(wg *sync.WaitGroup, uuid string, connectString string, agent gstr
|
|||
sock, _ := zmq.NewSocket(zmq.REQ)
|
||||
defer sock.Close()
|
||||
|
||||
sock.SetIdentity(uuid)
|
||||
err := sock.SetIdentity(uuid)
|
||||
|
||||
log.Printf("[DEBUG] Attempting to connect to %s\n", connectString)
|
||||
err := sock.Connect(connectString)
|
||||
err = sock.Connect(connectString)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to connect to %s\n", connectString)
|
||||
os.Exit(10)
|
||||
|
|
|
@ -39,7 +39,7 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
defer workerSock.Close()
|
||||
|
||||
workerListener := fmt.Sprintf("tcp://%s:%d", config.ListenAddr, config.WorkerPort)
|
||||
workerSock.Bind(workerListener)
|
||||
_ = workerSock.Bind(workerListener)
|
||||
|
||||
workers := make([]string, 0)
|
||||
|
||||
|
@ -49,6 +49,9 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
poller2 := zmq.NewPoller()
|
||||
poller2.Add(workerSock, zmq.POLLIN)
|
||||
|
||||
wg.Add(1)
|
||||
go createClientListener(wg, config)
|
||||
|
||||
LOOP:
|
||||
for {
|
||||
/*
|
||||
|
@ -87,20 +90,36 @@ LOOP:
|
|||
workers = append(workers, identity)
|
||||
|
||||
case clientSock:
|
||||
/*
|
||||
* Get client request, route to first available worker
|
||||
*/
|
||||
msg, err := s.RecvMessage(0)
|
||||
log.Printf("[DEBUG] Client message received: %s", msg)
|
||||
if err == nil {
|
||||
workerSock.SendMessage(workers[0], "", msg)
|
||||
workers = workers[1:]
|
||||
}
|
||||
wg.Add(1)
|
||||
go createClientListener(wg, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create listener for client requests
|
||||
*/
|
||||
func createClientListener(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
||||
defer wg.Done()
|
||||
|
||||
clientSock, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
defer clientSock.Close()
|
||||
|
||||
clientListener := fmt.Sprintf("tcp://%s:%d", config.ListenAddr, config.ClientPort)
|
||||
log.Printf("[DEBUG] Binding to: %s", clientListener)
|
||||
_ = clientSock.Bind(clientListener)
|
||||
|
||||
for {
|
||||
msg, err := clientSock.RecvMessage(0)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
log.Printf("[DEBUG] Client message received: %s", msg)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func unwrap(msg []string) (head string, tail []string) {
|
||||
head = msg[0]
|
||||
if len(msg) > 1 && msg[1] == "" {
|
||||
|
|
|
@ -56,7 +56,7 @@ func getAgent(wg *sync.WaitGroup, uuid string, connectString string) {
|
|||
subscriber, _ := zmq.NewSocket(zmq.REP)
|
||||
defer subscriber.Close()
|
||||
|
||||
subscriber.Connect(connectString)
|
||||
_ = subscriber.Connect(connectString)
|
||||
|
||||
msg, err := subscriber.Recv(0)
|
||||
if err != nil {
|
||||
|
|
|
@ -211,16 +211,16 @@ func CommandPuts(i *Interp, argv []string, pd interface{}) (string, error) {
|
|||
func (i *Interp) RegisterCoreCommands() {
|
||||
name := [...]string{"+", "-", "*", "/", ">", ">=", "<", "<=", "==", "!="}
|
||||
for _, n := range name {
|
||||
i.RegisterCommand(n, CommandMath, nil)
|
||||
_ = i.RegisterCommand(n, CommandMath, nil)
|
||||
}
|
||||
i.RegisterCommand("set", CommandSet, nil)
|
||||
i.RegisterCommand("unset", CommandUnset, nil)
|
||||
i.RegisterCommand("if", CommandIf, nil)
|
||||
i.RegisterCommand("while", CommandWhile, nil)
|
||||
i.RegisterCommand("break", CommandRetCodes, nil)
|
||||
i.RegisterCommand("continue", CommandRetCodes, nil)
|
||||
i.RegisterCommand("proc", CommandProc, nil)
|
||||
i.RegisterCommand("return", CommandReturn, nil)
|
||||
i.RegisterCommand("error", CommandError, nil)
|
||||
i.RegisterCommand("puts", CommandPuts, nil)
|
||||
_ = i.RegisterCommand("set", CommandSet, nil)
|
||||
_ = i.RegisterCommand("unset", CommandUnset, nil)
|
||||
_ = i.RegisterCommand("if", CommandIf, nil)
|
||||
_ = i.RegisterCommand("while", CommandWhile, nil)
|
||||
_ = i.RegisterCommand("break", CommandRetCodes, nil)
|
||||
_ = i.RegisterCommand("continue", CommandRetCodes, nil)
|
||||
_ = i.RegisterCommand("proc", CommandProc, nil)
|
||||
_ = i.RegisterCommand("return", CommandReturn, nil)
|
||||
_ = i.RegisterCommand("error", CommandError, nil)
|
||||
_ = i.RegisterCommand("puts", CommandPuts, nil)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue