Skip to content

Commit

Permalink
Merge pull request adnanh#486 from moorereason/iss439-raw-body
Browse files Browse the repository at this point in the history
Add option to send raw request body to command
  • Loading branch information
adnanh authored Dec 6, 2020
2 parents b6e5b11 + 62f9c01 commit 2e4aea4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
22 changes: 13 additions & 9 deletions internal/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ import (

// Constants used to specify the parameter source
const (
SourceHeader string = "header"
SourceQuery string = "url"
SourceQueryAlias string = "query"
SourcePayload string = "payload"
SourceRequest string = "request"
SourceString string = "string"
SourceEntirePayload string = "entire-payload"
SourceEntireQuery string = "entire-query"
SourceEntireHeaders string = "entire-headers"
SourceHeader string = "header"
SourceQuery string = "url"
SourceQueryAlias string = "query"
SourcePayload string = "payload"
SourceRawRequestBody string = "raw-request-body"
SourceRequest string = "request"
SourceString string = "string"
SourceEntirePayload string = "entire-payload"
SourceEntireQuery string = "entire-query"
SourceEntireHeaders string = "entire-headers"
)

const (
Expand Down Expand Up @@ -459,6 +460,9 @@ func (ha *Argument) Get(r *Request) (string, error) {
case SourceString:
return ha.Name, nil

case SourceRawRequestBody:
return string(r.Body), nil

case SourceRequest:
if r == nil || r.RawRequest == nil {
return "", errors.New("request is nil")
Expand Down
11 changes: 11 additions & 0 deletions test/hooks.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@
],
}
},
{
"id": "txt-raw",
"execute-command": "{{ .Hookecho }}",
"command-working-directory": "/",
"include-command-output-in-response": true,
"pass-arguments-to-command": [
{
"source": "raw-request-body"
}
]
},
{
"id": "sendgrid",
"execute-command": "{{ .Hookecho }}",
Expand Down
7 changes: 7 additions & 0 deletions test/hooks.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@
name: "app.messages.message.#text"
value: "Hello!!"

- id: txt-raw
execute-command: '{{ .Hookecho }}'
command-working-directory: /
include-command-output-in-response: true
pass-arguments-to-command:
- source: raw-request-body

- id: sendgrid
execute-command: '{{ .Hookecho }}'
command-working-directory: /
Expand Down
19 changes: 19 additions & 0 deletions webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,25 @@ env: HOOK_head_commit.timestamp=2013-03-12T08:14:29-07:00
`success`,
``,
},
{
"txt-raw",
"txt-raw",
nil,
"POST",
map[string]string{"Content-Type": "text/plain"},
"text/plain",
`# FOO
blah
blah`,
false,
http.StatusOK,
`# FOO
blah
blah`,
``,
},
{
"payload-json-array",
"sendgrid",
Expand Down

0 comments on commit 2e4aea4

Please sign in to comment.