• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H06-Dec-2020-3021

docs/H06-Dec-2020-1,2151,101

internal/H06-Dec-2020-2,3491,796

test/H06-Dec-2020-914885

vendor/H03-May-2022-602,285502,689

.gitignoreH A D06-Dec-202050 65

.travis.ymlH A D06-Dec-2020352 3326

CONTRIBUTING.mdH A D06-Dec-20204.4 KiB6742

LICENSEH A D06-Dec-20201.1 KiB2217

MakefileH A D06-Dec-20201.2 KiB4535

README.mdH A D06-Dec-202015.3 KiB219160

droppriv_nope.goH A D06-Dec-2020189 138

droppriv_unix.goH A D06-Dec-2020243 2215

go.modH A D06-Dec-2020642 2017

go.sumH A D06-Dec-20203 KiB3534

hooks.json.exampleH A D06-Dec-20201.1 KiB6160

hooks.json.tmpl.exampleH A D06-Dec-20201.2 KiB6160

hooks.yaml.exampleH A D06-Dec-2020685 2928

hooks.yaml.tmpl.exampleH A D06-Dec-2020713 2928

signals.goH A D06-Dec-2020919 5341

signals_windows.goH A D06-Dec-2020126 83

tls.goH A D06-Dec-20201.4 KiB8666

webhook.goH A D06-Dec-202022.6 KiB787588

webhook_test.goH A D06-Dec-202028.8 KiB1,1811,069

README.md

1# What is webhook? ![build-status][badge]
2
3 <img src="https://github.com/adnanh/webhook/raw/development/docs/logo/logo-128x128.png" alt="Webhook" align="left" />
4
5 [webhook][w] is a lightweight configurable tool written in Go, that allows you to easily create HTTP endpoints (hooks) on your server, which you can use to execute configured commands. You can also pass data from the HTTP request (such as headers, payload or query variables) to your commands. [webhook][w] also allows you to specify rules which have to be satisfied in order for the hook to be triggered.
6
7For example, if you're using Github or Bitbucket, you can use [webhook][w] to set up a hook that runs a redeploy script for your project on your staging server, whenever you push changes to the master branch of your project.
8
9If you use Mattermost or Slack, you can set up an "Outgoing webhook integration" or "Slash command" to run various commands on your server, which can then report back directly to you or your channels using the "Incoming webhook integrations", or the appropriate response body.
10
11[webhook][w] aims to do nothing more than it should do, and that is:
12 1. receive the request,
13 2. parse the headers, payload and query variables,
14 3. check if the specified rules for the hook are satisfied,
15 3. and finally, pass the specified arguments to the specified command via
16    command line arguments or via environment variables.
17
18Everything else is the responsibility of the command's author.
19
20# Hookdoo
21<a href="https://www.hookdoo.com/?github"><img src="https://www.hookdoo.com/logo/logo.svg" height="96" alt="hookdoo" align="left" /></a>
22
23If you don't have time to waste configuring, hosting, debugging and maintaining your webhook instance, we offer a __SaaS__ solution that has all of the capabilities webhook provides, plus a lot more, and all that packaged in a nice friendly web interface. If you are interested, find out more at [hookdoo website](https://www.hookdoo.com/?ref=github-webhook-readme). If you have any questions, you can contact us at info@hookdoo.com
24
25#
26
27<a href="https://www.hookdeck.io/?ref=adnanh-webhook"><img src="http://hajdarevic.net/hookdeck-logo.svg" height="17" alt="hookdeck" align="left" /></a> If you need a way of inspecting, monitoring and replaying webhooks without the back and forth troubleshooting, [give Hookdeck a try!](https://www.hookdeck.io/?ref=adnanh-webhook)
28
29# Getting started
30## Installation
31### Building from source
32To get started, first make sure you've properly set up your [Go](http://golang.org/doc/install) 1.14 or newer environment and then run
33```bash
34$ go build github.com/adnanh/webhook
35```
36to build the latest version of the [webhook][w].
37
38### Using package manager
39#### Snap store
40[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/webhook)
41
42#### Ubuntu
43If you are using Ubuntu linux (17.04 or later), you can install webhook using `sudo apt-get install webhook` which will install community packaged version.
44
45#### Debian
46If you are using Debian linux ("stretch" or later), you can install webhook using `sudo apt-get install webhook` which will install community packaged version (thanks [@freeekanayaka](https://github.com/freeekanayaka)) from https://packages.debian.org/sid/webhook
47
48### Download prebuilt binaries
49Prebuilt binaries for different architectures are available at [GitHub Releases](https://github.com/adnanh/webhook/releases).
50
51## Configuration
52Next step is to define some hooks you want [webhook][w] to serve.
53[webhook][w] supports JSON or YAML configuration files, but we'll focus primarily on JSON in the following example.
54Begin by creating an empty file named `hooks.json`. This file will contain an array of hooks the [webhook][w] will serve. Check [Hook definition page](docs/Hook-Definition.md) to see the detailed description of what properties a hook can contain, and how to use them.
55
56Let's define a simple hook named `redeploy-webhook` that will run a redeploy script located in `/var/scripts/redeploy.sh`. Make sure that your bash script has `#!/bin/sh` shebang on top.
57
58Our `hooks.json` file will now look like this:
59```json
60[
61  {
62    "id": "redeploy-webhook",
63    "execute-command": "/var/scripts/redeploy.sh",
64    "command-working-directory": "/var/webhook"
65  }
66]
67```
68
69**NOTE:** If you prefer YAML, the equivalent `hooks.yaml` file would be:
70```yaml
71- id: redeploy-webhook
72  execute-command: "/var/scripts/redeploy.sh"
73  command-working-directory: "/var/webhook"
74```
75
76You can now run [webhook][w] using
77```bash
78$ /path/to/webhook -hooks hooks.json -verbose
79```
80
81It will start up on default port 9000 and will provide you with one HTTP endpoint
82```http
83http://yourserver:9000/hooks/redeploy-webhook
84```
85
86Check [webhook parameters page](docs/Webhook-Parameters.md) to see how to override the ip, port and other settings such as hook hotreload, verbose output, etc, when starting the [webhook][w].
87
88By performing a simple HTTP GET or POST request to that endpoint, your specified redeploy script would be executed. Neat!
89
90However, hook defined like that could pose a security threat to your system, because anyone who knows your endpoint, can send a request and execute your command. To prevent that, you can use the `"trigger-rule"` property for your hook, to specify the exact circumstances under which the hook would be triggered. For example, you can use them to add a secret that you must supply as a parameter in order to successfully trigger the hook. Please check out the [Hook rules page](docs/Hook-Rules.md) for detailed list of available rules and their  usage.
91
92## Multipart Form Data
93[webhook][w] provides limited support the parsing of multipart form data.
94Multipart form data can contain two types of parts: values and files.
95All form _values_ are automatically added to the `payload` scope.
96Use the `parse-parameters-as-json` settings to parse a given value as JSON.
97All files are ignored unless they match one of the following criteria:
98
991. The `Content-Type` header is `application/json`.
1001. The part is named in the `parse-parameters-as-json` setting.
101
102In either case, the given file part will be parsed as JSON and added to the `payload` map.
103
104## Templates
105[webhook][w] can parse the hooks configuration file as a Go template when given the `-template` [CLI parameter](docs/Webhook-Parameters.md). See the [Templates page](docs/Templates.md) for more details on template usage.
106
107## Using HTTPS
108[webhook][w] by default serves hooks using http. If you want [webhook][w] to serve secure content using https, you can use the `-secure` flag while starting [webhook][w]. Files containing a certificate and matching private key for the server must be provided using the `-cert /path/to/cert.pem` and `-key /path/to/key.pem` flags. If the certificate is signed by a certificate authority, the cert file should be the concatenation of the server's certificate followed by the CA's certificate.
109
110TLS version and cipher suite selection flags are available from the command line. To list available cipher suites, use the `-list-cipher-suites` flag.  The `-tls-min-version` flag can be used with `-list-cipher-suites`.
111
112## CORS Headers
113If you want to set CORS headers, you can use the `-header name=value` flag while starting [webhook][w] to set the appropriate CORS headers that will be returned with each response.
114
115## Interested in running webhook inside of a Docker container?
116You can use [almir/webhook](https://hub.docker.com/r/almir/webhook/) docker image, or create your own (please read [this discussion](https://github.com/adnanh/webhook/issues/63)).
117
118## Examples
119Check out [Hook examples page](docs/Hook-Examples.md) for more complex examples of hooks.
120
121### Guides featuring webhook
122 - [Webhook & JIRA](https://sites.google.com/site/mrxpalmeiras/notes/jira-webhooks) by [@perfecto25](https://github.com/perfecto25)
123 - [Trigger Ansible AWX job runs on SCM (e.g. git) commit](http://jpmens.net/2017/10/23/trigger-awx-job-runs-on-scm-commit/) by [@jpmens](http://mens.de/)
124 - [Deploy using GitHub webhooks](https://davidauthier.wearemd.com/blog/deploy-using-github-webhooks.html) by [@awea](https://davidauthier.wearemd.com)
125 - [Setting up Automatic Deployment and Builds Using Webhooks](https://willbrowning.me/setting-up-automatic-deployment-and-builds-using-webhooks/) by [Will Browning](https://willbrowning.me/about/)
126 - [Auto deploy your Node.js app on push to GitHub in 3 simple steps](https://webhookrelay.com/blog/2018/07/17/auto-deploy-on-git-push/) by Karolis Rusenas
127 - [Automate Static Site Deployments with Salt, Git, and Webhooks](https://www.linode.com/docs/applications/configuration-management/automate-a-static-site-deployment-with-salt/) by [Linode](https://www.linode.com)
128 - [Using Prometheus to Automatically Scale WebLogic Clusters on Kubernetes](https://blogs.oracle.com/weblogicserver/using-prometheus-to-automatically-scale-weblogic-clusters-on-kubernetes-v5) by [Marina Kogan](https://blogs.oracle.com/author/9a4fe754-1cc2-4c64-95fc-360642b62927)
129 - [Github Pages and Jekyll - A New Platform for LACNIC Labs](https://labs.lacnic.net/a-new-platform-for-lacniclabs/) by [Carlos Martínez Cagnazzo](https://twitter.com/carlosm3011)
130 - [How to Deploy React Apps Using Webhooks and Integrating Slack on Ubuntu](https://www.alibabacloud.com/blog/how-to-deploy-react-apps-using-webhooks-and-integrating-slack-on-ubuntu_594116) by Arslan Ud Din Shafiq
131 - [Private webhooks](https://ihateithe.re/2018/01/private-webhooks/) by [Thomas](https://ihateithe.re/colophon/)
132 - [Adventures in webhooks](https://medium.com/@draketech/adventures-in-webhooks-2d6584501c62) by [Drake](https://medium.com/@draketech)
133 - [GitHub pro tips](http://notes.spencerlyon.com/2016/01/04/github-pro-tips/) by [Spencer Lyon](http://notes.spencerlyon.com/)
134 - [XiaoMi Vacuum + Amazon Button = Dash Cleaning](https://www.instructables.com/id/XiaoMi-Vacuum-Amazon-Button-Dash-Cleaning/) by [c0mmensal](https://www.instructables.com/member/c0mmensal/)
135 - [Set up Automated Deployments From Github With Webhook](https://maximorlov.com/automated-deployments-from-github-with-webhook/) by [Maxim Orlov](https://twitter.com/_maximization)
136 - VIDEO: [Gitlab CI/CD configuration using Docker and adnanh/webhook to deploy on VPS - Tutorial #1](https://www.youtube.com/watch?v=Qhn-lXjyrZA&feature=youtu.be) by [Yes! Let's Learn Software Engineering](https://www.youtube.com/channel/UCH4XJf2BZ_52fbf8fOBMF3w)
137 - ...
138 - Want to add your own? Open an Issue or create a PR :-)
139
140## Community Contributions
141See the [webhook-contrib][wc] repository for a collections of tools and helpers related to [webhook][w] that have been contributed by the [webhook][w] community.
142
143## Need help?
144Check out [existing issues](https://github.com/adnanh/webhook/issues) to see if someone else also had the same problem, or [open a new one](https://github.com/adnanh/webhook/issues/new).
145
146# Support active development
147
148## Sponsors
149## <a href="https://www.digitalocean.com/?ref=webhook"><img src="http://www.hajdarevic.net/DO_Logo_Horizontal_Blue.png" alt="DigitalOcean" width="250"/></a>
150[DigitalOcean](https://www.digitalocean.com/?ref=webhook) is a simple and robust cloud computing platform, designed for developers.
151
152
153## <a href="https://www.browserstack.com/?ref=webhook"><img src="http://www.hajdarevic.net/browserstack.svg" alt="BrowserStack" width="250"/></a>
154[BrowserStack](https://www.browserstack.com/?ref=webhook) is a cloud-based cross-browser testing tool that enables developers to test their websites across various browsers on different operating systems and mobile devices, without requiring users to install virtual machines, devices or emulators.
155
156---
157
158Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
159
160<a href="https://opencollective.com/webhook/sponsor/0/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/0/avatar.svg"></a>
161<a href="https://opencollective.com/webhook/sponsor/1/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/1/avatar.svg"></a>
162<a href="https://opencollective.com/webhook/sponsor/2/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/2/avatar.svg"></a>
163<a href="https://opencollective.com/webhook/sponsor/3/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/3/avatar.svg"></a>
164<a href="https://opencollective.com/webhook/sponsor/4/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/4/avatar.svg"></a>
165<a href="https://opencollective.com/webhook/sponsor/5/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/5/avatar.svg"></a>
166<a href="https://opencollective.com/webhook/sponsor/6/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/6/avatar.svg"></a>
167<a href="https://opencollective.com/webhook/sponsor/7/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/7/avatar.svg"></a>
168<a href="https://opencollective.com/webhook/sponsor/8/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/8/avatar.svg"></a>
169<a href="https://opencollective.com/webhook/sponsor/9/website" target="_blank"><img src="https://opencollective.com/webhook/sponsor/9/avatar.svg"></a>
170
171## By contributing
172
173This project exists thanks to all the people who contribute. [Contribute!](CONTRIBUTING.md).
174<a href="graphs/contributors"><img src="https://opencollective.com/webhook/contributors.svg?width=890" /></a>
175
176## By giving money
177
178 - [OpenCollective Backer](https://opencollective.com/webhook#backer)
179 - [OpenCollective Sponsor](https://opencollective.com/webhook#sponsor)
180 - [PayPal](https://paypal.me/hookdoo)
181 - [Patreon](https://www.patreon.com/webhook)
182 - [Faircode](https://faircode.io/product/webhook?utm_source=badge&utm_medium=badgelarge&utm_campaign=webhook)
183 - [Flattr](https://flattr.com/submit/auto?user_id=adnanh&url=https%3A%2F%2Fwww.github.com%2Fadnanh%2Fwebhook)
184
185---
186
187Thank you to all our backers!
188
189<a href="https://opencollective.com/webhook#backers" target="_blank"><img src="https://opencollective.com/webhook/backers.svg?width=890"></a>
190
191# License
192
193The MIT License (MIT)
194
195Copyright (c) 2015 Adnan Hajdarevic <adnanh@gmail.com>
196
197Permission is hereby granted, free of charge, to any person obtaining a copy
198of this software and associated documentation files (the "Software"), to deal
199in the Software without restriction, including without limitation the rights
200to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
201copies of the Software, and to permit persons to whom the Software is
202furnished to do so, subject to the following conditions:
203
204The above copyright notice and this permission notice shall be included in
205all copies or substantial portions of the Software.
206
207THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
208IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
209FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
210AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
211LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
212OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
213THE SOFTWARE.
214
215
216[w]: https://github.com/adnanh/webhook
217[wc]: https://github.com/adnanh/webhook-contrib
218[badge]: https://github.com/adnanh/webhook/workflows/build/badge.svg
219