console

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package console contains the console command processor for EliasDB.

Index

Constants

View Source
const CommandExport = "export"

CommandExport is a command name.

View Source
const CommandFind = "find"

CommandFind is a command name.

View Source
const CommandGrantperm = "grantperm"

CommandGrantperm is a command name.

View Source
const CommandGroupadd = "groupadd"

CommandGroupadd is a command name.

View Source
const CommandGroupdel = "groupdel"

CommandGroupdel is a command name.

View Source
const CommandGroups = "groups"

CommandGroups is a command name.

View Source
const CommandHelp = "help"

CommandHelp is a command name.

View Source
const CommandInfo = "info"

CommandInfo is a command name.

View Source
const CommandJoingroup = "joingroup"

CommandJoingroup is a command name.

View Source
const CommandLeavegroup = "leavegroup"

CommandLeavegroup is a command name.

View Source
const CommandLogin = "login"

CommandLogin is a command name.

View Source
const CommandLogout = "logout"

CommandLogout is a command name.

View Source
const CommandNewpass = "newpass"

CommandNewpass is a command name.

View Source
const CommandPart = "part"

CommandPart is a command name.

View Source
const CommandRevokeperm = "revokeperm"

CommandRevokeperm is a command name.

View Source
const CommandUseradd = "useradd"

CommandUseradd is a command name.

View Source
const CommandUserdel = "userdel"

CommandUserdel is a command name.

View Source
const CommandUsers = "users"

CommandUsers is a command name.

View Source
const CommandVer = "ver"

CommandVer is a command name.

View Source
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

func (c *CmdExport) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdExport) Name

func (c *CmdExport) Name() string

Name returns the command name (as it should be typed)

func (*CmdExport) Run

func (c *CmdExport) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdExport) ShortDescription

func (c *CmdExport) ShortDescription() string

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

func (c *CmdFind) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdFind) Name

func (c *CmdFind) Name() string

Name returns the command name (as it should be typed)

func (*CmdFind) Run

func (c *CmdFind) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdFind) ShortDescription

func (c *CmdFind) ShortDescription() string

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

func (c *CmdGroups) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdGroups) Name

func (c *CmdGroups) Name() string

Name returns the command name (as it should be typed)

func (*CmdGroups) Run

func (c *CmdGroups) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdGroups) ShortDescription

func (c *CmdGroups) ShortDescription() string

ShortDescription returns a short description of the command (single line)

type CmdHelp

type CmdHelp struct {
}

CmdHelp displays descriptions of other commands.

func (*CmdHelp) LongDescription

func (c *CmdHelp) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdHelp) Name

func (c *CmdHelp) Name() string

Name returns the command name (as it should be typed)

func (*CmdHelp) Run

func (c *CmdHelp) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdHelp) ShortDescription

func (c *CmdHelp) ShortDescription() string

ShortDescription returns a short description of the command (single line)

type CmdInfo

type CmdInfo struct {
}

CmdInfo returns general database information.

func (*CmdInfo) LongDescription

func (c *CmdInfo) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdInfo) Name

func (c *CmdInfo) Name() string

Name returns the command name (as it should be typed)

func (*CmdInfo) Run

func (c *CmdInfo) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdInfo) ShortDescription

func (c *CmdInfo) ShortDescription() string

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

func (c *CmdLogin) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdLogin) Name

func (c *CmdLogin) Name() string

Name returns the command name (as it should be typed)

func (*CmdLogin) Run

func (c *CmdLogin) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdLogin) ShortDescription

func (c *CmdLogin) ShortDescription() string

ShortDescription returns a short description of the command (single line)

type CmdLogout

type CmdLogout struct {
}

CmdLogout placeholder for the logout command.

func (*CmdLogout) LongDescription

func (c *CmdLogout) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdLogout) Name

func (c *CmdLogout) Name() string

Name returns the command name (as it should be typed)

func (*CmdLogout) Run

func (c *CmdLogout) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdLogout) ShortDescription

func (c *CmdLogout) ShortDescription() string

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

func (c *CmdPart) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdPart) Name

func (c *CmdPart) Name() string

Name returns the command name (as it should be typed)

func (*CmdPart) Run

func (c *CmdPart) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdPart) ShortDescription

func (c *CmdPart) ShortDescription() string

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

func (c *CmdUsers) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdUsers) Name

func (c *CmdUsers) Name() string

Name returns the command name (as it should be typed)

func (*CmdUsers) Run

func (c *CmdUsers) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdUsers) ShortDescription

func (c *CmdUsers) ShortDescription() string

ShortDescription returns a short description of the command (single line)

type CmdVer

type CmdVer struct {
}

CmdVer displays descriptions of other commands.

func (*CmdVer) LongDescription

func (c *CmdVer) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdVer) Name

func (c *CmdVer) Name() string

Name returns the command name (as it should be typed)

func (*CmdVer) Run

func (c *CmdVer) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdVer) ShortDescription

func (c *CmdVer) ShortDescription() string

ShortDescription returns a short description of the command (single line)

type CmdWhoAmI

type CmdWhoAmI struct {
}

CmdWhoAmI returns the current login status.

func (*CmdWhoAmI) LongDescription

func (c *CmdWhoAmI) LongDescription() string

LongDescription returns an extensive description of the command (can be multiple lines)

func (*CmdWhoAmI) Name

func (c *CmdWhoAmI) Name() string

Name returns the command name (as it should be typed)

func (*CmdWhoAmI) Run

func (c *CmdWhoAmI) Run(args []string, capi CommandConsoleAPI) error

Run executes the command.

func (*CmdWhoAmI) ShortDescription

func (c *CmdWhoAmI) ShortDescription() string

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.

func (*CommError) Error

func (c *CommError) Error() string

Error returns a textual representation of this error.

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.

func (*EQLConsole) Run

func (c *EQLConsole) 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.

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.

func (*GraphQLConsole) Run

func (c *GraphQLConsole) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL