mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-08-23 22:26:29 +00:00
log the SHA1 of the received payload
This commit is contained in:
@@ -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`
|
||||
|
||||
|
||||
@@ -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)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user