Compare commits

...

4 Commits

2 changed files with 26 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ install:
go build -o gohookr go build -o gohookr
cp gohookr /usr/local/bin/ cp gohookr /usr/local/bin/
cp gohookr.service /usr/lib/systemd/system/ cp gohookr.service /usr/lib/systemd/system/
cp config.json /etc/gohookr.json cp -n config.json /etc/gohookr.json
systemctl daemon-reload systemctl daemon-reload
systemctl enable --now gohookr 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 // Verify that signature provided matches signature calculated using secretsss
signature := r.Header.Get(service.SignatureHeader) 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("signature = %v\n", signature)
fmt.Printf("calcuatedSignature = %v\n", signature) fmt.Printf("calcuatedSignature = %v\n", calculatedSignature)
if signature != calculatedSignature && checkSignature { if signature != calculatedSignature && checkSignature {
writeResponse(w, 400, "Bad Request: Signatures do not match") writeResponse(w, 400, "Bad Request: Signatures do not match")
return return
} }
// run test and script in parralel to prevent timing out
go func(){
// Run tests, immediately stop if one fails // Run tests, immediately stop if one fails
for _, test := range service.Tests { for _, test := range service.Tests {
if _, err := test.Execute(payload); err != nil { if _, err := test.Execute(payload); err != nil {
@@ -80,14 +86,15 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
stdout, err := service.Script.Execute(payload)
if stdout, err := service.Script.Execute(payload); err != nil { fmt.Println(string(stdout))
writeResponse(w, 500, err.Error()) if err != nil {
return fmt.Println(err.Error())
} else {
writeResponse(w, 200, string(stdout))
return
} }
}()
writeResponse(w, 200, "OK")
return
} }
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) { func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {