-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.61 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
yaml "gopkg.in/yaml.v2"
"github.com/tparker00/Vision/events"
v "github.com/tparker00/Vision/types"
"github.com/labstack/echo"
)
func getEvents(c echo.Context) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
config := getConfig()
vmList, err := events.GetEvents(ctx, config)
if err != nil {
fmt.Printf("Error: %s", err)
return c.JSON(http.StatusInternalServerError, err)
}
response := v.Message{Status: "OK", Message: vmList}
return c.JSON(http.StatusOK, response)
}
func getTestEvents(c echo.Context) error {
vmList := []string{"ORGID001-VM0001", "ORG002-VM0001", "ORG003-VM0001", "ORG001-VM0001", "ORG002-VM0021", "ORG012-VM0101"}
fmt.Println(vmList)
var orgIDS []string
for _, l := range vmList {
orgID := strings.Split(l, "-")[0]
if events.Contains(orgIDS, orgID) {
fmt.Printf("OrgID %s already in the list, skipping\n", orgID)
} else {
orgIDS = append(orgIDS, orgID)
}
}
response := v.Message{Status: "OK", Message: orgIDS}
return c.JSON(http.StatusOK, response)
}
func getConfig() v.Config {
filename := "./vision.yaml"
var config v.Config
source, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println("Unable to load configuration file")
os.Exit(1)
}
err = yaml.Unmarshal(source, &config)
if err != nil {
panic(err)
}
return config
}
func main() {
e := echo.New()
e.GET("/haReport", getEvents)
e.GET("/haTest", getTestEvents)
e.GET("/", func(c echo.Context) error { return c.JSON(http.StatusNotImplemented, "Not Implemented") })
e.Start(":8000")
}