Documentation ¶
Index ¶
- Constants
- func CallBrowser(url string) error
- func GeneratePassword() (pass string)
- func IsConfigVar(name string) bool
- func Luhn(number string) (int, error)
- func MakeSignupForm(creditCardForm bool) (fields map[int]form.Field, f *form.Form, signup *bool)
- func ParseDiscSpec(spec string) (*brain.Disc, error)
- func Prompt(prompt string) string
- func PromptValidate(prompt string, valid func(string) bool) (input string)
- func PromptYesNo(prompt string) bool
- func Promptf(promptFormat string, values ...interface{}) string
- func PromptfValidate(valid func(string) (bool, string), prompt string, values ...interface{}) (input string)
- func ValidCreditCard(input string) (bool, string)
- func ValidEmail(input string) (bool, string)
- func ValidExpiry(input string) (bool, string)
- func ValidName(input string) (bool, string)
- type CannotLoadDefinitionsError
- type Config
- func (config *Config) ConfigDir() string
- func (config *Config) EndpointName() string
- func (config *Config) Get(name string) (string, error)
- func (config *Config) GetAll() (vars []ConfigVar, err error)
- func (config *Config) GetBool(name string) (bool, error)
- func (config *Config) GetDebugLevel() int
- func (config *Config) GetDefault(name string) ConfigVar
- func (config *Config) GetGroup() (group *lib.GroupName)
- func (config *Config) GetIgnoreErr(name string) string
- func (config *Config) GetPath(name string) string
- func (config *Config) GetSessionValidity() (validity int, err error)
- func (config *Config) GetV(name string) (ConfigVar, error)
- func (config *Config) GetVirtualMachine() (vm *lib.VirtualMachineName)
- func (config *Config) ImportFlags(flags *flag.FlagSet) []string
- func (config *Config) PanelURL() string
- func (config *Config) Set(name, value, source string)
- func (config *Config) SetPersistent(name, value, source string) error
- func (config *Config) Unset(name string) (err error)
- type ConfigDirInvalidError
- type ConfigManager
- type ConfigReadError
- type ConfigVar
- type ConfigWriteError
- type DiscSpecError
- type DiscSpecFlag
- type ExitCode
- type FileFlag
- type IPFlag
- type InvalidConfigVarError
- type SizeSpecFlag
- type SubprocessFailedError
- type UsageDisplayedError
- type UserRequestedExit
- type WontDeleteNonEmptyGroupError
Constants ¶
const ( // ExitCodeUsageDisplayed is returned when some usage info / help page was displayed. Unsure whether it should == E_SUCCESS or not ExitCodeUsageDisplayed ExitCode = 0 // ExitCodeSuccess is used to say everything went well ExitCodeSuccess = 0 // ExitCodeTrappedInterrupt is the exit code returned when an unexpected interrupt like SIGUSR1 was trapped ExitCodeTrappedInterrupt = -1 // ExitCodeClientBug is the exit code returned when bytemark-client knows it's faulty ExitCodeClientBug = 1 // ExitCodeCantReadConfig is the exit code returned when we couldn't read a config variable from the disk for some reason ExitCodeCantReadConfig = 3 // ExitCodeCantWriteConfig is the exit code returned when we couldn't write a config variable to the disk for some reason ExitCodeCantWriteConfig = 4 // ExitCodeUserExit is the exit code returned when the user's action caused the program to terminate (usually by saying no to a prompt) ExitCodeUserExit = 5 // ExitCodeWontDeletePopulated is the exit code returned when the user's requested that a group be deleted when it still had servers in ExitCodeWontDeletePopulated = 6 // ExitCodeBadInput is the exit code returned when the user entered a malformed command, name, or flag. ExitCodeBadInput = 7 // ExitCodeSubprocessFailed 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 ExitCodeSubprocessFailed = 8 // ExitCodeNoDefaultAccount is the exit code returned when the client couldn't determine a default account. In this situation, the user should manually specify the account to use with the --account flag or using `bytemark config set account` ExitCodeNoDefaultAccount = 9 // ExitCodeUnknownError is the exit code returned when we got an error we couldn't deal with. ExitCodeUnknownError = 49 // ExitCodeCantConnectAuth is the exit code returned when we were unable to establish an HTTP connection to the auth endpoint. ExitCodeCantConnectAuth = 50 // ExitCodeCantConnectAPI is the exit code returned when we were unable to establish an HTTP connection to the API endpoint. ExitCodeCantConnectAPI = 150 // ExitCodeAuthInternalError is the exit code returned when the auth server reported an internal error. ExitCodeAuthInternalError = 51 // ExitCodeAPIInternalError is the exit code returned when the API server reported an internal error. ExitCodeAPIInternalError = 152 // ExitCodeCantParseAuthResponse is the exit code returned when the auth server returned something we were unable to parse. ExitCodeCantParseAuthResponse = 52 // ExitCodeCantParseAPIResponse is the exit code returned when the API server returned something we were unable to parse. ExitCodeCantParseAPIResponse = 152 // ExitCodeInvalidCredentials is the exit code returned when the auth server says your credentials contain invalid characters. ExitCodeInvalidCredentials = 53 // ExitCodeBadCredentials is the exit code returned when the auth server says your credentials don't match a user in its database. ExitCodeBadCredentials = 54 // ExitCodeActionNotPermitted is the exit code returned when the API server says you haven't got permission to do that. ExitCodeActionNotPermitted = 155 // ExitCodeNotFound 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. ExitCodeNotFound = 156 // ExitCodeBadRequest is the exit code returned when we send a bad request to API. (E.g. names being too short or having wrong characters in) ExitCodeBadRequest = 157 // ExitCodeUnknownAuthError is the exit code returned when we get an unexpected error from the auth server. ExitCodeUnknownAuthError = 149 // ExitCodeUnknownAPIError is the exit code returned when we get an unexpected error from the Bytemark API. ExitCodeUnknownAPIError = 249 )
const ( // FormFieldOwnerName is the index of the account owner's username field in the signup form FormFieldOwnerName = iota // FormFieldOwnerPassword is the index of the account owner's password field in the signup form FormFieldOwnerPassword // FormFieldOwnerPasswordConfirmation is the index of the account owner's password confirmation field in the signup form FormFieldOwnerPasswordConfirmation // FormFieldOwnerEmail is the index of the account owner's email address field in the signup form FormFieldOwnerEmail // FormFieldOwnerFirstName is the index of the account owner's first name field in the signup form FormFieldOwnerFirstName // FormFieldOwnerLastName is the index of the account owner's last name field in the signup form FormFieldOwnerLastName // FormFieldOwnerAddress is the index of the account owner's address field in the signup form FormFieldOwnerAddress // FormFieldOwnerCity is the index of the account owner's city field in the signup form FormFieldOwnerCity // FormFieldOwnerPostcode is the index of the account owner's postcode field in the signup form FormFieldOwnerPostcode // FormFieldOwnerCountryCode is the index of the account owner's country code field in the signup form FormFieldOwnerCountryCode // FormFieldOwnerPhoneNumber is the index of the account owner's phone number field in the signup form FormFieldOwnerPhoneNumber // FormFieldOwnerMobileNumber is the index of the account owner's mobile number field in the signup form FormFieldOwnerMobileNumber // FormFieldOwnerOrgName is the index of the account owner's organisation name field in the signup form FormFieldOwnerOrgName // FormFieldOwnerOrgDivision is the index of the account owner's organisation division field in the signup form FormFieldOwnerOrgDivision // FormFieldOwnerOrgVATNumber is the index of the account owner's organisation VAT code field in the signup form FormFieldOwnerOrgVATNumber // FormFieldCreditCardNumber is the index of the credit card number field in the signup form FormFieldCreditCardNumber // FormFieldCreditCardName is the index of the credit card full name field in the signup form FormFieldCreditCardName // FormFieldCreditCardExpiry is the index of the credit card expiry field in the signup form FormFieldCreditCardExpiry // FormFieldCreditCardCVV is the index of the credit card cvv field in the signup form FormFieldCreditCardCVV )
const DefaultSessionValidity = 1800
DefaultSessionValidity is the default for the --session-validity flag
Variables ¶
This section is empty.
Functions ¶
func CallBrowser ¶
CallBrowser opens the user's desktop browser to the given URL. It tries really hard - first trying open on mac or xdg-open on other systems. If xdg-open couldn't be used, it attempts to use /usr/bin/x-www-browser
func GeneratePassword ¶
func GeneratePassword() (pass string)
GeneratePassword generates a random 16-character password made entirely of letters.
func IsConfigVar ¶ added in v0.7.0
IsConfigVar checks to see if the named variable is actually one of the settable configVars.
func MakeSignupForm ¶ added in v0.7.0
MakeSignupForm constructs the singup form, returning a may of all the fields, the form itself and a pointer to a bool that will be true when the user has requested to sign up, and false otherwise. This is so that once the signup form exits you know whether to continue or not.
func ParseDiscSpec ¶
ParseDiscSpec reads the given string and attempts to interpret it as a disc spec.
func PromptValidate ¶ added in v0.7.0
PromptValidate prompts for input, validates it. Repeats until the input is actually valid. Returns the valid input.
func PromptYesNo ¶
PromptYesNo provides a y/n prompt. Returns true if the user enters y, false otherwise.
func Promptf ¶ added in v0.7.0
Promptf formats its arguments with fmt.Sprintf, prompts for input and then returns it.
func PromptfValidate ¶ added in v0.7.0
func PromptfValidate(valid func(string) (bool, string), prompt string, values ...interface{}) (input string)
PromptfValidate uses prompt as a format string, values as the values for the prompt, then prompts for input. The input is then validated using the validation function, and if the input is invalid, it repeats the prompting. Returns the valid input once valid input is put in.
func ValidCreditCard ¶ added in v0.7.0
ValidCreditCard is a credit-card-looking bunch of numbers. Doesn't check the check digit.
func ValidEmail ¶ added in v0.7.0
ValidEmail checks that the input looks vaguely like an email address. It's very loose, relies on better validation elsewhere.
func ValidExpiry ¶ added in v0.7.0
ValidExpiry checks that the input is a valid credit card expiry, written in MMYY format.
Types ¶
type CannotLoadDefinitionsError ¶
type CannotLoadDefinitionsError struct {
Err error
}
CannotLoadDefinitionsError is unused. Planned to be used if bytemark-client starts caching definitions, but it doesn't at the moment.
func (*CannotLoadDefinitionsError) Error ¶
func (e *CannotLoadDefinitionsError) Error() string
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 ¶
NewConfig sets up a new config struct. Pass in an empty string to default to ~/.bytemark
func (*Config) EndpointName ¶
EndpointName trims the URL scheme off the beginning of the endpoint. TODO(telyn): Why?
func (*Config) Get ¶
Get returns the value of a ConfigVar. Used to simplify code when the source is unnecessary.
func (*Config) GetBool ¶
GetBool returns the given configvar as a bool - true if it is set, not blank, and not equal to "false". false otherwise.
func (*Config) GetDebugLevel ¶
GetDebugLevel returns the current debug-level as an integer. This is used throughout the github.com/BytemarkHosting/bytemark-client library to determine verbosity of output.
func (*Config) GetDefault ¶
GetDefault returns the default ConfigVar for the given key.
func (*Config) GetIgnoreErr ¶
GetIgnoreErr returns the value of a ConfigVar or an empty string , if it was unable to read it for whatever reason.
func (*Config) GetSessionValidity ¶
GetSessionValidity returns the configured session validity or the default, if the configured one is not a valid int between 0 and infinity
func (*Config) GetVirtualMachine ¶
func (config *Config) GetVirtualMachine() (vm *lib.VirtualMachineName)
GetVirtualMachine returns a VirtualMachineName with the config's default group and account set, and a blank VirtualMachine field
func (*Config) ImportFlags ¶
ImportFlags reads all the flags from the passed FlagSet that have the same name as a valid configVar, and sets the configVar to that.
func (*Config) PanelURL ¶
PanelURL returns config's best guess at the correct URL for the bytemark panel for the cluster with the endpoint we're using. Basically it flips between panel.bytemark and panel-int.
func (*Config) Set ¶
Set stores the given key-value pair in config's Memo. This storage does not persist once the program terminates.
func (*Config) SetPersistent ¶
SetPersistent writes a file to the config directory for the given key-value pair.
type ConfigDirInvalidError ¶
type ConfigDirInvalidError struct {
Path string
}
ConfigDirInvalidError is returned when the path specified as the config dir was not a directory.
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) GetSessionValidity() (int, error) GetVirtualMachine() *lib.VirtualMachineName GetGroup() *lib.GroupName GetAll() ([]ConfigVar, error) Set(string, string, string) SetPersistent(string, string, string) error Unset(string) error GetDebugLevel() int EndpointName() string PanelURL() string ConfigDir() 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 ¶
ConfigReadError is returned when a file containing a value for a configVar couldn't be read.
func (*ConfigReadError) Error ¶
func (e *ConfigReadError) Error() string
type ConfigVar ¶
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 ¶
SourceBaseName returns the basename of the configVar's source. it's a bit stupid and so its output is only valid for configVars with SourceType() of DIR
func (*ConfigVar) SourceType ¶
SourceType returns one of the following: FLAG for a configVar whose value was set by passing a flag on the command line ENV for a configVar whose value was set from an environment variable DIR for a configVar whose value was set from a file in the config dir
type ConfigWriteError ¶
ConfigWriteError is returned when a file containing a value for a configVar couldn't be written to.
func (*ConfigWriteError) Error ¶
func (e *ConfigWriteError) Error() string
type DiscSpecError ¶
DiscSpecError represents an error during parse.
func (*DiscSpecError) Error ¶
func (e *DiscSpecError) Error() string
type DiscSpecFlag ¶
DiscSpecFlag is a flag which reads its argument as a disc spec. It can be specified multiple times to add multiple discs.
func (*DiscSpecFlag) Set ¶
func (discsFlag *DiscSpecFlag) Set(value string) error
Set adds all the defined discs to this flag's value
func (*DiscSpecFlag) String ¶
func (discsFlag *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 ¶
ProcessError processes the given error, outputs a message, and returns the relevant ExitCode for the given error.
type FileFlag ¶
FileFlag implements the flag.Value (aka urfave/cli.Generic) interface to provide a flag value type that reads its effective value from the file named as its input.
type IPFlag ¶
IPFlag is a flag.Value used to provide an array of net.IPs
type InvalidConfigVarError ¶
type InvalidConfigVarError struct {
ConfigVar string
}
InvalidConfigVarError is used to inform the user that they variable they attempted to set / get doesn't exist
func (InvalidConfigVarError) Error ¶
func (e InvalidConfigVarError) Error() string
type SizeSpecFlag ¶
type SizeSpecFlag int
SizeSpecFlag represents a capacity as an integer number of megabytes.
func (*SizeSpecFlag) Set ¶
func (ssf *SizeSpecFlag) Set(spec string) error
Set sets the value to the size specified. Users can add "M" or "G" as a suffix to specify that they are talking about megabytes/gigabytes. Gigabytes are assumed by default.
func (*SizeSpecFlag) String ¶
func (ssf *SizeSpecFlag) String() string
type SubprocessFailedError ¶
SubprocessFailedError is returned when a process run by bytemark-client (e.g. open/xdg-open to open a browser) failed
func (SubprocessFailedError) Error ¶
func (e SubprocessFailedError) Error() string
type UsageDisplayedError ¶
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{}
UserRequestedExit is returned when the user said 'No' to a 'yes/no' prompt.
func (UserRequestedExit) Error ¶
func (e UserRequestedExit) Error() string
type WontDeleteNonEmptyGroupError ¶
WontDeleteNonEmptyGroupError is returned when 'delete group' was called on a group with stuff in, without --recursive being specified
func (WontDeleteNonEmptyGroupError) Error ¶
func (e WontDeleteNonEmptyGroupError) Error() string