Compare commits

...

7 Commits

Author SHA1 Message Date
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 Hajdarević 37b310feaa Merge pull request #4 from adnanh/development
added support for https
2015-03-14 13:06:14 +01:00
Adnan Hajdarevic ad76b51e6a updated minor version to 2.2.0 2015-03-14 13:04:28 +01:00
Adnan Hajdarevic 4304aaa2d5 readme update 2015-03-14 13:03:51 +01:00
Adnan Hajdarevic a2fac2373b updated readme to include https 2015-03-14 13:02:41 +01:00
Adnan Hajdarevic c9adceb5d8 added support for https 2015-03-14 12:59:54 +01:00
3 changed files with 35 additions and 11 deletions
+3
View File
@@ -53,6 +53,9 @@ By performing a simple HTTP GET or POST request to that endpoint, your specified
However, 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](https://github.com/adnanh/webhook/wiki/Hook-Rules) for detailed list of available rules and their usage. However, 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](https://github.com/adnanh/webhook/wiki/Hook-Rules) for detailed list of available rules and their usage.
# Using HTTPS
[webhook](https://github.com/adnanh/webhook/) by default serves hooks using http. If you want [webhook](https://github.com/adnanh/webhook/) to serve secure content using https, you can use the `-secure` flag while starting [webhook](https://github.com/adnanh/webhook/). 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.
# Examples # Examples
Check out [Hook examples page](https://github.com/adnanh/webhook/wiki/Hook-Examples) for more complex examples of hooks. Check out [Hook examples page](https://github.com/adnanh/webhook/wiki/Hook-Examples) for more complex examples of hooks.
+1
View File
@@ -49,6 +49,7 @@ type Hook struct {
ID string `json:"id"` ID string `json:"id"`
ExecuteCommand string `json:"execute-command"` ExecuteCommand string `json:"execute-command"`
CommandWorkingDirectory string `json:"command-working-directory"` CommandWorkingDirectory string `json:"command-working-directory"`
ResponseMessage string `json:"response-message"`
PassArgumentsToCommand []Argument `json:"pass-arguments-to-command"` PassArgumentsToCommand []Argument `json:"pass-arguments-to-command"`
TriggerRule *Rules `json:"trigger-rule"` TriggerRule *Rules `json:"trigger-rule"`
} }
+25 -5
View File
@@ -22,7 +22,7 @@ import (
) )
const ( const (
version = "2.1.0" version = "2.2.2"
) )
var ( var (
@@ -31,6 +31,10 @@ var (
verbose = flag.Bool("verbose", false, "show verbose output") verbose = flag.Bool("verbose", false, "show verbose output")
hotReload = flag.Bool("hotreload", false, "watch hooks file for changes and reload them automatically") hotReload = flag.Bool("hotreload", false, "watch hooks file for changes and reload them automatically")
hooksFilePath = flag.String("hooks", "hooks.json", "path to the json file containing defined hooks the webhook should serve") hooksFilePath = flag.String("hooks", "hooks.json", "path to the json file containing defined hooks the webhook should serve")
hooksURLPrefix = flag.String("urlprefix", "hooks", "url prefix to use for served hooks (protocol://yourserver:port/PREFIX/:hook-id)")
secure = flag.Bool("secure", false, "use HTTPS instead of HTTP")
cert = flag.String("cert", "cert.pem", "path to the HTTPS certificate pem file")
key = flag.String("key", "key.pem", "path to the HTTPS certificate private key pem file")
watcher *fsnotify.Watcher watcher *fsnotify.Watcher
@@ -103,14 +107,29 @@ func main() {
n := negroni.New(negroniRecovery, negroniLogger) n := negroni.New(negroniRecovery, negroniLogger)
router := mux.NewRouter() router := mux.NewRouter()
router.HandleFunc("/hooks/{id}", hookHandler)
var hooksURL string
if *hooksURLPrefix == "" {
hooksURL = "/{id}"
} else {
hooksURL = "/" + *hooksURLPrefix + "/{id}"
}
router.HandleFunc(hooksURL, hookHandler)
n.UseHandler(router) n.UseHandler(router)
log.Printf("listening on %s:%d", *ip, *port) if *secure {
log.Printf("starting secure (https) webhook on %s:%d", *ip, *port)
log.Fatal(http.ListenAndServeTLS(fmt.Sprintf("%s:%d", *ip, *port), *cert, *key, n))
} else {
log.Printf("starting insecure (http) webhook on %s:%d", *ip, *port)
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *ip, *port), n)) log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *ip, *port), n))
} }
}
func hookHandler(w http.ResponseWriter, r *http.Request) { func hookHandler(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"] id := mux.Vars(r)["id"]
@@ -156,9 +175,10 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
// handle hook // handle hook
go handleHook(hook, &headers, &query, &payload, &body) go handleHook(hook, &headers, &query, &payload, &body)
// say thanks // send the hook defined response message
fmt.Fprintf(w, "Thanks.") fmt.Fprintf(w, hook.ResponseMessage)
} else { } else {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "Hook not found.") fmt.Fprintf(w, "Hook not found.")
} }
} }