-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
utils.go
25 lines (22 loc) · 895 Bytes
/
utils.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
package plugins
import (
"fmt"
"os/exec"
)
// CmdConfig is configuration used to register the LOOP and generate an exec
type CmdConfig struct {
ID string // unique string used by the node to track the LOOP. typically supplied by the loop logger name
Cmd string // string value of executable to exec
}
// NewCmdFactory is helper to ensure synchronization between the loop registry and os cmd to exec the LOOP
func NewCmdFactory(register func(id string) (*RegisteredLoop, error), lcfg CmdConfig) (func() *exec.Cmd, error) {
registeredLoop, err := register(lcfg.ID)
if err != nil {
return nil, fmt.Errorf("failed to register %s LOOP plugin: %w", lcfg.ID, err)
}
return func() *exec.Cmd {
cmd := exec.Command(lcfg.Cmd) //#nosec G204 -- we control the value of the cmd so the lint/sec error is a false positive
SetCmdEnvFromConfig(cmd, registeredLoop.EnvCfg)
return cmd
}, nil
}