recieve the token
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bb12949637
commit
47a5b0659c
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue