From 1fc4445668bbb8b831a2e0a701551479e578a0a3 Mon Sep 17 00:00:00 2001 From: Ivan Pesin Date: Fri, 25 Aug 2017 23:31:02 -0400 Subject: [PATCH] Produce warnings if unable to locate binary and if static parameters specified erroneously --- webhook.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/webhook.go b/webhook.go index 2567bcc..12731c8 100644 --- a/webhook.go +++ b/webhook.go @@ -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)