Skip to content
Snippets Groups Projects
Unverified Commit a191cfdc authored by Max Adamo's avatar Max Adamo
Browse files

test

parent 0f13447d
Branches
Tags
No related merge requests found
...@@ -82,12 +82,15 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) { ...@@ -82,12 +82,15 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) {
cmd := exec.Command("/usr/bin/touch", "/TEST") cmd := exec.Command("/usr/bin/touch", "/TEST")
authToken := strings.Split(req.Header.Get("Authorization"), "Bearer ")[1] authToken := strings.Split(req.Header.Get("Authorization"), "Bearer ")[1]
statusFile := "/tmp/200.json" statusFile := "/tmp/200.json"
writeFile(fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 200\n \"token\": %v\n}", authToken), "/tmp/200.json") ok := fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 200\n \"token\": %v\n}", authToken)
writeFile(fmt.Sprintf("{\n \"status\": \"KO\",\n \"response\": 401\n \"token\": %v\n}", authToken), "/tmp/503.json") 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 { if authToken != bearerToken {
statusFile = "/tmp/401.json" statusFile = "/tmp/401.json"
//w.WriteHeader(http.StatusUnauthorized) //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, "/tmp/401.json")
//http.ServeFile(w, req, statusFile) //http.ServeFile(w, req, statusFile)
} else { } else {
...@@ -95,7 +98,6 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) { ...@@ -95,7 +98,6 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) {
if verboseBool { if verboseBool {
InfoLogger.Printf("HTTP Status %v", http.StatusOK) InfoLogger.Printf("HTTP Status %v", http.StatusOK)
} }
w.Header().Set("Content-Type", "application/json")
http.ServeFile(w, req, statusFile) http.ServeFile(w, req, statusFile)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment