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

fix missing toekn

parent d392e809
No related branches found
No related tags found
No related merge requests found
...@@ -82,25 +82,26 @@ func renderPage(w http.ResponseWriter, req *http.Request) { ...@@ -82,25 +82,26 @@ func renderPage(w http.ResponseWriter, req *http.Request) {
func triggerPuppet(w http.ResponseWriter, req *http.Request) { func triggerPuppet(w http.ResponseWriter, req *http.Request) {
cmd := exec.Command("/usr/bin/pkill", "-f", "/opt/puppetlabs/puppet/bin/puppet", "-s", "SIGUSR1") cmd := exec.Command("/usr/bin/pkill", "-f", "/opt/puppetlabs/puppet/bin/puppet", "-s", "SIGUSR1")
authToken := "BOFH" authToken := "BOFH"
if len(req.Header.Get("Authorization")) > 0 { _, ok := req.Header["Authorization"]
if ok {
authToken = strings.Split(req.Header.Get("Authorization"), "Bearer ")[1] authToken = strings.Split(req.Header.Get("Authorization"), "Bearer ")[1]
} }
okMsg := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 200\n}")
//statusFile := "/tmp/200.json" koMsg := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 401\n}")
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")
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if authToken != bearerToken { if authToken != bearerToken {
http.Error(w, ko, http.StatusUnauthorized) http.Error(w, koMsg, http.StatusUnauthorized)
} else { } else {
cmd.Run() err := cmd.Run()
if verboseBool { if err != nil {
InfoLogger.Printf("HTTP Status %v", http.StatusOK) WarningLogger.Println(err)
w.WriteHeader(http.StatusServiceUnavailable)
} else {
if verboseBool {
InfoLogger.Printf("HTTP Status %v", http.StatusOK)
}
http.Error(w, okMsg, http.StatusAccepted)
} }
//http.ServeFile(w, req, statusFile)
http.Error(w, ok, http.StatusAccepted)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment