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) {
|
func sendSampleProtobuf(conn *websocket.Conn) {
|
||||||
msg := pb.CreateSampleEvent()
|
msg := pb.CreateSampleEvent()
|
||||||
msg.Name = "test echo over gorilla websocket"
|
msg.Name = "test echo over gorilla websocket"
|
||||||
|
@ -31,6 +32,7 @@ func sendSampleProtobuf(conn *websocket.Conn) {
|
||||||
log.Println("sendProtobuf() write:", err)
|
log.Println("sendProtobuf() write:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func sendProtobuf(conn *websocket.Conn, msg *pb.Event) {
|
func sendProtobuf(conn *websocket.Conn, msg *pb.Event) {
|
||||||
data, _ := proto.Marshal(msg)
|
data, _ := proto.Marshal(msg)
|
||||||
|
@ -70,7 +72,12 @@ func eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("recv binary: %s", pdata)
|
log.Printf("recv binary: %s", pdata)
|
||||||
if pdata.Type == pb.Event_MIGRATE {
|
if pdata.Type == pb.Event_MIGRATE {
|
||||||
log.Printf("GOT 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)
|
sendProtobuf(conn, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@ type network struct {
|
||||||
Subdomain string `json:"subdomain"`
|
Subdomain string `json:"subdomain"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchNetworks() []network {
|
func fetchNetworks(token string) []network {
|
||||||
var networks []network
|
var networks []network
|
||||||
req, err := http.NewRequest("GET", API + "clusters", nil)
|
req, err := http.NewRequest("GET", API + "clusters", nil)
|
||||||
if err != nil { log.Fatal("can't make new req") }
|
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{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil { log.Printf("Can't exec the req to list networks: %s", err) }
|
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 {
|
if body == nil {
|
||||||
log.Println("networks is nil")
|
log.Println("networks is nil")
|
||||||
} else {
|
} else {
|
||||||
|
len := len(body)
|
||||||
err = json.Unmarshal(body, &networks)
|
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)
|
spew.Dump(networks)
|
||||||
return networks
|
return networks
|
||||||
|
@ -71,11 +76,11 @@ type vm struct {
|
||||||
BaseImage string `json:"base_image"`
|
BaseImage string `json:"base_image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchVMs(network string) []vm {
|
func fetchVMs(token string, network string) []vm {
|
||||||
var vms []vm
|
var vms []vm
|
||||||
req, err := http.NewRequest("GET", API + "vms/" + network, nil)
|
req, err := http.NewRequest("GET", API + "vms/" + network, nil)
|
||||||
if err != nil { log.Fatal("can't make new req") }
|
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{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil { log.Printf("Can't exec the req to fetch vms for %s: %s", network, err) }
|
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
|
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 := pb.Event{}
|
||||||
|
|
||||||
e.Name = "stablesid.org"
|
e.Name = "stablesid.org"
|
||||||
|
|
||||||
networks := fetchNetworks()
|
networks := fetchNetworks(ge.Token)
|
||||||
for i, network := range(networks) {
|
for i, network := range(networks) {
|
||||||
if i >= MAX_NETS {
|
if i >= MAX_NETS {
|
||||||
break
|
break
|
||||||
|
@ -104,7 +112,7 @@ func oldmain() *pb.Event {
|
||||||
|
|
||||||
e.Networks = append(e.Networks, &enetwork)
|
e.Networks = append(e.Networks, &enetwork)
|
||||||
|
|
||||||
vms := fetchVMs(network.Subdomain)
|
vms := fetchVMs(ge.Token, network.Subdomain)
|
||||||
for j, vm := range(vms) {
|
for j, vm := range(vms) {
|
||||||
if j >= MAX_VMS {
|
if j >= MAX_VMS {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue