mirror of
https://github.com/alvierahman90/gohookr.git
synced 2025-01-12 11:54:20 +00:00
Compare commits
4 Commits
6cacc65013
...
5ab36c57ef
Author | SHA1 | Date | |
---|---|---|---|
5ab36c57ef | |||
a3ded5a052 | |||
081aaee9c7 | |||
0953baae50 |
2
Makefile
2
Makefile
@ -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
25
main.go
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user