mirror of
https://github.com/alvierahman90/gohookr.git
synced 2025-01-26 10:03:24 +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
|
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
|
||||||
|
|
||||||
|
43
main.go
43
main.go
@ -63,31 +63,38 @@ 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(
|
||||||
fmt.Printf("signature = %v\n", signature)
|
"%v%v",
|
||||||
fmt.Printf("calcuatedSignature = %v\n", signature)
|
service.SignaturePrefix,
|
||||||
|
getSha256HMACSignature([]byte(service.Secret), payload),
|
||||||
|
)
|
||||||
|
fmt.Printf("signature = %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 tests, immediately stop if one fails
|
// run test and script in parralel to prevent timing out
|
||||||
for _, test := range service.Tests {
|
go func(){
|
||||||
if _, err := test.Execute(payload); err != nil {
|
// Run tests, immediately stop if one fails
|
||||||
writeResponse(w, 409,
|
for _, test := range service.Tests {
|
||||||
fmt.Sprintf("Conflict: Test failed: %v", err.Error()),
|
if _, err := test.Execute(payload); err != nil {
|
||||||
)
|
writeResponse(w, 409,
|
||||||
return
|
fmt.Sprintf("Conflict: Test failed: %v", err.Error()),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
stdout, err := service.Script.Execute(payload)
|
||||||
|
fmt.Println(string(stdout))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if stdout, err := service.Script.Execute(payload); err != nil {
|
writeResponse(w, 200, "OK")
|
||||||
writeResponse(w, 500, err.Error())
|
return
|
||||||
return
|
|
||||||
} else {
|
|
||||||
writeResponse(w, 200, string(stdout))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {
|
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user