mirror of
https://github.com/adnanh/webhook.git
synced 2026-07-26 08:39:17 +08:00
Fix environment and argument passing
Two issues are addressed in this commit: 1. Instead of only sending the predefined environment arguments, this commit appends the arguments to the existing OS environment. Fixes #53. 2. If an argument is not found in the payload, allow the command to run and pass in an empty string as a placeholder. Fixes #54. Additionally, I replaced `hook.ErrInvalidPayloadSignature` with a new `SignatureError` type so that we can embed the signature in the error.
This commit is contained in:
+5
-5
@@ -238,16 +238,16 @@ func handleHook(h *hook.Hook, headers, query, payload *map[string]interface{}, b
|
||||
cmd.Args, err = h.ExtractCommandArguments(headers, query, payload)
|
||||
if err != nil {
|
||||
log.Printf("error extracting command arguments: %s", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
cmd.Env, err = h.ExtractCommandArgumentsForEnv(headers, query, payload)
|
||||
var envs []string
|
||||
envs, err = h.ExtractCommandArgumentsForEnv(headers, query, payload)
|
||||
if err != nil {
|
||||
log.Printf("error extracting command arguments: %s", err)
|
||||
return ""
|
||||
log.Printf("error extracting command arguments for environment: %s", err)
|
||||
}
|
||||
cmd.Env = append(os.Environ(), envs...)
|
||||
|
||||
log.Printf("executing %s (%s) with arguments %s and environment %s using %s as cwd\n", h.ExecuteCommand, cmd.Path, cmd.Args, cmd.Env, cmd.Dir)
|
||||
log.Printf("executing %s (%s) with arguments %q and environment %s using %s as cwd\n", h.ExecuteCommand, cmd.Path, cmd.Args, envs, cmd.Dir)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user