forked from aquasecurity/postee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
37 lines (31 loc) · 920 Bytes
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package uiserver
import (
"io/ioutil"
"log"
"net/http"
"os"
)
func (srv *uiServer) getEvents(w http.ResponseWriter, r *http.Request) {
log.Printf("configured config path %s", srv.cfgPath)
posteeUrl := os.Getenv("POSTEE_UI_UPDATE_URL")
if len(posteeUrl) <= 0 {
w.WriteHeader(http.StatusBadRequest)
log.Println("No Postee URL configured, set POSTEE_UI_UPDATE_URL to the Postee URL")
return
}
resp, err := http.Get(posteeUrl + "/events")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
log.Println("Unable to reach Postee at URL: " + posteeUrl + "/events" + " err: " + err.Error())
return
}
currentEvents, err := ioutil.ReadAll(resp.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
log.Println("Failed to read events: " + err.Error())
return
}
w.Header().Set("Content-Type", "text/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(currentEvents)
}