diff --git a/main.go b/main.go index c9508d10b4c7faafe56d8d4e7f325ca9acab8538..e1ba79ee98b48e69f07e3d82d684115904009a09 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ func init() { } // write file +/* func writeFile(fileContent string, filePath string) { content := []byte(fileContent) err := os.WriteFile(filePath, content, 0644) @@ -39,6 +40,7 @@ func writeFile(fileContent string, filePath string) { WarningLogger.Println(err) } } +*/ // serve certificates JSON func renderJSON(w http.ResponseWriter, req *http.Request) { @@ -79,12 +81,16 @@ func renderPage(w http.ResponseWriter, req *http.Request) { // trigger puppet func triggerPuppet(w http.ResponseWriter, req *http.Request) { cmd := exec.Command("/usr/bin/pkill", "-f", "/opt/puppetlabs/puppet/bin/puppet", "-s", "SIGUSR1") - authToken := strings.Split(req.Header.Get("Authorization"), "Bearer ")[1] - statusFile := "/tmp/200.json" + authToken := "BOFH" + if len(req.Header.Get("Authorization")) > 0 { + authToken = strings.Split(req.Header.Get("Authorization"), "Bearer ")[1] + } + + //statusFile := "/tmp/200.json" ok := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 200\n}") ko := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 401\n}") - writeFile(ok, "/tmp/200.json") - writeFile(ko, "/tmp/401.json") + //writeFile(ok, "/tmp/200.json") + //writeFile(ko, "/tmp/401.json") w.Header().Set("Content-Type", "application/json") if authToken != bearerToken { http.Error(w, ko, http.StatusUnauthorized) @@ -93,7 +99,8 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) { if verboseBool { InfoLogger.Printf("HTTP Status %v", http.StatusOK) } - http.ServeFile(w, req, statusFile) + //http.ServeFile(w, req, statusFile) + http.Error(w, ok, http.StatusAccepted) } }