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

Fixed nexus-exam compile error

Fixed newly introduced csv parsing error
Moved most client utils functions to libclient
nexus-exam: changed token refresh delay to 2 min
parent bee0da5e
Branches
No related tags found
No related merge requests found
Showing
with 43 additions and 33 deletions
......@@ -6,6 +6,7 @@ import (
u "nexus-client/utils"
t "nexus-common/template"
libclient "nexus-libclient/template"
"nexus-libclient/utils"
"regexp"
"strings"
......@@ -60,7 +61,7 @@ func (cmd *List) Run(args []string) int {
}
if foundLongOutputFlag >= 0 {
args = u.RemoveArgAtIndex(args, foundLongOutputFlag)
args = utils.RemoveArgAtIndex(args, foundLongOutputFlag)
}
templates, err := cmd.getFilteredTemplates(args)
......
......@@ -8,6 +8,7 @@ import (
"nexus-common/params"
g "nexus-libclient/globals"
libclient "nexus-libclient/user"
"nexus-libclient/utils"
"os"
"strings"
)
......@@ -51,7 +52,7 @@ List of user capabilities:
usage += v + " "
i += 1
if i >= 5 {
usage = u.AppendNewLine(usage)
usage = utils.AppendNewLine(usage)
i = 0
}
}
......@@ -115,7 +116,7 @@ func (cmd *Add) Run(args []string) int {
}
email := columns[0]
if !u.IsEmail(email) {
if !utils.IsEmail(email) {
u.PrintlnErr("Failed reading record on line ", line, ": ", email, " is not a valid email")
statusCode = 1
continue
......
......@@ -6,6 +6,7 @@ import (
u "nexus-client/utils"
g "nexus-libclient/globals"
libclient "nexus-libclient/user"
"nexus-libclient/utils"
"os"
)
......@@ -43,12 +44,12 @@ func (cmd *Del) Run(args []string) int {
statusCode := 0
if argc == 1 && !u.IsEmail(args[0]) {
if argc == 1 && !utils.IsEmail(args[0]) {
// Single argument and it's a CSV file
csvFile := args[0]
if u.IsEmail(csvFile) {
if utils.IsEmail(csvFile) {
cmd.PrintUsage()
return 1
}
......@@ -83,7 +84,7 @@ func (cmd *Del) Run(args []string) int {
}
email := columns[0]
if !u.IsEmail(email) {
if !utils.IsEmail(email) {
u.PrintlnErr("Failed reading record on line ", line, ": ", email, " is not a valid email")
statusCode = 1
continue
......
......@@ -6,6 +6,7 @@ import (
u "nexus-client/utils"
"nexus-common/params"
libclient "nexus-libclient/user"
"nexus-libclient/utils"
"regexp"
"strings"
)
......@@ -58,7 +59,7 @@ func (cmd *List) Run(args []string) int {
}
if foundLongOutputFlag >= 0 {
args = u.RemoveArgAtIndex(args, foundLongOutputFlag)
args = utils.RemoveArgAtIndex(args, foundLongOutputFlag)
}
users, err := libclient.GetUsers()
......
......@@ -8,6 +8,7 @@ import (
"nexus-common/params"
g "nexus-libclient/globals"
libclient "nexus-libclient/user"
"nexus-libclient/utils"
"os"
"strings"
)
......@@ -50,7 +51,7 @@ List of user capabilities:
i += 1
count += 1
if i >= 5 && count < len(caps) {
usage = u.AppendNewLine(usage)
usage = utils.AppendNewLine(usage)
i = 0
}
}
......@@ -66,12 +67,12 @@ func (cmd *SetCaps) Run(args []string) int {
statusCode := 0
if argc == 1 && !u.IsEmail(args[0]) {
if argc == 1 && !utils.IsEmail(args[0]) {
// Single argument and it's a CSV file
csvFile := args[0]
if u.IsEmail(csvFile) {
if utils.IsEmail(csvFile) {
cmd.PrintUsage()
return 1
}
......@@ -116,7 +117,7 @@ func (cmd *SetCaps) Run(args []string) int {
}
email := columns[0]
if !u.IsEmail(email) {
if !utils.IsEmail(email) {
u.PrintlnErr("Failed reading record on line ", line, ": ", email, " is not a valid email")
statusCode = 1
continue
......
......@@ -9,6 +9,7 @@ import (
"nexus-common/caps"
"nexus-common/params"
g "nexus-libclient/globals"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
"os"
"strings"
......@@ -53,7 +54,7 @@ List of VM access capabilities:
i += 1
count += 1
if i >= 5 && count < len(caps) {
usage = u.AppendNewLine(usage)
usage = utils.AppendNewLine(usage)
i = 0
}
}
......@@ -107,7 +108,7 @@ func (cmd *AddAccess) Run(args []string) int {
vmID := columns[0]
email := columns[1]
if !u.IsEmail(email) {
if !utils.IsEmail(email) {
u.PrintlnErr("FAILED reading record on line ", line, ": ", email, " is not a valid email")
statusCode = 1
continue
......
......@@ -5,6 +5,7 @@ import (
u "nexus-client/utils"
"nexus-common/params"
"nexus-common/vm"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
"strconv"
......@@ -67,7 +68,7 @@ func (cmd *Create) Run(args []string) int {
return 1
}
nic := vm.NicType(args[3])
usbDevs := u.Str2UsbDevices(args[4])
usbDevs := utils.Str2UsbDevices(args[4])
templateID, err := uuid.Parse(args[5])
if err != nil {
u.PrintlnErr(err)
......@@ -82,7 +83,7 @@ func (cmd *Create) Run(args []string) int {
if err != nil {
// It's not a number, we assume it's a CSV file and parse it.
csvFile := args[6]
csvEntries, err = u.ReadCSVColumn(csvFile, 0)
csvEntries, err = utils.ReadCSVColumn(csvFile, 0)
if err != nil {
u.PrintlnErr(err)
return 1
......
......@@ -7,6 +7,7 @@ import (
"net/mail"
u "nexus-client/utils"
g "nexus-libclient/globals"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
"os"
)
......@@ -85,7 +86,7 @@ func (cmd *DelAccess) Run(args []string) int {
vmID := columns[0]
email := columns[1]
if !u.IsEmail(email) {
if !utils.IsEmail(email) {
u.PrintlnErr("FAILED reading record on line ", line, ": ", email, " is not a valid email")
statusCode = 1
continue
......
......@@ -5,6 +5,7 @@ import (
u "nexus-client/utils"
"nexus-common/params"
"nexus-common/vm"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
"strconv"
"strings"
......@@ -144,7 +145,7 @@ func (cmd *Edit) parseArgs(args []string) (*params.VMEdit, []string, error) {
}
s = getStringVal(arg, "usb=")
if s != "" {
vmParams.UsbDevs = u.Str2UsbDevices(s)
vmParams.UsbDevs = utils.Str2UsbDevices(s)
atLeastOneArg = true
continue
}
......
......@@ -2,9 +2,9 @@ package cmdVM
import (
u "nexus-client/utils"
"nexus-common/utils"
cu "nexus-common/utils"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
"os"
)
......@@ -60,14 +60,14 @@ func (cmd *ImportDir) Run(args []string) int {
statusCode := 0
tmpTarGzFile, err := utils.GetRandomTempFilename()
tmpTarGzFile, err := cu.GetRandomTempFilename()
if err != nil {
u.PrintlnErr(err)
return 1
}
tmpTarGzFile += ".tar.gz"
defer os.Remove(tmpTarGzFile)
if err := u.TarGzDir(localDir, tmpTarGzFile); err != nil {
if err := utils.TarGzDir(localDir, tmpTarGzFile); err != nil {
u.PrintlnErr(err)
return 1
}
......
......@@ -3,6 +3,7 @@ package cmdVM
import (
"fmt"
u "nexus-client/utils"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
)
......@@ -52,7 +53,7 @@ func (cmd *List) printFilteredVMs(args []string, route string) int {
}
if foundLongOutputFlag >= 0 {
args = u.RemoveArgAtIndex(args, foundLongOutputFlag)
args = utils.RemoveArgAtIndex(args, foundLongOutputFlag)
}
vms, err := getFilteredVMs(libclient.GetListVMs, args)
......
......@@ -4,6 +4,7 @@ import (
"errors"
u "nexus-client/utils"
"nexus-common/params"
"nexus-libclient/utils"
libclient "nexus-libclient/vm"
)
......@@ -35,12 +36,12 @@ func (cmd *StartWithCreds) PrintUsage() {
func (cmd *StartWithCreds) parseCSVFile(csvFile string) ([]string, []string, error) {
// Column 0: VM IDs
vmIDs, err := u.ReadCSVColumn(csvFile, 0)
vmIDs, err := utils.ReadCSVColumn(csvFile, 0)
if err != nil {
return nil, nil, err
}
// Column 2: passwords
pwds, err := u.ReadCSVColumn(csvFile, 2)
pwds, err := utils.ReadCSVColumn(csvFile, 2)
if err != nil {
return nil, nil, err
}
......
......@@ -4,8 +4,6 @@ import (
"bytes"
_ "embed"
"errors"
"nexus-client/cmdLogin"
"nexus-client/cmdToken"
"nexus-client/defaults"
e "nexus-client/exec"
u "nexus-client/utils"
......@@ -14,6 +12,7 @@ import (
"nexus-common/params"
"nexus-common/vm"
g "nexus-libclient/globals"
login "nexus-libclient/login"
libclient "nexus-libclient/vm"
"os"
"os/exec"
......@@ -128,7 +127,7 @@ func refreshToken(parent fyne.Window) {
for {
if !loggedIn {
// Logins and obtains a JWT token.
token, err = cmdLogin.GetToken(nexus_exam_user, nexus_exam_pwd)
token, err = login.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())
......@@ -139,7 +138,7 @@ func refreshToken(parent fyne.Window) {
}
} else {
setHeaderToken()
refreshedToken, err := cmdToken.GetToken()
refreshedToken, err := login.RefreshToken()
if err != nil {
appLabel.SetText("Unable to connect to server (error code 2)...\nCheck your network connection.")
u.PrintlnErr(time.Now(), ": failed refreshing token: "+err.Error())
......@@ -155,7 +154,7 @@ func refreshToken(parent fyne.Window) {
} else {
appConnect.Hide()
}
time.Sleep(10 * time.Second)
time.Sleep(60 * time.Second)
}
}
......
......@@ -2,9 +2,9 @@ package template
import (
"errors"
u "nexus-client/utils"
g "nexus-libclient/globals"
"nexus-libclient/response"
u "nexus-libclient/utils"
)
func TemplateExportDisk(tplID, outputFile string) error {
......
File moved
File moved
File moved
......@@ -2,9 +2,9 @@ package vm
import (
"errors"
u "nexus-client/utils"
"nexus-common/params"
g "nexus-libclient/globals"
u "nexus-libclient/utils"
)
func VMExportDir(vmName, vmID, dirToExport string) (string, error) {
......
......@@ -26,7 +26,7 @@ func isOlderThanMinutes(fi os.FileInfo, n time.Duration) bool {
func cleanup() {
dir := "/tmp"
log.Info("Cleanup thread configured to run every ", periodTimeInMin, " minutes and to delete uploaded files in ", dir, " last accessed more than ", deleteOlderThanInMin, " minutes ago")
log.Info("Cleanup thread: run every ", periodTimeInMin, " minutes; delete uploaded files in ", dir, " last accessed more than ", deleteOlderThanInMin, " minutes ago")
for {
log.Debug("Cleanup thread: checking for files to delete...")
......
......@@ -48,7 +48,7 @@ func main() {
cleaner.Start()
log.Info("API port: ", conf.Core.APIDefaultPort)
log.Info("Spice port range [", conf.Core.VMSpiceMinPort, "-", conf.Core.VMSpiceMaxPort, "]")
log.Info("Spice port range: ", conf.Core.VMSpiceMinPort, "-", conf.Core.VMSpiceMaxPort)
log.Info("Tmp directory: ", conf.Core.TmpDir)
log.Info("Max upload size: ", conf.Limits.MaxUploadSize)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment