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

minor

parent 9199b0e4
Branches
Tags
No related merge requests found
...@@ -31,6 +31,15 @@ func init() { ...@@ -31,6 +31,15 @@ func init() {
ErrorLogger = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime) ErrorLogger = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime)
} }
// write to 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 // serve certificates JSON
func renderJSON(w http.ResponseWriter, req *http.Request) { func renderJSON(w http.ResponseWriter, req *http.Request) {
provider := strings.Split(req.URL.Path, "/")[2] provider := strings.Split(req.URL.Path, "/")[2]
...@@ -69,21 +78,15 @@ func renderPage(w http.ResponseWriter, req *http.Request) { ...@@ -69,21 +78,15 @@ 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")
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"
fmt.Fprintf(w, "Welcome, "+authToken+"\r\n") writeFile(fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 200\n \"token\": %v}", authToken), "/tmp/200.json")
// create json files on the fly writeFile(fmt.Sprintf("{\n \"status\": \"KO\",\n \"response\": 503\n \"token\": %v}", authToken), "/tmp/503.json")
okMsg := []byte("{\n \"status\": \"OK\",\n \"response\": 200\n }") if authToken != bearerToken {
koMsg := []byte("{\n \"status\": \"KO\",\n \"response\": 503\n }")
okErr := os.WriteFile("/tmp/200.json", okMsg, 0644)
koErr := os.WriteFile("/tmp/503.json", koMsg, 0644)
if okErr != nil || koErr != nil {
statusFile = "/tmp/503.json"
w.WriteHeader(http.StatusUnauthorized)
} else if authToken != bearerToken {
statusFile = "/tmp/503.json" statusFile = "/tmp/503.json"
w.WriteHeader(http.StatusUnauthorized) //w.WriteHeader(http.StatusUnauthorized)
} else { } else {
cmd.Run() cmd.Run()
if verboseBool { if verboseBool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment