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

Updated commands' help to display which capabilities are required

parent 6b4367a0
No related branches found
No related tags found
No related merge requests found
Showing
with 200 additions and 85 deletions
......@@ -33,35 +33,94 @@ Usage: nexus-client CMD
CMD is the Command to run. Except for "login", all Commands require an access token.
The access token is read from the env. variable "NEXUS_TOKEN".
List of supported Commands:
login Login and obtain an access token.
whoami Display the current user's details.
passwd Update the current user's password.
userlist List users (regex matching).
useradd Add a user.
userdel Delete one or more users.
usersetcaps Set a user's capabilities.
vmlist List VMs that can be listed (regex matching).
vmliststart List VMs that can be started (regex matching).
vmlistattach List VMs that can be attached to (regex matching).
vmliststop List VMs that can be stopped or shutdown (regex matching).
vmlistedit List VMs that can be edited (regex matching).
vmlisteditaccess List VMs that can have their VM access edited (regex matching).
vmlistdel List VMs that can be deleted (regex matching).
login Obtains an access token.
Requires no capabilities.
whoami Displays the current user's details.
Requires no capabilities.
passwd Updates the current user's password.
Requires no capabilities.
userlist Lists users (regex matching).
Requires USER_LIST user capability.
useradd Adds a user.
Requires USER_CREATE user capability.
userdel Deletes one or more users.
Requires USER_DESTROY user capability.
usersetcaps Sets a user's capabilities.
Requires USER_SET_CAPS user capability.
vmlist Lists VMs that can be listed (regex matching).
Requires VM_LIST VM access capability or VM_LIST_ANY user capability.
vmliststart Lists VMs that can be started (regex matching).
Requires VM_START VM access capability or VM_START_ANY user capability.
vmlistattach Lists VMs that can be attached to (regex matching).
Requires VM_LIST VM access capability or VM_LIST_ANY user capability.
vmliststop Lists VMs that can be stopped or shutdown (regex matching).
Requires VM_STOP VM access capability or VM_STOP_ANY user capability.
vmlistedit Lists VMs that can be edited (regex matching).
Requires VM_EDIT VM access capability or VM_EDIT_ANY user capability.
vmlisteditaccess Lists VMs that can have their VM access edited (regex matching).
Requires VM_SET_ACCESS user capability and VM_SET_ACCESS VM access capability.
vmlistdel Lists VMs that can be deleted (regex matching).
Requires VM_DESTROY VM access capability or VM_DESTROY_ANY user capability.
vmlistexportdir List VMs that can have a directory exported (regex matching).
vmcred2pdf Create a PDF with the credentials required to attach to running VMs (regex matching).
vmstart Start one or more VMs (regex matching).
vmstop Stop by force one or more VMs (regex matching).
vmshutdown Gracefully shutdown one or more VMs (regex matching).
vmattach Attach to one or more VMs in order to use their desktop environment (regex matching).
vmcreate Create one or more VMs (regex matching).
vmedit Edit one or more VMs' properties: name, cpus, ram or nic (regex matching).
vmdel Delete one or more VMs (regex matching).
vmsetaccess Set a user's VM access in one or more VMs (regex matching).
vmdelaccess Delete a user's VM access in one or more VMs (regex matching).
vmexportdir Export one or more VMs' directory into one or more tar archives. Create one archive per VM (regex matching).
tpllist List available templates (regex matching).
tplcreate Create a template, either from an existing VM or from a .qcow file.
tpldel Delete one or more templates (regex matching).
Requires VM_READFS VM access capability or VM_READFS_ANY user capability.
vmcred2pdf Creates a PDF with the credentials required to attach to running VMs (regex matching).
Requires VM_LIST VM access capability or VM_LIST_ANY user capability.
vmstart Starts one or more VMs (regex matching).
Requires VM_START VM access capability or VM_START_ANY user capability.
vmstop Stops by force one or more VMs (regex matching).
Requires VM_STOP VM access capability or VM_STOP_ANY user capability.
vmshutdown Gracefully shutdowns one or more VMs (regex matching).
Requires VM_STOP VM access capability or VM_STOP_ANY user capability.
vmattach Attaches to one or more VMs in order to use their desktop environment (regex matching).
Requires VM_LIST VM access capability or VM_LIST_ANY user capability.
vmcreate Creates one or more VMs (regex matching).
Requires VM_CREATE user capability.
vmedit Edits one or more VMs' properties: name, cpus, ram or nic (regex matching).
Requires VM_EDIT VM access capability or VM_EDIT_ANY user capability.
vmdel Deletes one or more VMs (regex matching).
Requires VM_DESTROY VM access capability or VM_DESTROY_ANY user capability.
vmsetaccess Sets a user's VM access in one or more VMs (regex matching).
Requires VM_SET_ACCESS user capability and VM_SET_ACCESS VM access capability.
vmdelaccess Deletes a user's VM access in one or more VMs (regex matching).
Requires VM_SET_ACCESS user capability and VM_SET_ACCESS VM access capability.
vmexportdir Exports one or more VMs' directory into one or more tar archives.
Creates one archive per VM (regex matching).
Requires VM_READFS VM access capability or VM_READFS_ANY user capability.
tpllist Lists available templates (regex matching).
Requires TPL_LIST or TPL_LIST_ANY user capabilities.
tplcreate Creates a template, either from an existing VM or from a .qcow file.
Requires TPL_CREATE user capability.
tpldel Deletes one or more templates (regex matching).
Requires TPL_DESTROY or TPL_DESTROY_ANY user capabilities.
```
When attached to a VM's desktop (`vmattach` command), ctrl+F12 toggles between fullscreen/non-fullscreen modes.
......
......@@ -2,7 +2,7 @@ package cmd
type Command interface {
GetName() string
GetDesc() string
GetDesc() []string
PrintUsage()
Run(args []string) int // Returns 0 if the Command was successful.
}
......@@ -18,13 +18,17 @@ func (cmd *Login)GetName() string {
return cmd.Name
}
func (cmd *Login)GetDesc() string {
return "Login and obtain an access token."
func (cmd *Login)GetDesc() []string {
return []string{
"Obtains an access token.",
"Requires no capabilities."}
}
func (cmd *Login)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" email password")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name+" email password")
}
func (cmd *Login)Run(args []string) int {
......
......@@ -32,8 +32,10 @@ func (tpl *Template)String() string {
}
func printUsage(c cmd.Command, action string) {
u.PrintlnErr(c.GetDesc())
u.PrintlnErr("Usage: ",c.GetName()," [ID ...] [regex ...]")
for _, desc := range c.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: ",c.GetName()," [ID ...] [regex ...]")
u.PrintlnErr("Only templates matching the specified IDs or regexes will be "+action+".")
const usage string = `Any number of IDs or regexes can be specified.
The regex only matches the templates's name and is case-insensitive.
......
......@@ -22,13 +22,17 @@ func (cmd *Create)GetName() string {
return cmd.Name
}
func (cmd *Create)GetDesc() string {
return "Create a template, either from an existing VM or from a .qcow file."
func (cmd *Create)GetDesc() []string {
return []string{
"Creates a template, either from an existing VM or from a .qcow file.",
"Requires TPL_CREATE user capability."}
}
func (cmd *Create)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" vmID|qcowFile name access")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name+" vmID|qcowFile name access")
u.PrintlnErr("Notes: access is either \"public\" or \"private\"")
}
......
......@@ -13,8 +13,10 @@ func (cmd *Del)GetName() string {
return cmd.Name
}
func (cmd *Del)GetDesc() string {
return "Delete one or more templates (regex matching)."
func (cmd *Del)GetDesc() []string {
return []string{
"Deletes one or more templates (regex matching).",
"Requires TPL_DESTROY or TPL_DESTROY_ANY user capabilities."}
}
func (cmd *Del)PrintUsage() {
......
......@@ -8,8 +8,10 @@ func (cmd *List)GetName() string {
return cmd.Name
}
func (cmd *List)GetDesc() string {
return "List available templates (regex matching)."
func (cmd *List)GetDesc() []string {
return []string{
"Lists available templates (regex matching).",
"Requires TPL_LIST or TPL_LIST_ANY user capabilities."}
}
func (cmd *List)PrintUsage() {
......
......@@ -33,8 +33,10 @@ func (user *User)String() string {
}
func printUsage(c cmd.Command) {
u.PrintlnErr(c.GetDesc())
u.PrintlnErr("Usage: ",c.GetName()," [regex ...]")
for _, desc := range c.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: ",c.GetName()," [regex ...]")
const usage string = `Only users matching the specified regexes will be listed.
Any number of regexes can be specified.
The regex matches the user email, first name and last name and is case-insensitive.
......
......@@ -13,13 +13,17 @@ func (cmd *Add)GetName() string {
return cmd.Name
}
func (cmd *Add)GetDesc() string {
return "Add a user."
func (cmd *Add)GetDesc() []string {
return []string{
"Adds a user.",
"Requires USER_CREATE user capability."}
}
func (cmd *Add)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" email firstname lastname password [capability ...]")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name+" email firstname lastname password [capability ...]")
}
func (cmd *Add)Run(args []string) int {
......
......@@ -13,13 +13,17 @@ func (cmd *Del)GetName() string {
return cmd.Name
}
func (cmd *Del)GetDesc() string {
return "Delete one or more users."
func (cmd *Del)GetDesc() []string {
return []string{
"Deletes one or more users.",
"Requires USER_DESTROY user capability."}
}
func (cmd *Del)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" email [email ...]")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name+" email [email ...]")
}
func (cmd *Del)Run(args []string) int {
......
......@@ -8,8 +8,10 @@ func (cmd *List)GetName() string {
return cmd.Name
}
func (cmd *List)GetDesc() string {
return "List users (regex matching)."
func (cmd *List)GetDesc() []string {
return []string{
"Lists users (regex matching).",
"Requires USER_LIST user capability."}
}
func (cmd *List)PrintUsage() {
......
......@@ -13,13 +13,17 @@ func (cmd *SetCaps)GetName() string {
return cmd.Name
}
func (cmd *SetCaps)GetDesc() string {
return "Set a user's capabilities."
func (cmd *SetCaps)GetDesc() []string {
return []string{
"Sets a user's capabilities.",
"Requires USER_SET_CAPS user capability."}
}
func (cmd *SetCaps)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" email [capability ...]")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name+" email [capability ...]")
}
func (cmd *SetCaps)Run(args []string) int {
......
......@@ -18,13 +18,17 @@ func (cmd *UpdatePwd)GetName() string {
return cmd.Name
}
func (cmd *UpdatePwd)GetDesc() string {
return "Update the current user's password."
func (cmd *UpdatePwd)GetDesc() []string {
return []string{
"Updates the current user's password.",
"Requires no capabilities."}
}
func (cmd *UpdatePwd)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name)
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name)
}
func (cmd *UpdatePwd)Run(args []string) int {
......
......@@ -13,13 +13,17 @@ func (cmd *Whoami)GetName() string {
return cmd.Name
}
func (cmd *Whoami)GetDesc() string {
return "Display the current user's details."
func (cmd *Whoami)GetDesc() []string {
return []string{
"Displays the current user's details.",
"Requires no capabilities."}
}
func (cmd *Whoami)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name)
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name)
}
func (cmd *Whoami)Run(args []string) int {
......
......@@ -53,8 +53,10 @@ func (vm *VM)String() string {
}
func printRegexUsage(c cmd.Command) {
u.PrintlnErr(c.GetDesc())
u.PrintlnErr("Usage: ",c.GetName()," [ID ...] [regex ...]")
for _, desc := range c.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: ",c.GetName()," [ID ...] [regex ...]")
}
func printRegexUsageDetails() {
......
......@@ -22,8 +22,10 @@ func (cmd *Attach)GetName() string {
return cmd.Name
}
func (cmd *Attach)GetDesc() string {
return "Attach to one or more VMs in order to use their desktop environment (regex matching)."
func (cmd *Attach)GetDesc() []string {
return []string{
"Attaches to one or more VMs in order to use their desktop environment (regex matching).",
"Requires VM_LIST VM access capability or VM_LIST_ANY user capability."}
}
func (cmd *Attach)PrintUsage() {
......
......@@ -17,13 +17,17 @@ func (cmd *Create)GetName() string {
return cmd.Name
}
func (cmd *Create)GetDesc() string {
return "Create one or more VMs (regex matching)."
func (cmd *Create)GetDesc() []string {
return []string{
"Creates one or more VMs (regex matching).",
"Requires VM_CREATE user capability."}
}
func (cmd *Create)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" name cpus ram nic template [count|file.csv]")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.Name+" name cpus ram nic template [count|file.csv]")
const usage string = `name name of the VM
cpus Number of CPUs, between 1 and 16.
ram Amount of RAM in MB, between 512 and 32768.
......
......@@ -14,13 +14,17 @@ func (cmd *Cred2pdf)GetName() string {
return cmd.Name
}
func (cmd *Cred2pdf)GetDesc() string {
return "Create a PDF with the credentials required to attach to running VMs (regex matching)."
func (cmd *Cred2pdf)GetDesc() []string {
return []string{
"Creates a PDF with the credentials required to attach to running VMs (regex matching).",
"Requires VM_LIST VM access capability or VM_LIST_ANY user capability."}
}
func (cmd *Cred2pdf)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: ",cmd.GetName()," [ID ...] [regex ...] pdfile")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: ",cmd.GetName()," [ID ...] [regex ...] pdfile")
printRegexUsageDetails()
}
......
......@@ -13,8 +13,10 @@ func (cmd *Del)GetName() string {
return cmd.Name
}
func (cmd *Del)GetDesc() string {
return "Delete one or more VMs (regex matching)."
func (cmd *Del)GetDesc() []string {
return []string{
"Deletes one or more VMs (regex matching).",
"Requires VM_DESTROY VM access capability or VM_DESTROY_ANY user capability."}
}
func (cmd *Del)PrintUsage() {
......
......@@ -19,13 +19,17 @@ func (cmd *DelAccess)GetName() string {
return cmd.Name
}
func (cmd *DelAccess)GetDesc() string {
return "Delete a user's VM access in one or more VMs (regex matching)."
func (cmd *DelAccess)GetDesc() []string {
return []string{
"Deletes a user's VM access in one or more VMs (regex matching).",
"Requires VM_SET_ACCESS user capability and VM_SET_ACCESS VM access capability."}
}
func (cmd *DelAccess)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.GetName()+" [ID ...] [regex ...] email")
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] email")
const usage string = `Only VMs matching the specified IDs or regexes will have their VM access deleted.
Any number of IDs or regexes can be specified.
The regex only matches the VM's name and is case-insensitive.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment