diff --git a/config.go b/config.go index f6bf498..410b0b8 100644 --- a/config.go +++ b/config.go @@ -24,10 +24,6 @@ import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" -// always override the debugging flag from the command line -var debugging *bool -var debugtable *bool - var config *pb.Config // This loads the config file and marshals it into the @@ -76,6 +72,10 @@ var customUsage = func() { func parseFlags() { var hostname string + // always override the debugging flag from the command line + var debugging *bool + var debugtable *bool + flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname") height := flag.Int ("height", 0, "Height of the Window") @@ -114,18 +114,6 @@ func parseFlags() { config.Debugtable = *debugtable } -func parseConfig() { - // first load the config file - loadConfigFile() - - // override the config file from the command line - parseFlags() - - log.Println("config.width", config.Width) - log.Println("config.height", config.Height) - log.Println("config.debugging", config.Debugging) -} - // Convert a Protobuf to JSON func PBtoJSON() string { // this makes a sample protobuf @@ -195,6 +183,27 @@ func loadDefaultConfig() pb.Config { log.Println("jsonpb.Unmarshal() ERROR =", err) } spew.Dump(sets) - // os.Exit(0) return sets } + +// +// This is what you call from main() +// +func parseConfig() { + // first load the config file + loadConfigFile() + + // override the config file from the command line + parseFlags() + + log.Println("config.width", config.Width) + log.Println("config.height", config.Height) + log.Println("config.debugging", config.Debugging) + + // check that the config parsing worked + for key, foo := range config.Accounts { + log.Println("account = ", key, foo) + log.Println("Accounts[key] = ", config.Accounts[key]) + } + // os.Exit(0) +} diff --git a/eventChannel.go b/eventChannel.go index 7e51c2a..f2bfdaa 100644 --- a/eventChannel.go +++ b/eventChannel.go @@ -54,7 +54,7 @@ func addEvent(msg *pb.Event) { func processEvents() { for { currentMessage = <-mychannel - log.Println("processEvents() START on channel recieved a message = ", currentMessage) + log.Println("processEvents() RECIEVED msg = ", currentMessage) if (currentMessage.Type == pb.Event_DEMO) { log.Println("processEvents() do Event DEMO") } else { diff --git a/gorilla.go b/gorilla.go index 431ef55..f16f9d8 100644 --- a/gorilla.go +++ b/gorilla.go @@ -12,6 +12,7 @@ import "github.com/gorilla/websocket" import "github.com/golang/protobuf/proto" import pb "git.wit.com/wit/witProtobuf" +// import "git.wit.com/wit/gui" var gorillaConn *websocket.Conn @@ -41,22 +42,25 @@ func gorillaReadProtobuf(conn *websocket.Conn) { } func gorillaSendProtobuf(msg *pb.Event) { - log.Println("gorillaSendProtobuf() START", time.Now()) - log.Println("gorillaSendProtobuf()", msg) + log.Println("gorillaSendProtobuf() Event_Type =", msg.Type, "Event.Account.Nick =", msg.Account) + if (gorillaConn == nil) { - log.Println("gorillaSendProtobuf() gorillaConn == nil") - log.Println("Need to re-open connection here") + log.Println("gorillaSendProtobuf() CAN NOT SEND (socket connection isn't open)") return } - /* - msg := pb.CreateSampleEvent() - msg.Name = "test echo over gorilla websocket" - */ - log.Println("gorillaSendProtobuf() going to Marshal msg =", msg) - data, _ := proto.Marshal(msg) - err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, data) + + test, err := proto.Marshal(msg) + if err != nil { + log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err) + log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err) + log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err) + // TODO: return here? + return + } + + err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, test) if err2 != nil { - log.Println("write:", err2) + log.Println("gorillaConn.WriteMessage() failed write:", err2) gorillaConn = nil return } diff --git a/main.go b/main.go index 012436e..247e372 100644 --- a/main.go +++ b/main.go @@ -155,17 +155,18 @@ func main() { // might be a good approach. Time will tell... // func mainMouseClick(b *gui.ButtonMap) { - log.Println("mainMouseClick() b =", b) - if (b == nil) { log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") onExit(fmt.Errorf("mainMouseClick() got b = nil")) } + log.Println("mainMouseClick() b.Action =", b.Action) gui.Data.Current = b.Account - log.Println("main() BACK IN CONTROL PANEL CODE (button =", b, ")") - log.Println("\tmainMouseClick() setting current account = ", b.Account) + log.Println("main() BACK IN CONTROL PANEL CODE") + if (b.Account != nil) { + log.Println("\tmainMouseClick() setting current account = ", b.Account.Nick) + } if (b.Action == "BACK") { gui.Data.State = "splash" } else if (b.Action == "QUIT") { @@ -214,10 +215,10 @@ func mainMouseClick(b *gui.ButtonMap) { event.Account = b.Account prepareAndSend(event) - count := 0 + // count := 0 for { log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State) - time.Sleep(200 * time.Millisecond) + time.Sleep(20 * time.Millisecond) if (gui.Data.State == "NEW PROTOBUF") { if (currentMessage == nil) { gui.SocketError() @@ -225,13 +226,13 @@ func mainMouseClick(b *gui.ButtonMap) { } else { log.Println("LOGIN currentMessage =", currentMessage) if (currentMessage.Type == pb.Event_OK) { - log.Println("\tLOGIN WAS OK!") - log.Println("\tLOGIN WAS OK!") - log.Println("\tLOGIN WAS OK!") msg := "On account " + b.Account.Nick + "\n" + log.Println("\tLOGIN WAS OK!", msg) + log.Println("\tLOGIN WAS OK! old button.Account was =", b.Account) + log.Println("\tLOGIN WAS OK! currentMessage.Account =", currentMessage.Account) + log.Println("\tLOGIN WAS OK!") gui.MessageWindow("Login OK", msg) - } - if (currentMessage.Type == pb.Event_FAIL) { + } else if (currentMessage.Type == pb.Event_FAIL) { log.Println("\tLOGIN FAILED") log.Println("\tLOGIN FAILED") log.Println("\tLOGIN FAILED") @@ -247,6 +248,8 @@ func mainMouseClick(b *gui.ButtonMap) { } return } + /* + TODO: fix this with an actual timeout count += 1 if (count > 10) { log.Println("\tERROR: waited too long for a resposne") @@ -254,6 +257,7 @@ func mainMouseClick(b *gui.ButtonMap) { gui.Data.State = "done" return } + */ } } else if (b.Action == "SHOW") { log.Println("\tTRIGGER DISPLAY ACCOUNT") @@ -306,20 +310,13 @@ func mainMouseClick(b *gui.ButtonMap) { } func prepareAndSend(event *pb.Event) { - /* - // This is sent in the Account now - if (gui.Data.Current != nil) { - event.Token = gui.Data.Current.Token - event.Username = gui.Data.Current.Username - event.Password = gui.Data.Current.Password - } - */ if (event.Account == nil) { log.Println("\tmain.prepareAndSend() ERROR event.Token = nil") log.Println("\tmain.prepareAndSend() ERROR event.Token = nil") log.Println("\tmain.prepareAndSend() ERROR event.Token = nil") } else { - log.Println("\tmain.prepareAndSend() event.Token =", event.Account.Token) + s := event.Account.Token + log.Println("\tmain.prepareAndSend() event.Token(-24:) =", s[len(s)-24:]) } gorillaSendProtobuf(event) gui.Data.State = "READ PROTOBUF" @@ -342,13 +339,6 @@ func watchGUI() { event := pb.MakeGetEvent() prepareAndSend(event) } -/* - if (gui.Data.State == "SEND LOGIN") { - log.Println("\tTRIGGERING LOGIN") - event := pb.MakeLoginEvent() - prepareAndSend(event) - } -*/ if (gui.Data.State == "CREATE") { log.Println("\tTRIGGERING CREATE") event := pb.MakeAddVmEvent() @@ -361,11 +351,20 @@ func watchGUI() { onExit(nil) } if (gui.Data.State == "splash") { + if (config == nil) { + log.Println("gui.State = splash BUT SOMETHING HAS GONE VERY WRONG") + log.Println("gui.State = splash BUT SOMETHING HAS GONE VERY WRONG") + log.Println("gui.State = splash config = nil") + os.Exit(-1) + } for key, _ := range config.Accounts { - log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Nick = ", config.Accounts[key].Nick) - log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Username = ", config.Accounts[key].Username) + log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Account = ", config.Accounts[key]) + // log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Username = ", config.Accounts[key]) log.Println("SETTING gui.State = main") gui.Data.State = "main"; + if (config.Accounts[key] == nil) { + log.Println("THIS IS LAME. CONFIG FILE MADE NULL ACCOUNTS key =", key) + } } } } diff --git a/resources/protobuf-config.json b/resources/protobuf-config.json index 851990b..6d67f6f 100644 --- a/resources/protobuf-config.json +++ b/resources/protobuf-config.json @@ -6,22 +6,28 @@ "nick": "jcarr", "username": "jcarr@wit.com", "token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e", - "hostname": "hosttest.wit.com", - "domainname": "test.wit.com" + "hostname": "customers.wprod.wit.com", + "password": "yowzayowza", + "URL": "http://stackapi:4000/", + "domain": "test.wit.com" }, { "nick": "jcarr2", "username": "jcarr@wit.com", + "email": "jcarr@wit.com", + "password": "yowzayowza", + "URL": "http://stackapi:4000/", + "hostname": "customers.wprod.wit.com", "token": "brokenToken", - "hostname": "hosttest.wit.com", - "domainname": "test.wit.com" + "domain": "test.wit.com" }, { "nick": "bmath", "username": "bmath@wit.com", "token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6ImJRSVFtV2JjdktUN2FtUWpEZWlMUFhXeSIsImV4cCI6MTU1OTQzMTgzNiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.9hdVWBZwAA1Hssf6Oh9UlP_DW3TPIv30wuq8pyhQHtQLaBgAXgaSqwBbGOWrjhYixQlzfUCZ6Oym6AqVNJ3H5_lPl3wwUm7Qz3G0zmenV2BE54rtVoENbzm_cKSzMqco", "hostname": "customers.wprod.wit.com", - "domainname": "testing.com" + "URL": "http://stackapi:4000/", + "domain": "testing.com" } ] } diff --git a/resources/protobuf-config2.json b/resources/protobuf-config2.json deleted file mode 100644 index 5688f3c..0000000 --- a/resources/protobuf-config2.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "USER": "jcarr", - "width": 700, - "height": 600, - "filename": "/home/jcarr/.config/cloud-control-panel.json", - "accounts": [ - { - "nick": "jcarr", - "username": "jcarr@wit.com", - "token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e", - "hostname": "hosttest.wit.com", - "domainname": "test.wit.com" - }, - { - "nick": "jcarr2", - "username": "jcarr@wit.com", - "token": "brokenToken", - "hostname": "hosttest.wit.com", - "domainname": "test.wit.com" - }, - { - "nick": "bmath", - "username": "bmath@wit.com", - "token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI", - "hostname": "hosttest.wit.com", - "domainname": "test.wit.com" - } - ] -} diff --git a/resources/protobuf-small.json b/resources/protobuf-small.json deleted file mode 100644 index 0967ef4..0000000 --- a/resources/protobuf-small.json +++ /dev/null @@ -1 +0,0 @@ -{}