Updated with a Gitea example

This commit is contained in:
ruliezz 2018-11-16 15:23:39 +01:00 committed by GitHub
parent b2899d1d3e
commit ce7f8d5d28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,296 +1,351 @@
# Hook examples # Hook examples
This page is still work in progress. Feel free to contribute! This page is still work in progress. Feel free to contribute!
## Incoming Github webhook ## Incoming Github webhook
```json ```json
[ [
{ {
"id": "webhook", "id": "webhook",
"execute-command": "/home/adnan/redeploy-go-webhook.sh", "execute-command": "/home/adnan/redeploy-go-webhook.sh",
"command-working-directory": "/home/adnan/go", "command-working-directory": "/home/adnan/go",
"pass-arguments-to-command": "pass-arguments-to-command":
[ [
{ {
"source": "payload", "source": "payload",
"name": "head_commit.id" "name": "head_commit.id"
}, },
{ {
"source": "payload", "source": "payload",
"name": "pusher.name" "name": "pusher.name"
}, },
{ {
"source": "payload", "source": "payload",
"name": "pusher.email" "name": "pusher.email"
} }
], ],
"trigger-rule": "trigger-rule":
{ {
"and": "and":
[ [
{ {
"match": "match":
{ {
"type": "payload-hash-sha1", "type": "payload-hash-sha1",
"secret": "mysecret", "secret": "mysecret",
"parameter": "parameter":
{ {
"source": "header", "source": "header",
"name": "X-Hub-Signature" "name": "X-Hub-Signature"
} }
} }
}, },
{ {
"match": "match":
{ {
"type": "value", "type": "value",
"value": "refs/heads/master", "value": "refs/heads/master",
"parameter": "parameter":
{ {
"source": "payload", "source": "payload",
"name": "ref" "name": "ref"
} }
} }
} }
] ]
} }
} }
] ]
``` ```
## Incoming Bitbucket webhook ## Incoming Bitbucket webhook
Bitbucket does not pass any secrets back to the webhook. [Per their documentation](https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html#Managewebhooks-trigger_webhookTriggeringwebhooks), in order to verify that the webhook came from Bitbucket you must whitelist the IP range `104.192.143.0/24`: Bitbucket does not pass any secrets back to the webhook. [Per their documentation](https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html#Managewebhooks-trigger_webhookTriggeringwebhooks), in order to verify that the webhook came from Bitbucket you must whitelist the IP range `104.192.143.0/24`:
```json ```json
[ [
{ {
"id": "webhook", "id": "webhook",
"execute-command": "/home/adnan/redeploy-go-webhook.sh", "execute-command": "/home/adnan/redeploy-go-webhook.sh",
"command-working-directory": "/home/adnan/go", "command-working-directory": "/home/adnan/go",
"pass-arguments-to-command": "pass-arguments-to-command":
[ [
{ {
"source": "payload", "source": "payload",
"name": "actor.username" "name": "actor.username"
} }
], ],
"trigger-rule": "trigger-rule":
{ {
"match": "match":
{ {
"type": "ip-whitelist", "type": "ip-whitelist",
"ip-range": "104.192.143.0/24" "ip-range": "104.192.143.0/24"
} }
} }
} }
] ]
``` ```
## Incoming Gitlab Webhook ## Incoming Gitlab Webhook
Gitlab provides webhooks for many kinds of events. Gitlab provides webhooks for many kinds of events.
Refer to this URL for example request body content: [gitlab-ce/integrations/webhooks](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/user/project/integrations/webhooks.md) Refer to this URL for example request body content: [gitlab-ce/integrations/webhooks](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/user/project/integrations/webhooks.md)
Values in the request body can be accessed in the command or to the match rule by referencing 'payload' as the source: Values in the request body can be accessed in the command or to the match rule by referencing 'payload' as the source:
```json ```json
[ [
{ {
"id": "redeploy-webhook", "id": "redeploy-webhook",
"execute-command": "/home/adnan/redeploy-go-webhook.sh", "execute-command": "/home/adnan/redeploy-go-webhook.sh",
"command-working-directory": "/home/adnan/go", "command-working-directory": "/home/adnan/go",
"pass-arguments-to-command": "pass-arguments-to-command":
[ [
{ {
"source": "payload", "source": "payload",
"name": "user_name" "name": "user_name"
} }
], ],
"response-message": "Executing redeploy script", "response-message": "Executing redeploy script",
"trigger-rule": "trigger-rule":
{ {
"match": "match":
{ {
"type": "value", "type": "value",
"value": "<YOUR-GENERATED-TOKEN>", "value": "<YOUR-GENERATED-TOKEN>",
"parameter": "parameter":
{ {
"source": "header", "source": "header",
"name": "X-Gitlab-Token" "name": "X-Gitlab-Token"
} }
} }
} }
} }
] ]
``` ```
## Incoming Gogs webhook ## Incoming Gogs webhook
```json ```json
[ [
{ {
"id": "webhook", "id": "webhook",
"execute-command": "/home/adnan/redeploy-go-webhook.sh", "execute-command": "/home/adnan/redeploy-go-webhook.sh",
"command-working-directory": "/home/adnan/go", "command-working-directory": "/home/adnan/go",
"pass-arguments-to-command": "pass-arguments-to-command":
[ [
{ {
"source": "payload", "source": "payload",
"name": "head_commit.id" "name": "head_commit.id"
}, },
{ {
"source": "payload", "source": "payload",
"name": "pusher.name" "name": "pusher.name"
}, },
{ {
"source": "payload", "source": "payload",
"name": "pusher.email" "name": "pusher.email"
} }
], ],
"trigger-rule": "trigger-rule":
{ {
"and": "and":
[ [
{ {
"match": "match":
{ {
"type": "payload-hash-sha256", "type": "payload-hash-sha256",
"secret": "mysecret", "secret": "mysecret",
"parameter": "parameter":
{ {
"source": "header", "source": "header",
"name": "X-Gogs-Signature" "name": "X-Gogs-Signature"
} }
} }
}, },
{ {
"match": "match":
{ {
"type": "value", "type": "value",
"value": "refs/heads/master", "value": "refs/heads/master",
"parameter": "parameter":
{ {
"source": "payload", "source": "payload",
"name": "ref" "name": "ref"
} }
} }
} }
] ]
} }
} }
] ]
``` ```
## Incoming Gitea webhook
## Slack slash command ```json
```json [
[ {
{ "id": "webhook",
"id": "redeploy-webhook", "execute-command": "/home/adnan/redeploy-go-webhook.sh",
"execute-command": "/home/adnan/redeploy-go-webhook.sh", "command-working-directory": "/home/adnan/go",
"command-working-directory": "/home/adnan/go", "pass-arguments-to-command":
"response-message": "Executing redeploy script", [
"trigger-rule": {
{ "source": "payload",
"match": "name": "head_commit.id"
{ },
"type": "value", {
"value": "<YOUR-GENERATED-TOKEN>", "source": "payload",
"parameter": "name": "pusher.name"
{ },
"source": "payload", {
"name": "token" "source": "payload",
} "name": "pusher.email"
} }
} ],
} "trigger-rule":
] {
``` "and":
[
## A simple webhook with a secret key in GET query {
"match":
__Not recommended in production due to low security__ {
"type": "value",
`example.com:9000/hooks/simple-one` - won't work "value": "mysecret",
`example.com:9000/hooks/simple-one?token=42` - will work "parameter":
{
```json "source": "payload",
[ "name": "secret"
{ }
"id": "simple-one", }
"execute-command": "/path/to/command.sh", },
"response-message": "Executing simple webhook...", {
"trigger-rule": "match":
{ {
"match": "type": "value",
{ "value": "refs/heads/master",
"type": "value", "parameter":
"value": "42", {
"parameter": "source": "payload",
{ "name": "ref"
"source": "url", }
"name": "token" }
} }
} ]
} }
} }
] ]
``` ```
# JIRA Webhooks ## Slack slash command
[Guide by @perfecto25](https://sites.google.com/site/mrxpalmeiras/notes/jira-webhooks) ```json
[
# Pass File-to-command sample {
"id": "redeploy-webhook",
## Webhook configuration "execute-command": "/home/adnan/redeploy-go-webhook.sh",
"command-working-directory": "/home/adnan/go",
<pre> "response-message": "Executing redeploy script",
[ "trigger-rule":
{ {
"id": "test-file-webhook", "match":
"execute-command": "/bin/ls", {
"command-working-directory": "/tmp", "type": "value",
"pass-file-to-command": "value": "<YOUR-GENERATED-TOKEN>",
[ "parameter":
{ {
"source": "payload", "source": "payload",
"name": "binary", "name": "token"
"envname": "ENV_VARIABLE", // to use $ENV_VARIABLE in execute-command }
// if not defined, $HOOK_BINARY will be provided }
"base64decode": true, // defaults to false }
} }
], ]
"include-command-output-in-response": true ```
}
] ## A simple webhook with a secret key in GET query
</pre>
__Not recommended in production due to low security__
## Sample client usage
`example.com:9000/hooks/simple-one` - won't work
Store the following file as `testRequest.json`. `example.com:9000/hooks/simple-one?token=42` - will work
<pre> ```json
{"binary":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2lpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU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eNqkk89rE1EQx2d/NNq0xcYYayPYJDWC9ODBsKIgAREjBmvEg2cvHnr05KHQ9iB49SL+/BMEfxBQKHgwCEbTNNIYaqgaoanFJi+rcXezye4689jYkIMIDnx47837zrx583YFx3Hgf0xA6/dJyAkkgUy4vgryAnmNWH9L4EVmotFoKplMHgoGg6PkrFarjXQ6/bFcLj/G5W1E+3NaX4KZeDx+dX5+7kg4HBlmrC6JoiDFYrGhROLM/mp1Y6JSqdCd3/SW0GUqEAjkl5ZyHTSHKBQKnO6a9khD2m5cr91IJBJ1VVWdiM/n6LruNJtNDs3JR3ukIW03SHTHi8iVsbG9I51OG1bW16HVasHQZopDc/JZVgdIQ1o3BmTkEnJXURS/KIpgGAYPkCQJPi0u8uzDKQN0XQPbtgE1MmrHs9nsfSqAEjxCNtHxZHLy4G4smUQgyzL4LzOegDGGp1ucVqsNqKVrpJCM7F4hg6iaZvhqtZrg8XjA4xnAU3XeKLqWaRImoIZeQXVjQO5pYp4xNVirsR1erxer2O4yfa227WCwhtWoJmn7m0h270NxmemFW4706zMm8GCgxBGEASCfhnukIW03iFdQnOPz0LNKp3362JqQzSw4u2LXBe+Bs3xD+/oc1NxN55RiC9fOme0LEQiRf2rBzaKEeJJ37ZWTVunBeGN2WmQjg/DeLTVP89nzAive2dMwlo9bpFVC2xWMZr+A720FVn88fAUb3wDMOjyN7YNc6TvUSHQ4AH6TOUdLL7em68UtWPsJqxgTpgeiLu1EBt1R+Me/mF7CQPTfAgwAGxY2vOTrR3oAAAAASUVORK5CYII="} [
</pre> {
"id": "simple-one",
use then the curl tool to execute a request to the webhook. "execute-command": "/path/to/command.sh",
"response-message": "Executing simple webhook...",
<pre> "trigger-rule":
#!/bin/bash {
curl -H "Content-Type:application/json" -X POST -d @testRequest.json \ "match":
http://localhost:9000/hooks/test-file-webhook {
</pre> "type": "value",
"value": "42",
or in a single line, using https://github.com/jpmens/jo to generate the JSON code "parameter":
<pre> {
jo binary=%filename.zip | curl -H "Content-Type:application/json" -X POST -d @- \ "source": "url",
http://localhost:9000/hooks/test-file-webhook "name": "token"
</pre> }
}
}
## Incoming Scalr Webhook }
[Guide by @hassanbabaie] ]
Scalr makes webhook calls based on an event to a configured webhook endpoint (for example Host Down, Host Up). Webhook endpoints are URLs where Scalr will deliver Webhook notifications. ```
Scalr assigns a unique signing key for every configured webhook endpoint.
Refer to this URL for information on how to setup the webhook call on the Scalr side: [Scalr Wiki Webhooks](https://scalr-wiki.atlassian.net/wiki/spaces/docs/pages/6193173/Webhooks) # JIRA Webhooks
In order to leverage the Signing Key for addtional authentication/security you must configure the trigger rule with a match type of "scalr-signature". [Guide by @perfecto25](https://sites.google.com/site/mrxpalmeiras/notes/jira-webhooks)
```json # Pass File-to-command sample
## Webhook configuration
<pre>
[
{
"id": "test-file-webhook",
"execute-command": "/bin/ls",
"command-working-directory": "/tmp",
"pass-file-to-command":
[
{
"source": "payload",
"name": "binary",
"envname": "ENV_VARIABLE", // to use $ENV_VARIABLE in execute-command
// if not defined, $HOOK_BINARY will be provided
"base64decode": true, // defaults to false
}
],
"include-command-output-in-response": true
}
]
</pre>
## Sample client usage
Store the following file as `testRequest.json`.
<pre>
{"binary":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2lpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4g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X4KZeDx+dX5+7kg4HBlmrC6JoiDFYrGhROLM/mp1Y6JSqdCd3/SW0GUqEAjkl5ZyHTSHKBQKnO6a9khD2m5cr91IJBJ1VVWdiM/n6LruNJtNDs3JR3ukIW03SHTHi8iVsbG9I51OG1bW16HVasHQZopDc/JZVgdIQ1o3BmTkEnJXURS/KIpgGAYPkCQJPi0u8uzDKQN0XQPbtgE1MmrHs9nsfSqAEjxCNtHxZHLy4G4smUQgyzL4LzOegDGGp1ucVqsNqKVrpJCM7F4hg6iaZvhqtZrg8XjA4xnAU3XeKLqWaRImoIZeQXVjQO5pYp4xNVirsR1erxer2O4yfa227WCwhtWoJmn7m0h270NxmemFW4706zMm8GCgxBGEASCfhnukIW03iFdQnOPz0LNKp3362JqQzSw4u2LXBe+Bs3xD+/oc1NxN55RiC9fOme0LEQiRf2rBzaKEeJJ37ZWTVunBeGN2WmQjg/DeLTVP89nzAive2dMwlo9bpFVC2xWMZr+A720FVn88fAUb3wDMOjyN7YNc6TvUSHQ4AH6TOUdLL7em68UtWPsJqxgTpgeiLu1EBt1R+Me/mF7CQPTfAgwAGxY2vOTrR3oAAAAASUVORK5CYII="}
</pre>
use then the curl tool to execute a request to the webhook.
<pre>
#!/bin/bash
curl -H "Content-Type:application/json" -X POST -d @testRequest.json \
http://localhost:9000/hooks/test-file-webhook
</pre>
or in a single line, using https://github.com/jpmens/jo to generate the JSON code
<pre>
jo binary=%filename.zip | curl -H "Content-Type:application/json" -X POST -d @- \
http://localhost:9000/hooks/test-file-webhook
</pre>
## Incoming Scalr Webhook
[Guide by @hassanbabaie]
Scalr makes webhook calls based on an event to a configured webhook endpoint (for example Host Down, Host Up). Webhook endpoints are URLs where Scalr will deliver Webhook notifications.
Scalr assigns a unique signing key for every configured webhook endpoint.
Refer to this URL for information on how to setup the webhook call on the Scalr side: [Scalr Wiki Webhooks](https://scalr-wiki.atlassian.net/wiki/spaces/docs/pages/6193173/Webhooks)
In order to leverage the Signing Key for addtional authentication/security you must configure the trigger rule with a match type of "scalr-signature".
```json
[ [
{ {
"id": "redeploy-webhook", "id": "redeploy-webhook",
@ -319,6 +374,6 @@ In order to leverage the Signing Key for addtional authentication/security you m
} }
] ]
} }
] ]
``` ```