Documentation ¶
Overview ¶
Package console contains the console command processor for EliasDB.
Index ¶
- Constants
- type CmdExport
- type CmdFind
- type CmdGrantperm
- type CmdGroupadd
- type CmdGroupdel
- type CmdGroups
- type CmdHelp
- type CmdInfo
- type CmdJoingroup
- type CmdLeavegroup
- type CmdLogin
- type CmdLogout
- type CmdNewpass
- type CmdPart
- type CmdRevokeperm
- type CmdUseradd
- type CmdUserdel
- type CmdUsers
- type CmdVer
- type CmdWhoAmI
- type CommError
- type Command
- type CommandConsole
- type CommandConsoleAPI
- type EQLConsole
- type EliasDBConsole
- func (c *EliasDBConsole) AskPassword() string
- func (c *EliasDBConsole) Authenticate(force bool)
- func (c *EliasDBConsole) Commands() []Command
- func (c *EliasDBConsole) ExportBuffer() *bytes.Buffer
- func (c *EliasDBConsole) Out() io.Writer
- func (c *EliasDBConsole) Partition() string
- func (c *EliasDBConsole) Req(endpoint string, method string, content []byte) (interface{}, error)
- func (c *EliasDBConsole) Run(cmd string) (bool, error)
- func (c *EliasDBConsole) RunCommand(cmdString string) (bool, error)
- func (c *EliasDBConsole) SendRequest(endpoint string, contentType string, method string, content []byte, ...) (string, *http.Response, error)
- func (c *EliasDBConsole) SetPartition(part string)
- func (c *EliasDBConsole) URL() string
- type GraphQLConsole
Constants ¶
const CommandExport = "export"
CommandExport is a command name.
const CommandFind = "find"
CommandFind is a command name.
const CommandGrantperm = "grantperm"
CommandGrantperm is a command name.
const CommandGroupadd = "groupadd"
CommandGroupadd is a command name.
const CommandGroupdel = "groupdel"
CommandGroupdel is a command name.
const CommandGroups = "groups"
CommandGroups is a command name.
const CommandHelp = "help"
CommandHelp is a command name.
const CommandInfo = "info"
CommandInfo is a command name.
const CommandJoingroup = "joingroup"
CommandJoingroup is a command name.
const CommandLeavegroup = "leavegroup"
CommandLeavegroup is a command name.
const CommandLogin = "login"
CommandLogin is a command name.
const CommandLogout = "logout"
CommandLogout is a command name.
const CommandNewpass = "newpass"
CommandNewpass is a command name.
const CommandPart = "part"
CommandPart is a command name.
const CommandRevokeperm = "revokeperm"
CommandRevokeperm is a command name.
const CommandUseradd = "useradd"
CommandUseradd is a command name.
const CommandUserdel = "userdel"
CommandUserdel is a command name.
const CommandUsers = "users"
CommandUsers is a command name.
const CommandVer = "ver"
CommandVer is a command name.
const CommandWhoAmI = "whoami"
CommandWhoAmI is a command name.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdExport ¶
type CmdExport struct {
// contains filtered or unexported fields
}
CmdExport exports the data which is currently in the export buffer.
func (*CmdExport) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdExport) Run ¶
func (c *CmdExport) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdExport) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdFind ¶
type CmdFind struct { }
CmdFind does a full-text search of the database.
func (*CmdFind) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdFind) Run ¶
func (c *CmdFind) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdFind) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdGrantperm ¶
type CmdGrantperm struct { }
CmdGrantperm grants a new permission to a group.
func (*CmdGrantperm) LongDescription ¶
func (c *CmdGrantperm) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdGrantperm) Name ¶
func (c *CmdGrantperm) Name() string
Name returns the command name (as it should be typed)
func (*CmdGrantperm) Run ¶
func (c *CmdGrantperm) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdGrantperm) ShortDescription ¶
func (c *CmdGrantperm) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdGroupadd ¶
type CmdGroupadd struct { }
CmdGroupadd adds a new group.
func (*CmdGroupadd) LongDescription ¶
func (c *CmdGroupadd) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdGroupadd) Name ¶
func (c *CmdGroupadd) Name() string
Name returns the command name (as it should be typed)
func (*CmdGroupadd) Run ¶
func (c *CmdGroupadd) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdGroupadd) ShortDescription ¶
func (c *CmdGroupadd) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdGroupdel ¶
type CmdGroupdel struct { }
CmdGroupdel deletes a group.
func (*CmdGroupdel) LongDescription ¶
func (c *CmdGroupdel) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdGroupdel) Name ¶
func (c *CmdGroupdel) Name() string
Name returns the command name (as it should be typed)
func (*CmdGroupdel) Run ¶
func (c *CmdGroupdel) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdGroupdel) ShortDescription ¶
func (c *CmdGroupdel) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdGroups ¶
type CmdGroups struct { }
CmdGroups returns a list of all groups and their permissions.
func (*CmdGroups) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdGroups) Run ¶
func (c *CmdGroups) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdGroups) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdHelp ¶
type CmdHelp struct { }
CmdHelp displays descriptions of other commands.
func (*CmdHelp) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdHelp) Run ¶
func (c *CmdHelp) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdHelp) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdInfo ¶
type CmdInfo struct { }
CmdInfo returns general database information.
func (*CmdInfo) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdInfo) Run ¶
func (c *CmdInfo) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdInfo) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdJoingroup ¶
type CmdJoingroup struct { }
CmdJoingroup joins a user to a group.
func (*CmdJoingroup) LongDescription ¶
func (c *CmdJoingroup) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdJoingroup) Name ¶
func (c *CmdJoingroup) Name() string
Name returns the command name (as it should be typed)
func (*CmdJoingroup) Run ¶
func (c *CmdJoingroup) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdJoingroup) ShortDescription ¶
func (c *CmdJoingroup) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdLeavegroup ¶
type CmdLeavegroup struct { }
CmdLeavegroup removes a user from a group.
func (*CmdLeavegroup) LongDescription ¶
func (c *CmdLeavegroup) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdLeavegroup) Name ¶
func (c *CmdLeavegroup) Name() string
Name returns the command name (as it should be typed)
func (*CmdLeavegroup) Run ¶
func (c *CmdLeavegroup) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdLeavegroup) ShortDescription ¶
func (c *CmdLeavegroup) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdLogin ¶
type CmdLogin struct { }
CmdLogin placeholder for the login command.
func (*CmdLogin) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdLogin) Run ¶
func (c *CmdLogin) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdLogin) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdLogout ¶
type CmdLogout struct { }
CmdLogout placeholder for the logout command.
func (*CmdLogout) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdLogout) Run ¶
func (c *CmdLogout) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdLogout) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdNewpass ¶
type CmdNewpass struct { }
CmdNewpass changes the password of a user.
func (*CmdNewpass) LongDescription ¶
func (c *CmdNewpass) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdNewpass) Name ¶
func (c *CmdNewpass) Name() string
Name returns the command name (as it should be typed)
func (*CmdNewpass) Run ¶
func (c *CmdNewpass) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdNewpass) ShortDescription ¶
func (c *CmdNewpass) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdPart ¶
type CmdPart struct { }
CmdPart displays or sets the current partition.
func (*CmdPart) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdPart) Run ¶
func (c *CmdPart) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdPart) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdRevokeperm ¶
type CmdRevokeperm struct { }
CmdRevokeperm revokes permissions to a resource for a group.
func (*CmdRevokeperm) LongDescription ¶
func (c *CmdRevokeperm) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdRevokeperm) Name ¶
func (c *CmdRevokeperm) Name() string
Name returns the command name (as it should be typed)
func (*CmdRevokeperm) Run ¶
func (c *CmdRevokeperm) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdRevokeperm) ShortDescription ¶
func (c *CmdRevokeperm) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdUseradd ¶
type CmdUseradd struct { }
CmdUseradd adds a user.
func (*CmdUseradd) LongDescription ¶
func (c *CmdUseradd) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdUseradd) Name ¶
func (c *CmdUseradd) Name() string
Name returns the command name (as it should be typed)
func (*CmdUseradd) Run ¶
func (c *CmdUseradd) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdUseradd) ShortDescription ¶
func (c *CmdUseradd) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdUserdel ¶
type CmdUserdel struct { }
CmdUserdel deletes a user.
func (*CmdUserdel) LongDescription ¶
func (c *CmdUserdel) LongDescription() string
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdUserdel) Name ¶
func (c *CmdUserdel) Name() string
Name returns the command name (as it should be typed)
func (*CmdUserdel) Run ¶
func (c *CmdUserdel) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdUserdel) ShortDescription ¶
func (c *CmdUserdel) ShortDescription() string
ShortDescription returns a short description of the command (single line)
type CmdUsers ¶
type CmdUsers struct { }
CmdUsers returns a list of all users.
func (*CmdUsers) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdUsers) Run ¶
func (c *CmdUsers) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdUsers) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdVer ¶
type CmdVer struct { }
CmdVer displays descriptions of other commands.
func (*CmdVer) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdVer) Run ¶
func (c *CmdVer) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdVer) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CmdWhoAmI ¶
type CmdWhoAmI struct { }
CmdWhoAmI returns the current login status.
func (*CmdWhoAmI) LongDescription ¶
LongDescription returns an extensive description of the command (can be multiple lines)
func (*CmdWhoAmI) Run ¶
func (c *CmdWhoAmI) Run(args []string, capi CommandConsoleAPI) error
Run executes the command.
func (*CmdWhoAmI) ShortDescription ¶
ShortDescription returns a short description of the command (single line)
type CommError ¶
type CommError struct { Resp *http.Response // Error response from the REST API // contains filtered or unexported fields }
CommError is a communication error from the ConsoleAPI.
type Command ¶
type Command interface { /* Name returns the command name (as it should be typed). */ Name() string /* ShortDescription returns a short description of the command (single line). */ ShortDescription() string /* LongDescription returns an extensive description of the command (can be multiple lines). */ LongDescription() string /* Run executes the command. */ Run(args []string, capi CommandConsoleAPI) error }
Command describes an available command.
type CommandConsole ¶
type CommandConsole interface { /* Run executes one or more commands. It returns an error if the command had an unexpected result and a flag if the command was handled. */ Run(cmd string) (bool, error) /* Commands returns a sorted list of all available commands. */ Commands() []Command }
CommandConsole is the main interface for command processors.
func NewConsole ¶
func NewConsole(url string, out io.Writer, getCredentials func() (string, string), getPassword func() string, exportFunc func([]string, *bytes.Buffer) error) CommandConsole
NewConsole creates a new Console object which can parse and execute given commands from the given Reader and outputs the result to the Writer. It optionally exports data with the given export function via the save command. Export is disabled if no export function is defined.
type CommandConsoleAPI ¶
type CommandConsoleAPI interface { CommandConsole /* Authenticate authenticates the user if necessary. */ Authenticate(force bool) /* URL returns the current connection URL. */ URL() string /* Partition returns the current partition. */ Partition() string /* Sets the current partition. */ SetPartition(string) /* AskPassword asks the user for a password. */ AskPassword() string /* Req is a convenience function to send common requests. */ Req(endpoint string, method string, content []byte) (interface{}, error) /* SendRequest sends a request to the connected server. The calling code of the function can specify the contentType (e.g. application/json), the method (e.g. GET), the content (for POST, PUT and DELETE requests) and a request modifier function which can be used to modify the request object before the request to the server is being made. */ SendRequest(endpoint string, contentType string, method string, content []byte, reqMod func(*http.Request)) (string, *http.Response, error) /* Out returns a writer which can be used to write to the console. */ Out() io.Writer /* ExportBuffer returns a buffer which can be used to write exportable data. */ ExportBuffer() *bytes.Buffer }
CommandConsoleAPI is the console interface which commands can use to send communicate to the server.
type EQLConsole ¶
type EQLConsole struct {
// contains filtered or unexported fields
}
EQLConsole runs EQL queries.
func (*EQLConsole) Commands ¶
func (c *EQLConsole) Commands() []Command
Commands returns an empty list. The command line is interpreted as an EQL query.
type EliasDBConsole ¶
type EliasDBConsole struct { CommandMap map[string]Command // Map of registered commands GetCredentials func() (string, string) // Ask the user for credentials GetPassword func() string // Ask the user for a password // contains filtered or unexported fields }
EliasDBConsole implements the basic console functionality like login and version.
func (*EliasDBConsole) AskPassword ¶
func (c *EliasDBConsole) AskPassword() string
AskPassword asks the user for a password.
func (*EliasDBConsole) Authenticate ¶
func (c *EliasDBConsole) Authenticate(force bool)
Authenticate authenticates the user if necessary.
func (*EliasDBConsole) Commands ¶
func (c *EliasDBConsole) Commands() []Command
Commands returns a sorted list of all available commands.
func (*EliasDBConsole) ExportBuffer ¶
func (c *EliasDBConsole) ExportBuffer() *bytes.Buffer
ExportBuffer returns a buffer which can be used to write exportable data.
func (*EliasDBConsole) Out ¶
func (c *EliasDBConsole) Out() io.Writer
Out returns a writer which can be used to write to the console.
func (*EliasDBConsole) Partition ¶
func (c *EliasDBConsole) Partition() string
Partition returns the current partition.
func (*EliasDBConsole) Req ¶
func (c *EliasDBConsole) Req(endpoint string, method string, content []byte) (interface{}, error)
Req is a convenience function to send common requests.
func (*EliasDBConsole) Run ¶
func (c *EliasDBConsole) Run(cmd string) (bool, error)
Run executes one or more commands. It returns an error if the command had an unexpected result and a flag if the command was handled.
func (*EliasDBConsole) RunCommand ¶
func (c *EliasDBConsole) RunCommand(cmdString string) (bool, error)
RunCommand executes a single command. It returns an error for unexpected results and a flag if the command was handled.
func (*EliasDBConsole) SendRequest ¶
func (c *EliasDBConsole) SendRequest(endpoint string, contentType string, method string, content []byte, reqMod func(*http.Request)) (string, *http.Response, error)
SendRequest sends a request to the connected server. The calling code of the function can specify the contentType (e.g. application/json), the method (e.g. GET), the content (for POST, PUT and DELETE requests) and a request modifier function which can be used to modify the request object before the request to the server is being made.
func (*EliasDBConsole) SetPartition ¶
func (c *EliasDBConsole) SetPartition(part string)
SetPartition sets the current partition.
func (*EliasDBConsole) URL ¶ added in v1.0.4
func (c *EliasDBConsole) URL() string
URL returns the current connected server URL.
type GraphQLConsole ¶
type GraphQLConsole struct {
// contains filtered or unexported fields
}
GraphQLConsole runs GraphQL queries.
func (*GraphQLConsole) Commands ¶
func (c *GraphQLConsole) Commands() []Command
Commands returns an empty list. The command line is interpreted as a GraphQL query.