Commit graph

149 commits

Author SHA1 Message Date
Cameron Moore
d2e315d9c6 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.
2015-11-18 12:00:47 -06:00
Adnan Hajdarevic
82bba7ba07 bump up the version 2015-11-13 09:24:17 +01:00
Cameron Moore
ea3dbf3438 Add environment arguments and improve testing
There's a lot in this commit.

 1. Add `pass-environment-to-command` option that works much like
 `pass-arguments-to-command`.  You can see an example usage in the
 "github" test case.

 2. Add a test program called "hookecho" that is used to test the
 webhook package instead of relying upon a system `echo` command.

 3. Move hooks_test.json to a template so that we can update the path to
 hookecho on the fly.

 4. Don't return an error at the end of hook.MatchRule.Evaluate().  All
 tests succeed for me now.
2015-11-02 15:11:23 -06:00
Adnan Hajdarević
6774079a57 Merge pull request #46 from moorereason/testing
Add testing framework for main webhook app
2015-10-31 09:29:34 +01:00
Adnan Hajdarević
334fbc814c Merge pull request #45 from moorereason/signals
Refactor signal handling and Windows support
2015-10-31 09:29:22 +01:00
Cameron Moore
802f3f572c Add testing framework for main webhook app
This commit adds a testing framework modeled after the godoc tests. It builds
webhook in a temporary directory, runs it with the supplied `hooks_test.json`
configuration, and then tests different payloads.  I use `/bin/echo` for the
test executable, so I've added build tags to exclude Windows.

Three minor (I hope) changes in functionality:

- I ended up moving everything from `init()` to `main()` because `init()` was
  firing while trying to build the tests, and it was dying since `hooks.json`
  didn't exist. I'm still not 100% sure `init()` was firing, but I didn't see
  any real need for anything to be in `init()` in the first place.

- make sure logger is using `os.Stderr`

- don't send `http.StatusBadRequest` when the Hook rules don't match.  "Bad
  Request" is used to identify malformed requests.  The request was properly
  formed and processed, so I think we should send back `http.StatusOK`.  For
  example, if I setup a webhook rule to only execute when commits are made to
  the `master` branch, we shouldn't send back `http.StatusBadRequest` when we
  ingest a payload for the `development` branch.

The test payloads are pretty verbose and could probably be shortened, but I kind
of like having an example payload for each service.  We can pare them down if we
want to do more focused, minimalist testing.
2015-10-30 21:32:48 -05:00
Cameron Moore
1c319a7a08 Refactor signal handling and Windows support
This commit drops webhook_windows.go in favor of simply pulling out the
signal handling code to separate files.
2015-10-29 11:17:15 -05:00
Cameron Moore
2947e5e0e8 Remove logging side-effects from hook package
The hook package should be self-contained and return errors instead of
relying on the log subsystem.  This commit removes the logging
side-effects from the hook package.  Custom errors are returned that
should be transparent to the caller -- they can just treat them as
simple errors if they don't care to check the type.
2015-10-29 11:00:30 -05:00
Adnan Hajdarevic
272546bb2b add nopanic flag 2015-10-04 17:06:17 +02:00
Adnan Hajdarevic
9977fa8c61 refactor 2015-06-06 14:28:00 +02:00
Adnan Hajdarevic
9c545a745f return command output, pass whole payload as json to the command 2015-06-06 14:19:52 +02:00
Adnan Hajdarevic
f1ebc440a4 match all hooks with the same id 2015-05-27 09:16:26 +02:00
Adnan Hajdarevic
4350685330 separated windows and other platforms to different files, removed signal watcher from windows build file so webhook can actually compile on windows, added string as a source, so you can pass static strings to your scripts without having to wrap them around with other scripts 2015-05-16 13:32:21 +02:00
Kevin Le Brun
6cd8258651 Fix for OS X USR1 signal
It seems that signals code for Linux and OS X (FreeBSD) are different. I
rely on `syscall.SIGUSR1` which should be cross-compatible.

Tested with `kill -usr1 <pid>` on OS X 10.10
2015-04-05 23:21:40 +02:00
Adnan Hajdarevic
1039151a16 added hook reload on USR1 signal 2015-03-31 22:10:35 +02:00
Adnan Hajdarević
db928228c8 bumping up the minor version 2015-03-30 15:33:15 +02:00
Kevin Le Brun
5f853d8aba Allow charset to be defined in Content-Type header
The payload couldn't be parsed when charset was present in the
`Content-Type` header. The content type should begin with the MIME type
so we now check if the content type starts with `application/json` or
`application/x-www-form-urlencoded`.

This closes #20
2015-03-29 20:01:56 +02:00
Adnan Hajdarevic
231426da57 removed leftover debug trace, fixed a panic bug 2015-03-21 01:26:04 +01:00
Adnan Hajdarevic
688483d6d1 added parse-parameters-as-json property to hooks, fixed some bugs in old code 2015-03-21 01:10:17 +01:00
Cameron Moore
7dd55f5232 Refactor to remove helpers package
This commit removes the "helpers" package by moving functions from the
package into the other packages that use them.

CheckPayloadSignature() and ExtractParamater() are simply moved to the
"hook" package.  I'm not sure of the usefulness of having these
functions exported, but I left them allow for now.

ValuesToMap() is moved to the "main" webhook package and renamed to
valuesToMap().

Tests were moved into the "hook" package since we only test
ExtractParameter() right now.

This commit closes adnanh/webhook#12.
2015-03-20 08:55:42 -05:00
Cameron Moore
e9aaeb579e Rework negroni Logger creation
From `go vet`:

webhook.go:98: github.com/codegangsta/negroni.Logger composite literal uses unkeyed fields
2015-03-19 09:23:47 -05:00
Adnan Hajdarevic
f83af97138 added per-hook defined response message 2015-03-17 19:34:54 +01:00
Adnan Hajdarevic
5a96a5721a added custom url prefix for served hooks url path 2015-03-17 19:05:18 +01:00
Adnan Hajdarevic
ad76b51e6a updated minor version to 2.2.0 2015-03-14 13:04:28 +01:00
Adnan Hajdarevic
c9adceb5d8 added support for https 2015-03-14 12:59:54 +01:00
Adnan Hajdarevic
d3f5da5489 bumped up the minor version to 2.1.0 2015-03-14 12:44:05 +01:00
Adnan Hajdarevic
652109d46e added ability to hot reload the hooks file 2015-03-14 12:37:45 +01:00
Adnan Hajdarevic
90528b2ed9 webhook 2.0.0 2015-03-13 01:31:49 +01:00
Adnan Hajdarević
2e16eb5d77 bumped up the minor version 2015-02-26 15:56:41 +01:00
Adnan Hajdarević
f47ba2ad97 Update webhook.go
misplaced closing bracket...
2015-02-26 15:56:15 +01:00
Adnan Hajdarevic
d285c08f9f logical error 2015-02-25 01:06:55 +01:00
Adnan Hajdarevic
73278ff99b github hookshot user agent fix 2015-02-25 00:27:05 +01:00
Adnan Hajdarevic
ea7fd4cb87 fix 2015-02-25 00:21:10 +01:00
Adnan Hajdarevic
f1c4415fc8 refactoring 2015-02-25 00:12:24 +01:00
Adnan Hajdarevic
a5d79fddd9 separated github from post handler 2015-02-24 16:52:55 +01:00
Adnan Hajdarevic
4e4260e24f wording 2015-01-20 19:00:31 +01:00
Adnan Hajdarevic
3c4c025233 added support for x-hub-signature 2015-01-20 18:57:16 +01:00
Adnan Hajdarevic
450852e1be removed signals 2015-01-15 16:52:26 +01:00
Adnan Hajdarevic
7b3ebcc9cb added signal watcher 2015-01-15 16:49:32 +01:00
Adnan Hajdarevic
f5276ea955 debugging... 2015-01-15 16:37:34 +01:00
Adnan Hajdarevic
fb8ac8564b bumped up the version to 1.0.1 2015-01-15 16:31:28 +01:00
Adnan Hajdarevic
179367a28d added support for secrets 2015-01-15 16:27:54 +01:00
Adnan Hajdarevic
363a5359bd refactoring 2015-01-13 02:12:19 +01:00
Adnan Hajdarevic
6af1966ac7 rotation is annoying 2015-01-13 02:07:08 +01:00
Adnan Hajdarevic
a4ce24550c fix 2015-01-13 01:49:49 +01:00
Adnan Hajdarevic
6c6f353c88 added logging support 2015-01-13 01:43:46 +01:00
Adnan Hajdarevic
7d9d3652ba refactoring 2015-01-13 01:07:47 +01:00
Adnan Hajdarevic
c70c21fda7 added flags to specify the hooks json file path, ip and port the webhook should serve on 2015-01-13 00:59:18 +01:00
Adnan Hajdarevic
ffabc5541e initial commit 2015-01-12 22:14:25 +01:00