From a191cfdc41227daf6d2c87571baeef81ed2b2240 Mon Sep 17 00:00:00 2001
From: Massimiliano Adamo <maxadamo@gmail.com>
Date: Thu, 1 Sep 2022 00:25:48 +0200
Subject: [PATCH] test

---
 main.go | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go
index 2d41f27..eb11d05 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)
 	}
 }
-- 
GitLab