From 47a5b0659cdafdac60cb6b2319a4485ef9d6fddd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 24 May 2019 02:33:19 +0000 Subject: [PATCH] recieve the token Signed-off-by: Jeff Carr --- gorilla-server/main.go | 9 ++++++++- gorilla-server/stack-client.go | 24 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gorilla-server/main.go b/gorilla-server/main.go index f74cd3d..e7a61bf 100644 --- a/gorilla-server/main.go +++ b/gorilla-server/main.go @@ -22,6 +22,7 @@ var upgrader = websocket.Upgrader{ }, } +/* func sendSampleProtobuf(conn *websocket.Conn) { msg := pb.CreateSampleEvent() msg.Name = "test echo over gorilla websocket" @@ -31,6 +32,7 @@ func sendSampleProtobuf(conn *websocket.Conn) { log.Println("sendProtobuf() write:", err) } } +*/ func sendProtobuf(conn *websocket.Conn, msg *pb.Event) { data, _ := proto.Marshal(msg) @@ -70,7 +72,12 @@ func eventHandler(w http.ResponseWriter, r *http.Request) { log.Printf("recv binary: %s", pdata) if pdata.Type == pb.Event_MIGRATE { log.Printf("GOT MIGRATE") - e := oldmain() + e := processGetEvent(pdata) + sendProtobuf(conn, e) + } + if pdata.Type == pb.Event_GET { + log.Printf("GOT GET") + e := processGetEvent(pdata) sendProtobuf(conn, e) } } diff --git a/gorilla-server/stack-client.go b/gorilla-server/stack-client.go index 232f37b..06130b4 100644 --- a/gorilla-server/stack-client.go +++ b/gorilla-server/stack-client.go @@ -21,11 +21,11 @@ type network struct { Subdomain string `json:"subdomain"` } -func fetchNetworks() []network { +func fetchNetworks(token string) []network { var networks []network req, err := http.NewRequest("GET", API + "clusters", nil) if err != nil { log.Fatal("can't make new req") } - req.Header.Set("X-Wit-Auth", JWT) + req.Header.Set("X-Wit-Auth", token) client := &http.Client{} resp, err := client.Do(req) if err != nil { log.Printf("Can't exec the req to list networks: %s", err) } @@ -35,8 +35,13 @@ func fetchNetworks() []network { if body == nil { log.Println("networks is nil") } else { + len := len(body) err = json.Unmarshal(body, &networks) - if err != nil { log.Fatal("can't unmarshal resp for list networks: %s", err) } + if err != nil { + log.Println("body = ", body) + log.Println("body len = ", len) + log.Println("can't unmarshal resp for list networks: %s", err) + } } spew.Dump(networks) return networks @@ -71,11 +76,11 @@ type vm struct { BaseImage string `json:"base_image"` } -func fetchVMs(network string) []vm { +func fetchVMs(token string, network string) []vm { var vms []vm req, err := http.NewRequest("GET", API + "vms/" + network, nil) if err != nil { log.Fatal("can't make new req") } - req.Header.Set("X-Wit-Auth", JWT) + req.Header.Set("X-Wit-Auth", token) client := &http.Client{} resp, err := client.Do(req) if err != nil { log.Printf("Can't exec the req to fetch vms for %s: %s", network, err) } @@ -87,12 +92,15 @@ func fetchVMs(network string) []vm { return vms } -func oldmain() *pb.Event { +func processGetEvent(ge *pb.Event) *pb.Event { + log.Println("processGetEvent() START") + log.Println("processGetEvent() ge.Token =", ge.Token) + e := pb.Event{} e.Name = "stablesid.org" - networks := fetchNetworks() + networks := fetchNetworks(ge.Token) for i, network := range(networks) { if i >= MAX_NETS { break @@ -104,7 +112,7 @@ func oldmain() *pb.Event { e.Networks = append(e.Networks, &enetwork) - vms := fetchVMs(network.Subdomain) + vms := fetchVMs(ge.Token, network.Subdomain) for j, vm := range(vms) { if j >= MAX_VMS { break