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

nexush and nexus-cli: useradd, usersectcaps and vmaddaccess now display, in...

nexush and nexus-cli: useradd, usersectcaps and vmaddaccess now display, in the usage help, the various potential capabilities that can be used.
parent c75dda69
Branches
No related tags found
No related merge requests found
......@@ -34,13 +34,28 @@ func (cmd *Add)PrintUsage() {
u.PrintlnErr("USAGE: "+cmd.GetName()+" email firstname lastname password [capability ...]")
u.PrintlnErr(" "+cmd.GetName()+" file.csv")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
const usage string = `file.csv 5-column CSV file defining each new user:
usage := `file.csv 5-column CSV file defining each new user:
column1 email
column2 firstname
column3 lastname
column4 password
column5 capabilities (space separated)`
u.PrintlnErr(usage)
column5 capabilities (space separated)
List of user capabilities:
`
caps := caps.GetUserCapsNames()
i := 0
for _, v := range caps {
if (i == 0) {
usage += " "
}
usage += v + " "
i += 1
if (i >= 5) {
usage = u.AppendNewLine(usage)
i = 0
}
}
u.PrintErr(usage)
}
func (cmd *Add)Run(args []string) int {
......
......@@ -6,6 +6,7 @@ import (
"errors"
"strings"
"encoding/csv"
"nexus-common/caps"
"nexus-common/params"
u "nexus-client/utils"
g "nexus-client/globals"
......@@ -33,10 +34,25 @@ func (cmd *SetCaps)PrintUsage() {
u.PrintlnErr("USAGE: "+cmd.GetName()+" email [capability ...]")
u.PrintlnErr(" "+cmd.GetName()+" file.csv")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
const usage string = `file.csv 2-column CSV file specifying each user's capabilities:
usage := `file.csv 2-column CSV file specifying each user's capabilities:
column1 email
column2 capabilities (space separated)`
u.PrintlnErr(usage)
column2 capabilities (space separated)
List of user capabilities:
`
caps := caps.GetUserCapsNames()
i := 0
for _, v := range caps {
if (i == 0) {
usage += " "
}
usage += v + " "
i += 1
if (i >= 5) {
usage = u.AppendNewLine(usage)
i = 0
}
}
u.PrintErr(usage)
}
func (cmd *SetCaps)Run(args []string) int {
......
......@@ -35,11 +35,26 @@ func (cmd *AddAccess)PrintUsage() {
u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] email [capability ...]")
u.PrintlnErr(" "+cmd.GetName()+" file.csv")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
const usage string = `file.csv 3-column CSV file specifying which VMs must have which VM access added:
usage := `file.csv 3-column CSV file specifying which VMs must have which VM access added:
column1 VM ID
column2 email for which the VM Access must be removed
column3 capabilities (space separated)`
u.PrintlnErr(usage)
column3 capabilities (space separated)
List of VM access capabilities:
`
caps := caps.GetVMAccessCapsNames()
i := 0
for _, v := range caps {
if (i == 0) {
usage += " "
}
usage += v + " "
i += 1
if (i >= 5) {
usage = u.AppendNewLine(usage)
i = 0
}
}
u.PrintErr(usage)
printRegexUsageDetails()
}
......
......@@ -41,7 +41,7 @@ replace nexus-client/cmdVersion => ../cmdVersion
require (
github.com/go-resty/resty/v2 v2.12.0
github.com/peterh/liner v1.2.2
golang.org/x/term v0.18.0
golang.org/x/term v0.19.0
nexus-client/cmd v0.0.0-00010101000000-000000000000
nexus-client/cmdLogin v0.0.0-00010101000000-000000000000
nexus-client/cmdMisc v0.0.0-00010101000000-000000000000
......@@ -62,9 +62,9 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
nexus-client/exec v0.0.0-00010101000000-000000000000 // indirect
nexus-common/caps v0.0.0-00010101000000-000000000000 // indirect
nexus-common/params v0.0.0-00010101000000-000000000000 // indirect
......
......@@ -40,6 +40,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
......@@ -55,6 +57,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
......@@ -71,6 +75,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
......@@ -79,6 +85,8 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
......
......@@ -75,6 +75,9 @@ var prompt *liner.State = nil
var savedTermState *term.State = nil
func run() int {
cmdList[18].PrintUsage()
os.Exit(0)
var appname = path.Base(os.Args[0])
u.PrintlnErr(appname+" version "+version.Get().String())
......
......@@ -135,3 +135,10 @@ func FileToString(file string) (string, error) {
func RemoveArgAtIndex(slice []string, index int) []string {
return append(slice[:index], slice[index+1:]...)
}
// TODO: better way of appending a portable "new line" to a string
func AppendNewLine(s string) string {
var newLine string
newLine = fmt.Sprintln(newLine, "")
return s+newLine
}
......@@ -78,7 +78,7 @@ var userCaps = Capabilities {
}
// Capabilities stored in the VM config (access)
var VMAccessCaps = Capabilities {
var vmAccessCaps = Capabilities {
CAP_VM_SET_ACCESS: 1,
CAP_VM_DESTROY: 1,
CAP_VM_EDIT: 1,
......@@ -99,7 +99,7 @@ func IsUserCapValid(cap string) bool {
// Returns true if the string cap matches a VM access capability
func IsVMAccessCapValid(cap string) bool {
_, exists := VMAccessCaps[cap]
_, exists := vmAccessCaps[cap]
return exists
}
......@@ -122,3 +122,19 @@ func ValidateVMAccessCaps(caps Capabilities) error {
}
return nil
}
func GetUserCapsNames() []string {
caps := []string{}
for key, _ := range userCaps {
caps = append(caps, key)
}
return caps
}
func GetVMAccessCapsNames() []string {
caps := []string{}
for key, _ := range vmAccessCaps {
caps = append(caps, key)
}
return caps
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment