util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2016 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// E_USAGE_DISPLAYED is returned when some usage info / help page was displayed. Unsure whether it should == E_SUCCESS or not
	E_USAGE_DISPLAYED ExitCode = 0
	// E_SUCCESS is used to say everything went well
	E_SUCCESS = 0
	// E_TRAPPED_INTERRUPT is the exit code returned when an unexpected interrupt like SIGUSR1 was trapped
	E_TRAPPED_INTERRUPT = -1
	// E_CANT_READ_CONFIG is the exit code returned when we couldn't read a config variable from the disk for some reason
	E_CANT_READ_CONFIG = 3
	// E_CANT_WRITE_CONFIG is the exit code returned when we couldn't write a config variable to the disk for some reason
	E_CANT_WRITE_CONFIG = 4
	// E_USER_EXIT is the exit code returned when the user's action caused the program to terminate (usually by saying no to a prompt)
	E_USER_EXIT = 5
	// E_WONT_DELETE_NONEMPTY is the exit code returned when the user's requested that a group be deleted when it still had servers in
	E_WONT_DELETE_NONEMPTY = 6
	// E_PEBKAC is the exit code returned when the user entered a malformed command, name, or flag.
	E_PEBKAC = 7
	// E_SUBPROCESS_FAILED is the exit code returned when the client attempted to run a subprocess (e.g. ssh, a browser or a vpn client) but couldn't
	E_SUBPROCESS_FAILED = 8

	// E_UNKNOWN_ERROR is the exit code returned when we got an error we couldn't deal with.
	E_UNKNOWN_ERROR = 49

	// E_CANT_CONNECT_AUTH is the exit code returned when we were unable to establish an HTTP connection to the auth endpoint.
	E_CANT_CONNECT_AUTH = 50
	// E_CANT_CONNECT_API is the exit code returned when we were unable to establish an HTTP connection to the API endpoint.
	E_CANT_CONNECT_API = 150

	// E_AUTH_REPORTED_ERROR is the exit code returned when the auth server reported an internal error.
	E_AUTH_REPORTED_ERROR = 51
	// E_API_REPORTED_ERROR is the exit code returned when the API server reported an internal error.
	E_API_REPORTED_ERROR = 152

	// E_CANT_PARSE_AUTH is the exit code returned when the auth server returned something we were unable to parse.
	E_CANT_PARSE_AUTH = 52
	// E_CANT_PARSE_API is the exit code returned when the API server returned something we were unable to parse.
	E_CANT_PARSE_API = 152

	// E_CREDENTIALS_INVALID is the exit code returned when the auth server says your credentials contain invalid characters.
	E_CREDENTIALS_INVALID = 53
	// E_CREDENTIALS_WRONG is the exit code returned when the auth server says your credentials don't match a user in its database.
	E_CREDENTIALS_WRONG = 54

	// E_NOT_AUTHORIZED_API is the exit code returned when the API server says you haven't got permission to do that.
	E_NOT_AUTHORIZED_API = 155

	// E_NOT_FOUND_API is the exit code returned when the API server says you do not have permission to see the object you are trying to view, or that it does not exist.
	E_NOT_FOUND_API = 156

	// E_BAD_REQUEST_API is the exit code returned when we send a bad request to API. (E.g. names being too short or having wrong characters in)
	E_BAD_REQUEST_API = 157

	// E_UNKNOWN_AUTH is the exit code returned when we get an unexpected error from the auth server.
	E_UNKNOWN_AUTH_ERROR = 149
	// E_UNKNOWN_API_ERROR is the exit code returned when we get an unexpected error from the Bytemark API.
	E_UNKNOWN_API_ERROR = 249
)
View Source
const (
	FIELD_OWNER_NAME = iota
	FIELD_OWNER_PASS
	FIELD_OWNER_PASS_CONFIRM
	FIELD_OWNER_EMAIL
	FIELD_OWNER_FIRSTNAME
	FIELD_OWNER_LASTNAME
	FIELD_OWNER_CC
	FIELD_OWNER_POSTCODE
	FIELD_OWNER_CITY
	FIELD_OWNER_ADDRESS
	FIELD_OWNER_PHONE
	FIELD_OWNER_MOBILE
	FIELD_OWNER_ORG_NAME
	FIELD_OWNER_ORG_DIVISION
	FIELD_OWNER_ORG_VAT
	FIELD_CC_NUMBER
	FIELD_CC_NAME
	FIELD_CC_EXPIRY
	FIELD_CC_CVV
)

Variables

This section is empty.

Functions

func CallBrowser

func CallBrowser(url string) error

func EnsureAccountName

func EnsureAccountName(account string, config ConfigManager) string

func EnsureGroupName

func EnsureGroupName(group lib.GroupName, config ConfigManager) lib.GroupName

func FormatAccount

func FormatAccount(a *client.Account) string

func FormatImageInstall added in v0.7.0

func FormatImageInstall(ii *client.ImageInstall) string

func FormatVirtualMachine

func FormatVirtualMachine(vm *client.VirtualMachine, options ...int) string

FormatVirtualMachine pretty-prints a VM. The optional second argument is a bitmask of VMFormatOptions, and the optional third is the width you'd like to display..oh.

func FormatVirtualMachineSpec

func FormatVirtualMachineSpec(group *client.GroupName, spec *client.VirtualMachineSpec) string

func FormatVirtualMachines

func FormatVirtualMachines(vms []*client.VirtualMachine, options ...int) []string

FormatVirtualMachines loops through a bunch of VMs, formatting each one as it goes, and returns each formatted VM as a string. The options are the same as FormatVirtualMachine

func GeneratePassword

func GeneratePassword() (pass string)

func IsConfigVar added in v0.7.0

func IsConfigVar(name string) bool

func Luhn added in v0.7.0

func Luhn(number string) (int, error)

Luhn calculates the Luhn checksum for the given number

func MakeSignupForm added in v0.7.0

func MakeSignupForm(creditCardForm bool) (fields map[int]form.Field, f *form.Form, signup *bool)

func ParseDiscSpec

func ParseDiscSpec(spec string) (*lib.Disc, error)

func ParseSize

func ParseSize(spec string) (int, error)

ParseSize will take a size as a string like <num>[G|M][[i]B] and output a size. It's actually more permissive than that but w/e

func Prompt

func Prompt(prompt string) string

Prompt provides a string prompt, returns the entered string with no whitespace (hopefully)

func PromptValidate added in v0.7.0

func PromptValidate(prompt string, valid func(string) bool) (input string)

func PromptYesNo

func PromptYesNo(prompt string) bool

PromptYesNo provides a y/n prompt. Returns true if the user enters y, false otherwise.

func Promptf added in v0.7.0

func Promptf(promptFormat string, values ...interface{}) string

func PromptfValidate added in v0.7.0

func PromptfValidate(valid func(string) (bool, string), prompt string, values ...interface{}) (input string)

func ShiftArgument

func ShiftArgument(args *[]string, kindOfThing string) (string, bool)

func ValidCreditCard added in v0.7.0

func ValidCreditCard(input string) (bool, string)

func ValidEmail added in v0.7.0

func ValidEmail(input string) (bool, string)

func ValidExpiry added in v0.7.0

func ValidExpiry(input string) (bool, string)

func ValidName added in v0.7.0

func ValidName(input string) (bool, string)

Types

type CannotLoadDefinitionsError

type CannotLoadDefinitionsError struct {
	Err error
}

func (*CannotLoadDefinitionsError) Error

type Config

type Config struct {
	Dir         string
	Memo        map[string]ConfigVar
	Definitions map[string]string
	// contains filtered or unexported fields
}

A Config determines the configuration of the Bytemark client. It's responsible for handling things like the credentials to use and what endpoints to talk to.

Each configuration item is read from the following places, falling back to successive places:

Per-command command-line flags, global command-line flags, environment variables, configuration directory, hard-coded defaults

The location of the configuration directory is read from global command-line flags, or is otherwise ~/.bytemark

func NewConfig

func NewConfig(configDir string) (config *Config, err error)

NewConfig sets up a new config struct. Pass in an empty string to default to ~/.bytemark

func (*Config) EndpointName

func (config *Config) EndpointName() string

func (*Config) Force

func (config *Config) Force() bool

func (*Config) Get

func (config *Config) Get(name string) (string, error)

Get returns the value of a ConfigVar. Used to simplify code when the source is unnecessary.

func (*Config) GetAll

func (config *Config) GetAll() (vars []ConfigVar, err error)

GetAll returns all of the available ConfigVars in the Config.

func (*Config) GetBool

func (config *Config) GetBool(name string) (bool, error)

func (*Config) GetDebugLevel

func (config *Config) GetDebugLevel() int

GetDebugLevel returns the current debug-level as an integer. This is used throughout the bytemark.co.uk/client library to determine verbosity of output.

func (*Config) GetDefault

func (config *Config) GetDefault(name string) ConfigVar

GetDefault returns the default ConfigVar for the given key.

func (*Config) GetGroup

func (config *Config) GetGroup() (group *lib.GroupName)

func (*Config) GetIgnoreErr

func (config *Config) GetIgnoreErr(name string) string

GetIgnoreErr returns the value of a ConfigVar or an empty string , if it was unable to read it for whatever reason.

func (*Config) GetPath

func (config *Config) GetPath(name string) string

GetPath joins the given string onto the end of the Config.Dir path

func (*Config) GetV

func (config *Config) GetV(name string) (ConfigVar, error)

GetV returns the ConfigVar for the given key.

func (*Config) GetVirtualMachine

func (config *Config) GetVirtualMachine() (vm *lib.VirtualMachineName)

func (*Config) ImportFlags

func (config *Config) ImportFlags(flags *flag.FlagSet) []string

func (*Config) PanelURL

func (config *Config) PanelURL() string

func (*Config) Set

func (config *Config) Set(name, value, source string)

Set stores the given key-value pair in config's Memo. This storage does not persist once the program terminates.

func (*Config) SetPersistent

func (config *Config) SetPersistent(name, value, source string) error

SetPersistent writes a file to the config directory for the given key-value pair.

func (*Config) Silent

func (config *Config) Silent() bool

func (*Config) Unset

func (config *Config) Unset(name string) error

Unset removes the named key from both config's Memo and the user's config directory.

type ConfigDirInvalidError

type ConfigDirInvalidError struct {
	Path string
}

func (*ConfigDirInvalidError) Error

func (e *ConfigDirInvalidError) Error() string

type ConfigManager

type ConfigManager interface {
	Get(string) (string, error)
	GetIgnoreErr(string) string
	GetBool(string) (bool, error)
	GetV(string) (ConfigVar, error)
	GetVirtualMachine() *lib.VirtualMachineName
	GetGroup() *lib.GroupName
	GetAll() ([]ConfigVar, error)
	Set(string, string, string)
	SetPersistent(string, string, string) error
	Unset(string) error
	GetDebugLevel() int
	Force() bool
	EndpointName() string
	PanelURL() string

	ImportFlags(*flag.FlagSet) []string
}

ConfigManager is an interface defining a key->value store that also knows where the values were set from.

type ConfigReadError

type ConfigReadError struct {
	Name string
	Path string
	Err  error
}

func (*ConfigReadError) Error

func (e *ConfigReadError) Error() string

type ConfigVar

type ConfigVar struct {
	Name   string
	Value  string
	Source string
}

ConfigVar is a struct which contains a name-value-source triplet Source is up to two words separated by a space. The first word is the source type: FLAG, ENV, DIR, CODE. The second is the name of the flag/file/environment var used.

func (*ConfigVar) SourceBaseName

func (v *ConfigVar) SourceBaseName() string

func (*ConfigVar) SourceType

func (v *ConfigVar) SourceType() string

type ConfigWriteError

type ConfigWriteError struct {
	Name string
	Path string
	Err  error
}

func (*ConfigWriteError) Error

func (e *ConfigWriteError) Error() string

type DiscSpecError

type DiscSpecError struct {
	Position  int
	Character rune
}

DiscSpecError represents an error during parse.

func (*DiscSpecError) Error

func (e *DiscSpecError) Error() string

type DiscSpecFlag

type DiscSpecFlag []lib.Disc

func (*DiscSpecFlag) Set

func (discsFlag *DiscSpecFlag) Set(value string) error

func (*DiscSpecFlag) String

func (discFlag *DiscSpecFlag) String() string

type ExitCode

type ExitCode int

ExitCode is a named type for the E_* constants which are used as exit codes.

func HelpForExitCodes

func HelpForExitCodes() ExitCode

HelpForExitCodes prints readable information on what the various exit codes do.

func ProcessError

func ProcessError(err error, message ...string) ExitCode

type FileFlag

type FileFlag struct {
	FileName string
	Value    string
}

FileFlag implements the flag.Value (aka codegangsta/cli.Generic) interface to provide a flag value type that reads its effective value from the file named as its input.

func (*FileFlag) Set

func (f *FileFlag) Set(name string) error

func (*FileFlag) String

func (f *FileFlag) String() string

type IPFlag

type IPFlag []net.IP

func (*IPFlag) Set

func (ips *IPFlag) Set(value string) error

func (*IPFlag) String

func (ips *IPFlag) String() string

type InvalidConfigVarError

type InvalidConfigVarError struct {
	ConfigVar string
}

func (InvalidConfigVarError) Error

func (e InvalidConfigVarError) Error() string

type NotEnoughArgumentsError

type NotEnoughArgumentsError struct {
}

func (NotEnoughArgumentsError) Error

func (e NotEnoughArgumentsError) Error() string

type SizeSpecError

type SizeSpecError struct {
	Position  int
	Character rune
	Spec      string
}

func (*SizeSpecError) Error

func (e *SizeSpecError) Error() string

type SizeSpecFlag

type SizeSpecFlag int

func (*SizeSpecFlag) Set

func (ssf *SizeSpecFlag) Set(spec string) error

func (*SizeSpecFlag) String

func (ssf *SizeSpecFlag) String() string

type SubprocessFailedError

type SubprocessFailedError struct {
	Args     []string
	ExitCode int
	Err      error
}

func (*SubprocessFailedError) Error

func (e *SubprocessFailedError) Error() string

type UsageDisplayedError

type UsageDisplayedError struct {
	TheProblem string
}

UsageDisplayedError is returned by commands when the user entered wrong info and the help was output

func (UsageDisplayedError) Error

func (e UsageDisplayedError) Error() string

type UserRequestedExit

type UserRequestedExit struct{}

func (*UserRequestedExit) Error

func (e *UserRequestedExit) Error() string

type VMFormatOptions

type VMFormatOptions uint8

VMFormatOptions controls formatting of VMs in FormatVirtualMachine Add or or them together to get what you want

type VMListFormatMode

type VMListFormatMode uint8

VMListFormatMode is the way that FormatVirtualMachineList will format the VMList

type WontDeleteNonEmptyGroupError

type WontDeleteNonEmptyGroupError struct {
	Group *lib.GroupName
}

func (WontDeleteNonEmptyGroupError) Error

Jump to

Keyboard shortcuts

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