store the account information

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-23 11:33:30 -07:00
parent 3eaa1bf85e
commit a3896449ca
2 changed files with 54 additions and 15 deletions

View File

@ -12,6 +12,7 @@ package main
import "log" import "log"
import "os" import "os"
import "os/user"
import "flag" import "flag"
import "fmt" import "fmt"
import "runtime" import "runtime"
@ -87,16 +88,30 @@ func parseConfig(defaultConfig string) {
config.AddDriver(yaml.Driver) config.AddDriver(yaml.Driver)
config.AddDriver(json.Driver) config.AddDriver(json.Driver)
// look up the user information to try to figure out where the config file is stored
user, err := user.Current()
if err != nil {
onExit(err)
}
// TODO: figure out how to look for this file in the right // TODO: figure out how to look for this file in the right
// place under Linux, MacOS and Windows // place under Linux, MacOS and Windows
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
log.Println("OS: Linux") log.Println("OS: Linux")
config.Set("configfile", user.HomeDir + "/.config/cloud-control-panel.json")
} else if runtime.GOOS == "windows" { } else if runtime.GOOS == "windows" {
log.Println("OS: Windows") log.Println("OS: Windows")
config.Set("configfile", user.HomeDir + "\\cloud-control-panel.json")
} else { } else {
log.Println("OS: " + runtime.GOOS) log.Println("OS: " + runtime.GOOS)
config.Set("configfile", user.HomeDir + "/cloud-control-panel.json")
} }
config.LoadFiles("config.json")
// TODO: load the default config file from the resources dir if the config file doesn't exist yet
// config.LoadFiles("config.json")
filename := config.String("configfile")
config.LoadFiles(filename)
for _, addr := range config.Strings("arr1") { for _, addr := range config.Strings("arr1") {
log.Println("addr =", addr) log.Println("addr =", addr)

40
main.go
View File

@ -3,7 +3,7 @@ package main
import "log" import "log"
import "os" import "os"
import "time" import "time"
// import "fmt" import "os/user"
import "github.com/gookit/config" import "github.com/gookit/config"
import "github.com/gobuffalo/packr" import "github.com/gobuffalo/packr"
@ -34,20 +34,26 @@ var GOVERSION string // this is passed in as an ldflag
// Exit and write out the config // Exit and write out the config
// (in yaml and json I guess.) // (in yaml and json I guess.)
// switch to json once it can be made human readable // switch to json once it can be made human readable
func onExit() { func onExit(err error) {
log.Println("Sleep for 1 second") log.Println("Sleep for 1 second")
time.Sleep(1 * 1000 * 1000 * 1000) time.Sleep(1 * 1000 * 1000 * 1000)
f, err := os.Create("/tmp/cloud-control-panel.yaml") filename := config.String("configfile")
f, err := os.Create(filename + ".yaml")
if err == nil { if err == nil {
config.DumpTo(f, "yaml") config.DumpTo(f, "yaml")
} }
f, err = os.Create("/tmp/cloud-control-panel.json") f, err = os.Create(filename)
if err == nil { if err == nil {
config.DumpTo(f, "json") config.DumpTo(f, "json")
} }
if (err != nil) {
panic(err)
}
os.Exit(0) os.Exit(0)
} }
@ -63,7 +69,7 @@ func main() {
// only test the socket code if no GUI // only test the socket code if no GUI
if (config.String("nogui") == "true") { if (config.String("nogui") == "true") {
log.Println("Need to re-implement this") log.Println("Need to re-implement this")
onExit() onExit(nil)
} }
initChannel() initChannel()
@ -72,12 +78,27 @@ func main() {
go gorillaDial("v000185.testing.com.customers.wprod.wit.com:9000") go gorillaDial("v000185.testing.com.customers.wprod.wit.com:9000")
go watchGUI() go watchGUI()
user, err := user.Current()
if err != nil {
onExit(err)
}
gui.Data.Width = config.Int("width") gui.Data.Width = config.Int("width")
gui.Data.Height = config.Int("height") gui.Data.Height = config.Int("height")
gui.Data.Version = "v0.4" gui.Data.Version = "v0.4"
gui.Data.GitCommit = GITCOMMIT gui.Data.GitCommit = GITCOMMIT
gui.Data.GoVersion = GOVERSION gui.Data.GoVersion = GOVERSION
gui.Data.ButtonClickNew = buttonClickNew gui.Data.ButtonClickNew = buttonClickNew
gui.Data.HomeDir = user.HomeDir
// Current User
log.Println("Hi " + user.Name + " (id: " + user.Uid + ")")
log.Println("Username: " + user.Username)
log.Println("Home Dir: " + user.HomeDir)
// Get "Real" User under sudo.
// More Info: https://stackoverflow.com/q/29733575/402585
log.Println("Real User: " + os.Getenv("SUDO_USER"))
// make this the main loop in an attempt to figure out the crashes // make this the main loop in an attempt to figure out the crashes
// do not change this until the GUI is stable // do not change this until the GUI is stable
@ -93,12 +114,14 @@ func buttonClickNew(b *gui.ButtonMap) {
gui.Data.State = "splash" gui.Data.State = "splash"
} }
if (b.Note == "QUIT") { if (b.Note == "QUIT") {
onExit() onExit(nil)
} }
if (b.Note == "ADD") { if (b.Note == "ADD") {
log.Println("\tSHOULD ADD ACCOUNT HERE") log.Println("\tSHOULD ADD ACCOUNT HERE")
log.Println("\tSHOULD ADD ACCOUNT HERE") if (gui.Data.AccNick != "") {
log.Println("\tSHOULD ADD ACCOUNT HERE") log.Println("\tADDING ACCOUNT HERE")
log.Println("\tADDING ACCOUNT HERE")
log.Println("\tADDING ACCOUNT HERE")
log.Println("\tData.AccNick = ", gui.Data.AccNick) log.Println("\tData.AccNick = ", gui.Data.AccNick)
log.Println("\tData.AccUser = ", gui.Data.AccUser) log.Println("\tData.AccUser = ", gui.Data.AccUser)
log.Println("\tData.AccPass = ", gui.Data.AccPass) log.Println("\tData.AccPass = ", gui.Data.AccPass)
@ -106,6 +129,7 @@ func buttonClickNew(b *gui.ButtonMap) {
config.Set("accounts." + gui.Data.AccNick + ".password", gui.Data.AccPass) config.Set("accounts." + gui.Data.AccNick + ".password", gui.Data.AccPass)
config.Set("accounts." + gui.Data.AccNick + ".hostname", "v000185.testing.com.customers.wprod.wit.com") config.Set("accounts." + gui.Data.AccNick + ".hostname", "v000185.testing.com.customers.wprod.wit.com")
} }
}
if (b.Note == "BMATH") { if (b.Note == "BMATH") {
log.Println("\tTRIGGER BMATH HERE") log.Println("\tTRIGGER BMATH HERE")
log.Println("\tTRIGGER BMATH HERE") log.Println("\tTRIGGER BMATH HERE")