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

minor

parent 9199b0e4
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,15 @@ func init() {
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
func renderJSON(w http.ResponseWriter, req *http.Request) {
provider := strings.Split(req.URL.Path, "/")[2]
......@@ -69,21 +78,15 @@ 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", "-s", "SIGUSR1")
cmd := exec.Command("/usr/bin/touch", "/TEST")
authToken := strings.Split(req.Header.Get("Authorization"), "Bearer ")[1]
statusFile := "/tmp/200.json"
fmt.Fprintf(w, "Welcome, "+authToken+"\r\n")
// create json files on the fly
okMsg := []byte("{\n \"status\": \"OK\",\n \"response\": 200\n }")
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 {
writeFile(fmt.Sprintf("{\n \"status\": \"OK\",\n \"response\": 200\n \"token\": %v}", authToken), "/tmp/200.json")
writeFile(fmt.Sprintf("{\n \"status\": \"KO\",\n \"response\": 503\n \"token\": %v}", authToken), "/tmp/503.json")
if authToken != bearerToken {
statusFile = "/tmp/503.json"
w.WriteHeader(http.StatusUnauthorized)
//w.WriteHeader(http.StatusUnauthorized)
} else {
cmd.Run()
if verboseBool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment