lots of cleanups to token handling. protobuf fixes
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
b16b4c84bb
commit
2d3a0a900a
|
@ -43,9 +43,16 @@ func fetchJSON(GETorPOST string, token string, a string) []byte {
|
|||
}
|
||||
|
||||
func getToken(ge *pb.Event) string {
|
||||
if ge == nil {return ""}
|
||||
if ge == nil {
|
||||
log.Println("getToken() has ge = nil")
|
||||
return ""
|
||||
}
|
||||
if ge.Account == nil {
|
||||
log.Println("getToken() has ge.Account = nil")
|
||||
return ""
|
||||
}
|
||||
|
||||
url := ge.Account.URL + "/auth/login" + "?email=" + ge.Email + "&password=" + ge.Password
|
||||
url := ge.Account.URL + "/auth/login" + "?email=" + ge.Account.Email + "&password=" + ge.Account.Password
|
||||
log.Println("URL =", url)
|
||||
|
||||
var jsonStr = []byte(`{}`)
|
||||
|
|
|
@ -26,7 +26,7 @@ type network struct {
|
|||
func checkLogin(ge *pb.Event) string {
|
||||
if (origLoginCheck(ge) == true) {
|
||||
log.Println("origLoginCheck() LOGIN WORKED")
|
||||
return ge.Token
|
||||
return ge.Account.Token
|
||||
}
|
||||
log.Println("origLoginCheck() LOGIN FAILED. ATTEMPT getToken(ge)")
|
||||
log.Println("origLoginCheck() LOGIN FAILED. ATTEMPT getToken(ge)")
|
||||
|
@ -226,13 +226,13 @@ func main() {
|
|||
|
||||
func processGetEvent(ge *pb.Event) *pb.Event {
|
||||
log.Println("processGetEvent() START")
|
||||
log.Println("processGetEvent() ge.Token =", ge.Token)
|
||||
log.Println("processGetEvent() ge.Username =", ge.Username)
|
||||
log.Println("processGetEvent() ge.Email =", ge.Email)
|
||||
log.Println("processGetEvent() ge.Account.Token =", ge.Account.Token)
|
||||
log.Println("processGetEvent() ge.Account.Username =", ge.Account.Username)
|
||||
log.Println("processGetEvent() ge.Account.Email =", ge.Account.Email)
|
||||
|
||||
e := pb.Event{}
|
||||
|
||||
networks := fetchNetworks(ge.Token)
|
||||
networks := fetchNetworks(ge.Account.Token)
|
||||
for i, network := range(networks) {
|
||||
if i >= MAX_NETS {
|
||||
break
|
||||
|
@ -244,7 +244,7 @@ func processGetEvent(ge *pb.Event) *pb.Event {
|
|||
|
||||
e.Networks = append(e.Networks, &enetwork)
|
||||
|
||||
vms := fetchVMs(ge.Token, network.Subdomain)
|
||||
vms := fetchVMs(ge.Account.Token, network.Subdomain)
|
||||
for j, vm := range(vms) {
|
||||
if j >= MAX_VMS {
|
||||
break
|
||||
|
@ -266,7 +266,7 @@ func processGetEvent(ge *pb.Event) *pb.Event {
|
|||
|
||||
func processLoginEvent(ge *pb.Event) *pb.Event {
|
||||
log.Println("processLoginEvent() START")
|
||||
log.Println("processLoginEvent() ge.Token =", ge.Token)
|
||||
log.Println("processLoginEvent() ge.Account.Token =", ge.Account.Token)
|
||||
|
||||
|
||||
log.Println("processLoginEvent() NEED TO LOGIN HERE OR CHECK TOKEN WORKS")
|
||||
|
@ -276,29 +276,29 @@ func processLoginEvent(ge *pb.Event) *pb.Event {
|
|||
e.Comment = "LOGIN FAILED"
|
||||
return e
|
||||
}
|
||||
|
||||
log.Println("processLoginEvent() LOGIN WORKED")
|
||||
log.Println("processLoginEvent() LOGIN WORKED")
|
||||
log.Println("processLoginEvent() LOGIN WORKED")
|
||||
e := pb.MakeOkResponse()
|
||||
e.Token = token
|
||||
e.Account = ge.Account
|
||||
if (e.Account.Token != token) {
|
||||
log.Println("processLoginEvent() GENERATED NEW TOKEN old =", e.Account.Token)
|
||||
log.Println("processLoginEvent() GENERATED NEW TOKEN new =", token)
|
||||
}
|
||||
e.Account.Token = token
|
||||
e.Comment = "LOGIN WORKED"
|
||||
return e
|
||||
}
|
||||
|
||||
func processAddEvent(ge *pb.Event) *pb.Event {
|
||||
log.Println("processAddEvent() START")
|
||||
log.Println("processAddLoginEvent() ge.Token =", ge.Token)
|
||||
log.Println("processAddLoginEvent() ge.Account.Token =", ge.Account.Token)
|
||||
log.Println("processAddEvent() END")
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
var login string
|
||||
login = "auth/login?email=jcarr@wit.com&password=yowzayowza"
|
||||
raw = fetchPOST("badtoken", login)
|
||||
log.Println("raw =", string(raw))
|
||||
*/
|
||||
|
||||
func jsonAddEvent(ge *pb.Event) bool {
|
||||
var url string
|
||||
var httpType string
|
||||
|
@ -306,7 +306,6 @@ func jsonAddEvent(ge *pb.Event) bool {
|
|||
if ge.Type == pb.Event_LOGIN {
|
||||
url = API + "me"
|
||||
} else if ge.Type == pb.Event_ADD {
|
||||
// stackapi:4000/vms/jcarr.com?count=1&cpu=2&ram=512&disk=25
|
||||
url = API + "vms/jcarr.com?count=1&cpu=2&ram=512&disk=25"
|
||||
httpType = "POST"
|
||||
} else if ge.Type == pb.Event_MIGRATE {
|
||||
|
@ -352,6 +351,7 @@ func jsonAddEvent(ge *pb.Event) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
*/
|
||||
|
||||
// This is the 'orig' code
|
||||
// TODO: phase this out for more common code
|
||||
|
@ -367,7 +367,7 @@ func origLoginCheck(ge *pb.Event) bool {
|
|||
log.Println("can't make new req")
|
||||
return false
|
||||
}
|
||||
req.Header.Set("X-Wit-Auth", ge.Token)
|
||||
req.Header.Set("X-Wit-Auth", ge.Account.Token)
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
@ -379,7 +379,7 @@ func origLoginCheck(ge *pb.Event) bool {
|
|||
log.Println("can't read resp")
|
||||
return false
|
||||
}
|
||||
log.Printf("RESPONSE =", body)
|
||||
log.Printf("RESPONSE =", string(body))
|
||||
if body == nil {
|
||||
log.Println("RESPONSE is nil")
|
||||
return false
|
||||
|
@ -389,8 +389,8 @@ func origLoginCheck(ge *pb.Event) bool {
|
|||
log.Println("body len = ", len)
|
||||
email := gjson.Get(string(body), "email")
|
||||
log.Println("email = ", email.String())
|
||||
log.Println("ge.Username = ", ge.Username)
|
||||
if (email.String() == ge.Username) {
|
||||
log.Println("ge.Account.Username = ", ge.Account.Username)
|
||||
if (email.String() == ge.Account.Username) {
|
||||
log.Println("\tTHIS TOTALLY WORKED MAN")
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue