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

fix tokens

parent 5b557ee3
No related branches found
No related tags found
No related merge requests found
......@@ -31,17 +31,6 @@ func init() {
ErrorLogger = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime)
}
// write file
/*
func writeFile(fileContent string, filePath string) {
content := []byte(fileContent)
err := os.WriteFile(filePath, content, 0644)
if err != nil {
WarningLogger.Println(err)
}
}
*/
// serve certificates JSON
func renderJSON(w http.ResponseWriter, req *http.Request) {
provider := strings.Split(req.URL.Path, "/")[2]
......@@ -80,27 +69,29 @@ 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")
cmd := exec.Command("/usr/bin/pkill", "-f", "/opt/puppetlabs/puppet/bin/puppet", "--signal", "SIGUSR1")
authToken := "BOFH"
_, ok := req.Header["Authorization"]
if ok {
authToken = strings.Split(req.Header.Get("Authorization"), "Bearer ")[1]
}
okMsg := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 200\n}")
koMsg := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 401\n}")
unauthorizedMsg := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 401\n}")
unavailableMsg := fmt.Sprintln("{\n \"status\": \"OK\",\n \"response\": 503\n}")
w.Header().Set("Content-Type", "application/json")
if authToken != bearerToken {
http.Error(w, koMsg, http.StatusUnauthorized)
http.Error(w, unauthorizedMsg, http.StatusUnauthorized)
} else {
err := cmd.Run()
if err != nil {
WarningLogger.Println(err)
w.WriteHeader(http.StatusServiceUnavailable)
http.Error(w, unavailableMsg, http.StatusServiceUnavailable)
} else {
if verboseBool {
InfoLogger.Printf("HTTP Status %v", http.StatusOK)
}
http.Error(w, okMsg, http.StatusAccepted)
http.Error(w, okMsg, http.StatusOK)
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment