log the SHA1 of the received payload

This commit is contained in:
Stefan Prodan
2018-02-11 15:42:37 +02:00
parent 4f7aa3cff8
commit 8be417a4a1
2 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ Web API:
* `POST /readyz/enable` signals the Kubernetes LB that this instance is ready to receive traffic
* `POST /readyz/disable` signals the Kubernetes LB to stop sending requests to this instance
* `GET /panic` crashes the process with exit code 255
* `POST /echo` echos the posted content
* `POST /echo` echos the posted content, logs the SHA1 hash of the content
* `POST /job` long running job, json body: `{"wait":2}`
* `POST /backend` forwards the call to the backend service on `http://backend-podinfo:9898/echo`
+9 -1
View File
@@ -12,6 +12,8 @@ import (
"time"
"os"
"bytes"
"crypto/sha1"
"fmt"
)
func (s *Server) index(w http.ResponseWriter, r *http.Request) {
@@ -49,7 +51,8 @@ func (s *Server) echo(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(err.Error()))
return
}
glog.Infof("Payload received from %s: %s", r.RemoteAddr, string(body))
sha1 := hash(string(body))
glog.Infof("Payload received from %s hash %s", r.RemoteAddr, sha1)
w.WriteHeader(http.StatusAccepted)
w.Write(body)
default:
@@ -184,3 +187,8 @@ func (s *Server) disable(w http.ResponseWriter, r *http.Request) {
func (s *Server) panic(w http.ResponseWriter, r *http.Request) {
glog.Fatal("Kill switch triggered")
}
func hash(input string) string {
h := sha1.New()
return fmt.Sprintf("%x", h.Sum([]byte(input)))
}