Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Secure solution for nexus infrastructure
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_masters
TM
Secure solution for nexus infrastructure
Commits
61bc84c2
Commit
61bc84c2
authored
10 months ago
by
Florent Gluck
Browse files
Options
Downloads
Patches
Plain Diff
Reworked nexus-exam to better indicate whether there is a connection issue
parent
633c74a1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile
+1
-1
1 addition, 1 deletion
Makefile
src/client/nexus-exam/nexus-exam.go
+47
-31
47 additions, 31 deletions
src/client/nexus-exam/nexus-exam.go
with
48 additions
and
32 deletions
Makefile
+
1
−
1
View file @
61bc84c2
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
src/client/nexus-exam/nexus-exam.go
+
47
−
31
View file @
61bc84c2
...
...
@@ -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)...
\n
Check 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)...
\n
Check 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
}
l
abel
:
=
widget
.
NewLabel
(
"
Enter password to
connect to
your VM:
"
)
appL
abel
=
widget
.
NewLabel
(
"
Please wait,
connect
ing
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment