Skip to content
Snippets Groups Projects
Commit 61bc84c2 authored by Florent Gluck's avatar Florent Gluck
Browse files

Reworked nexus-exam to better indicate whether there is a connection issue

parent 633c74a1
Branches
No related tags found
No related merge requests found
......@@ -312,7 +312,7 @@ build_nexus-exam: check_server_var check_cert_var check_nexus_exam_vars copy_res
@echo -n '$(value EXAM_PWD)' > $(NEXUS_EXAM_PWD_CREDS_FILE)
@cd $(SRC_CLIENT)/nexus-exam && go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) && mv nexus-exam $(BUILD_ABS_CLIENT)
@strip -s $(BUILD_DIR_CLIENT)/nexus-exam
@upx -q $(BUILD_DIR_CLIENT)/nexus-exam
# @upx -q $(BUILD_DIR_CLIENT)/nexus-exam
@rm $(NEXUS_EXAM_USER_CREDS_FILE) $(NEXUS_EXAM_PWD_CREDS_FILE)
clean_client:
......
......@@ -32,6 +32,8 @@ import (
const (
windowTitle = "nexus-exam"
connectionMsg = "Enter password to connect to your VM:"
)
var (
......@@ -41,9 +43,13 @@ var (
//go:embed nexus_exam_pwd.val
nexus_exam_pwd string
token string
certPath string
exitFn func()
token string
loggedIn bool
appLabel *widget.Label
appConnect *widget.Form
)
func exit(code int) {
......@@ -144,27 +150,44 @@ func setHeaderToken() {
// Recurrently obtains a new JWT token so that the user session doesn't expire.
func refreshToken(parent fyne.Window) {
// Wait 10 seconds before attempting to refresh the token.
// The reason for this delay is that when nexus-exam is launched from
// a nexus live image, the wifi interface might not be up yet.
time.Sleep(10 * time.Second)
var err error
for {
if !loggedIn {
// Logins and obtains a JWT token.
token, err = cmdLogin.GetToken(nexus_exam_user, nexus_exam_pwd)
if err != nil {
appLabel.SetText("Unable to connect to server (error code 1)...\nCheck your network connection.")
u.PrintlnErr(time.Now(), ": failed connecting to server: "+err.Error())
} else {
u.Println(time.Now(), ": successfully connected to server")
appLabel.SetText(connectionMsg)
loggedIn = true
}
} else {
setHeaderToken()
refreshedToken, err := cmdToken.GetToken()
if err != nil {
errorPopup(parent, "Failed refreshing token")
appLabel.SetText("Unable to connect to server (error code 2)...\nCheck your network connection.")
u.PrintlnErr(time.Now(), ": failed refreshing token: "+err.Error())
break
loggedIn = false
} else {
appLabel.SetText(connectionMsg)
u.Println(time.Now(), ": successfully refreshed token")
}
token = refreshedToken
time.Sleep(1 * time.Hour)
}
if loggedIn {
appConnect.Show()
} else {
appConnect.Hide()
}
time.Sleep(10 * time.Second)
}
}
func run() int {
loggedIn = false
var appname = path.Base(os.Args[0])
clientVersion := version.Get()
u.PrintlnErr(appname + " version " + clientVersion.String() + " (commit " + buildversion.GitCommit() + ")")
......@@ -176,11 +199,9 @@ func run() int {
abortWindow(err.Error())
}
var err error // necessary for certPath below to be ref as the same variable
certPath, err = defaults.CreateCert()
certPath, err := defaults.CreateCert()
if err != nil {
abortWindow("Failed creating certificate from embedded certificate!")
abortWindow("Failed creating certificate!")
}
// No embedded certificate, exit with a information message.
if certPath == "" {
......@@ -205,19 +226,13 @@ func run() int {
g.Init(hostname, host, certPath, client)
client.SetTimeout(10 * time.Second)
client.SetTimeout(4 * time.Second)
// Checks the client version is compatible with the server's API.
// if !cmdVersion.CheckServerCompatibility("nexus-exam") {
// abortWindow("client version is incompatible with server!")
// }
// Logins and obtains a JWT token.
token, err = cmdLogin.GetToken(nexus_exam_user, nexus_exam_pwd)
if err != nil {
abortWindow("Failed obtaining token (network issue?)")
}
app := app.New()
app.Settings().SetTheme(theme.LightTheme())
win := app.NewWindow(windowTitle)
......@@ -232,9 +247,9 @@ func run() int {
return nil
}
label := widget.NewLabel("Enter password to connect to your VM:")
appLabel = widget.NewLabel("Please wait, connecting to server...")
form := &widget.Form{
appConnect = &widget.Form{
Items: []*widget.FormItem{
{Text: "Password", Widget: pwdEntry},
},
......@@ -244,8 +259,9 @@ func run() int {
SubmitText: "Connect",
}
win.SetContent(container.NewPadded(container.NewVBox(label, form)))
win.Resize(fyne.NewSize(600, 200))
win.SetContent(container.NewPadded(container.NewVBox(appLabel, appConnect)))
win.Resize(fyne.NewSize(600, 160))
appConnect.Hide()
go refreshToken(win)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment