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

fix missing token

parent b63bd303
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ func init() { ...@@ -32,6 +32,7 @@ func init() {
} }
// write file // write file
/*
func writeFile(fileContent string, filePath string) { func writeFile(fileContent string, filePath string) {
content := []byte(fileContent) content := []byte(fileContent)
err := os.WriteFile(filePath, content, 0644) err := os.WriteFile(filePath, content, 0644)
...@@ -39,6 +40,7 @@ func writeFile(fileContent string, filePath string) { ...@@ -39,6 +40,7 @@ func writeFile(fileContent string, filePath string) {
WarningLogger.Println(err) WarningLogger.Println(err)
} }
} }
*/
// serve certificates JSON // serve certificates JSON
func renderJSON(w http.ResponseWriter, req *http.Request) { func renderJSON(w http.ResponseWriter, req *http.Request) {
...@@ -79,12 +81,16 @@ func renderPage(w http.ResponseWriter, req *http.Request) { ...@@ -79,12 +81,16 @@ func renderPage(w http.ResponseWriter, req *http.Request) {
// trigger puppet // trigger puppet
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 := strings.Split(req.Header.Get("Authorization"), "Bearer ")[1] authToken := "BOFH"
statusFile := "/tmp/200.json" 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}") ok := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 200\n}")
ko := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 401\n}") ko := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 401\n}")
writeFile(ok, "/tmp/200.json") //writeFile(ok, "/tmp/200.json")
writeFile(ko, "/tmp/401.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, ko, http.StatusUnauthorized)
...@@ -93,7 +99,8 @@ func triggerPuppet(w http.ResponseWriter, req *http.Request) { ...@@ -93,7 +99,8 @@ 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)
} }
http.ServeFile(w, req, statusFile) //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