Compare commits

...

4 Commits

2 changed files with 26 additions and 19 deletions

View File

@ -8,7 +8,7 @@ install:
go build -o gohookr
cp gohookr /usr/local/bin/
cp gohookr.service /usr/lib/systemd/system/
cp config.json /etc/gohookr.json
cp -n config.json /etc/gohookr.json
systemctl daemon-reload
systemctl enable --now gohookr

25
main.go
View File

@ -63,14 +63,20 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
// Verify that signature provided matches signature calculated using secretsss
signature := r.Header.Get(service.SignatureHeader)
calculatedSignature := fmt.Sprintf("%v%v", service.SignaturePrefix, getSha256HMACSignature([]byte(service.Secret), payload))
calculatedSignature := fmt.Sprintf(
"%v%v",
service.SignaturePrefix,
getSha256HMACSignature([]byte(service.Secret), payload),
)
fmt.Printf("signature = %v\n", signature)
fmt.Printf("calcuatedSignature = %v\n", signature)
fmt.Printf("calcuatedSignature = %v\n", calculatedSignature)
if signature != calculatedSignature && checkSignature {
writeResponse(w, 400, "Bad Request: Signatures do not match")
return
}
// run test and script in parralel to prevent timing out
go func(){
// Run tests, immediately stop if one fails
for _, test := range service.Tests {
if _, err := test.Execute(payload); err != nil {
@ -80,14 +86,15 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
if stdout, err := service.Script.Execute(payload); err != nil {
writeResponse(w, 500, err.Error())
return
} else {
writeResponse(w, 200, string(stdout))
return
stdout, err := service.Script.Execute(payload)
fmt.Println(string(stdout))
if err != nil {
fmt.Println(err.Error())
}
}()
writeResponse(w, 200, "OK")
return
}
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {