diff --git a/main.go b/main.go index 2d41f277977fc11731201f1bc3068110474f2e94..eb11d050760a532310cdc48c2613718337f316dd 100644 --- a/main.go +++ b/main.go @@ -82,12 +82,15 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) { cmd := exec.Command("/usr/bin/touch", "/TEST") authToken := strings.Split(req.Header.Get("Authorization"), "Bearer ")[1] statusFile := "/tmp/200.json" - writeFile(fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 200\n \"token\": %v\n}", authToken), "/tmp/200.json") - writeFile(fmt.Sprintf("{\n \"status\": \"KO\",\n \"response\": 401\n \"token\": %v\n}", authToken), "/tmp/503.json") + ok := fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 200\n \"token\": %v\n}", authToken) + ko := fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 401\n \"token\": %v\n}", authToken) + writeFile(ok, "/tmp/200.json") + writeFile(ko, "/tmp/503.json") + w.Header().Set("Content-Type", "application/json") if authToken != bearerToken { statusFile = "/tmp/401.json" //w.WriteHeader(http.StatusUnauthorized) - http.Error(w, "unauthorized access", http.StatusUnauthorized) + http.Error(w, ko, http.StatusUnauthorized) http.ServeFile(w, req, "/tmp/401.json") //http.ServeFile(w, req, statusFile) } else { @@ -95,7 +98,6 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) { if verboseBool { InfoLogger.Printf("HTTP Status %v", http.StatusOK) } - w.Header().Set("Content-Type", "application/json") http.ServeFile(w, req, statusFile) } }