Produce warnings if unable to locate binary and if static parameters specified erroneously

This commit is contained in:
Ivan Pesin 2017-08-25 23:31:02 -04:00
parent d52d7bde1c
commit 1fc4445668

View file

@ -312,7 +312,21 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
func handleHook(h *hook.Hook, headers, query, payload *map[string]interface{}, body *[]byte) (string, error) {
var errors []error
cmd := exec.Command(h.ExecuteCommand)
// check the command exists
cmdPath, err := exec.LookPath(h.ExecuteCommand)
if err != nil {
log.Printf("unable to locate command: '%s'", h.ExecuteCommand)
// check if parameters specified in execute-command by mistake
if strings.IndexByte(h.ExecuteCommand, ' ') != -1 {
s := strings.Fields(h.ExecuteCommand)[0]
log.Printf("use 'pass-arguments-to-command' to specify args for '%s'", s)
}
return "", err
}
cmd := exec.Command(cmdPath)
cmd.Dir = h.CommandWorkingDirectory
cmd.Args, errors = h.ExtractCommandArguments(headers, query, payload)