mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-22 21:32:32 +00:00
Provide means to transfer files #162
This commit is contained in:
parent
147c95dd8b
commit
34c4b1c166
2 changed files with 80 additions and 4 deletions
27
webhook.go
27
webhook.go
|
@ -12,7 +12,7 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/adnanh/webhook/hook"
|
||||
"./hook"
|
||||
|
||||
"github.com/codegangsta/negroni"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -333,6 +333,31 @@ func handleHook(h *hook.Hook, headers, query, payload *map[string]interface{}, b
|
|||
|
||||
cmd.Env = append(os.Environ(), envs...)
|
||||
|
||||
var files []hook.FileParameter
|
||||
files, errors = h.ExtractCommandArgumentsForFile(headers, query, payload)
|
||||
|
||||
if errors != nil {
|
||||
for _, err := range errors {
|
||||
log.Printf("error extracting command arguments for file: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
for i := range files {
|
||||
var filename string
|
||||
if h.CommandWorkingDirectory != "" {
|
||||
filename = h.CommandWorkingDirectory + "/" + files[i].Filename
|
||||
} else {
|
||||
filename = files[i].Filename
|
||||
}
|
||||
|
||||
log.Printf("writing file %s", filename)
|
||||
|
||||
err := ioutil.WriteFile(filename, files[i].Data, 0644)
|
||||
if err != nil {
|
||||
log.Printf("error writing file %s [%s]", filename, err)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue