Documentation
¶
Index ¶
- Constants
- Variables
- func AcquireKey(ProfileName string) ([]byte, error)
- func BuildProfilePath(name string) (string, error)
- func CheckIsPiped() bool
- func CompareStrings(a, b string) int
- func DirExists(dirPath string) bool
- func FileExists(filePath string) bool
- func FileExistsInfo(filePath string) (found, isDir bool)
- func FileExistsWithDetails(filePath string) (isFound, isDir bool, err error)
- func ForcePath(p string) error
- func FormatDuration(totalTime time.Duration) string
- func GetConfigPath() (string, error)
- func GetConsoleInputChar(allowedChars string) (inputChar string, err error)
- func GetConsoleInputLine(promptText string) (inputLine string, err error)
- func GetConsoleMultipleInputLines(labelText string) (inputLines []string, err error)
- func GetConsoleRequiredInputLine(promptText, valueName string) (inputLine string, err error)
- func GetEnvSafeName(inputName string) (outputName string)
- func GetFileSafeName(inputName string) (outputName string)
- func GetPassword() ([]byte, error)
- func GetPasswordWithConfirm(label string) ([]byte, error)
- func GetRandomBytes(requestedByteCount int) (secretBytes []byte, err error)
- func InitializeClipboard() (err error)
- func MatchesFilter(value, pattern string) bool
- func ReadFromClipboard() ([]byte, error)
- func ReplaceFileExt(filePath, newExt string) string
- func WriteToClipboard(data []byte) error
- type ConfigHelper
- func (ch *ConfigHelper) GetConfigInfo() *ConfigInfo
- func (ch *ConfigHelper) GetConfigYAMLLines() ([]string, error)
- func (ch *ConfigHelper) GetCurrentProfile() *Profile
- func (ch *ConfigHelper) GetProfile(name string) *Profile
- func (ch *ConfigHelper) GetProfileYAMLLines(profileName string) ([]string, string, error)
- func (ch *ConfigHelper) ListProfiles() []Profile
- func (ch *ConfigHelper) LoadConfig() error
- func (ch *ConfigHelper) NewProfile(profile *Profile) error
- func (ch *ConfigHelper) RemoveProfile(name string) (found bool, err error)
- func (ch *ConfigHelper) RenameProfile(currentName, newName string) (found bool, err error)
- func (ch *ConfigHelper) SelectProfile(name string) error
- func (ch *ConfigHelper) WriteConfig() error
- type ConfigInfo
- type ExportOutputEncoding
- type ExportOutputTarget
- type HelpersInfo
- type ImportInputSource
- type InputResponseVal
- type Profile
- type TextScanner
- type TextWriter
- func (tw *TextWriter) Flush() (n int, err error)
- func (tw *TextWriter) PostFlushOutputBuffer() []byte
- func (tw *TextWriter) PrintFooter() error
- func (tw *TextWriter) PrintTextLine(textLine string) error
- func (tw *TextWriter) Reset(headerText, footerText string)
- func (tw *TextWriter) Write(p []byte) (n int, err error)
- type TextWriterEventFunc
- type TextWriterMode
- type TextWriterTarget
- type YAMLConfig
Constants ¶
const ( BBGLobalFolderName = "Bumblebee" BBConfigFileName = "config.yaml" )
const ( KeyPairNameForKeyStoreReads = "keystore_read" KeyPairNameForKeyStoreWrites = "keystore_write" )
const ( ExitCodeSuccess = iota ExitCodePanicInExecute ExitCodeErrorReturnedToExecute ExitCodeInvalidInput ExitCodeInputError ExitCodeCipherError ExitCodeStartupFailure ExitCodeOutputError ExitCodeRequestFailed )
A list of ExitCode value mappings to specific errors. This is useful when running this utility from a shell call or some other app.
const MAX_TRY_RECOUNTS = 5
Variables ¶
var CmdHelpers = &HelpersInfo{}
var ExitCode int = ExitCodeSuccess
ExitCode is used as the final ExitCode return by this runtime
var GlobalUseProfile string
var LineBreak string
Functions ¶
func AcquireKey ¶
AcquireKey will check to see if the key env var is available. If not, it will prompt the user for the key
func BuildProfilePath ¶
func CheckIsPiped ¶
func CheckIsPiped() bool
func CompareStrings ¶
CompareStrings is a case-insensitive comparison. Returns:
- 0 if strings are the same
- -1 if a is less than b
- 1 if a is greater than b
While strings.Equalfold is available from the standard lib, it does not tell us which value is greater than the other. This CompareStrings provides that where needed. When we only need a true/false comparison, we'll use EqualFold.
func FileExists ¶
func FileExistsInfo ¶
func FileExistsWithDetails ¶
func FormatDuration ¶
func GetConfigPath ¶
func GetConsoleInputChar ¶
func GetConsoleInputLine ¶
func GetEnvSafeName ¶
func GetFileSafeName ¶
GetFileSafeName will replace characters in the inputName that are not safe for naming directories or files. Due to cross-platform concerns, this will convert or remove things that are not within the POSIX Portable File Name character set.
func GetPassword ¶
func GetPasswordWithConfirm ¶
func GetRandomBytes ¶
func InitializeClipboard ¶
func InitializeClipboard() (err error)
func MatchesFilter ¶
MatchesFilter tests for match scenarios, where value can contain pattern, value can equal pattern, value can start with pattern, or pattern can be a regex expression applied to value
General guidelines...
- pattern starts with a !!, then the rest of pattern is a regex expression
- pattern starts AND ends with an *, then the text between the *'s should be contained in value
- pattern only ends in an *, leading portion of value must match the corresponding leading portion of pattern prior to the *
- pattern only starts with an *, then value must end with the portion of pattern up to the *, but does not have to exactly MATCH pattern
- pattern does NOT start with !! and has no * at end or beginning, then value must case-insensitive MATCH pattern
This does NOT support...
- abstract matches (*) in the middle of the match pattern
- Placeholder wildcards using ?, but might add that in the future
If the pattern start with a single "!", this is considered a NOT indicator, so that match logic is reserved post match of the remainder of the pattern text.
func ReadFromClipboard ¶
func ReplaceFileExt ¶
ReplaceFileExt will change the file extension if the filePath contains one. If it does not, it will add the extension. newExt is allowed to have a period or not, both scenarios will work correctly
func WriteToClipboard ¶
Types ¶
type ConfigHelper ¶
type ConfigHelper struct {
Config *ConfigInfo
}
var GlobalConfig *ConfigHelper
func NewConfigHelper ¶
func NewConfigHelper() *ConfigHelper
func NewConfigHelperFromConfig ¶
func NewConfigHelperFromConfig(config *ConfigInfo) *ConfigHelper
func (*ConfigHelper) GetConfigInfo ¶
func (ch *ConfigHelper) GetConfigInfo() *ConfigInfo
func (*ConfigHelper) GetConfigYAMLLines ¶
func (ch *ConfigHelper) GetConfigYAMLLines() ([]string, error)
func (*ConfigHelper) GetCurrentProfile ¶
func (ch *ConfigHelper) GetCurrentProfile() *Profile
func (*ConfigHelper) GetProfile ¶
func (ch *ConfigHelper) GetProfile(name string) *Profile
func (*ConfigHelper) GetProfileYAMLLines ¶
func (ch *ConfigHelper) GetProfileYAMLLines(profileName string) ([]string, string, error)
func (*ConfigHelper) ListProfiles ¶
func (ch *ConfigHelper) ListProfiles() []Profile
func (*ConfigHelper) LoadConfig ¶
func (ch *ConfigHelper) LoadConfig() error
func (*ConfigHelper) NewProfile ¶
func (ch *ConfigHelper) NewProfile(profile *Profile) error
func (*ConfigHelper) RemoveProfile ¶
func (ch *ConfigHelper) RemoveProfile(name string) (found bool, err error)
func (*ConfigHelper) RenameProfile ¶
func (ch *ConfigHelper) RenameProfile(currentName, newName string) (found bool, err error)
func (*ConfigHelper) SelectProfile ¶
func (ch *ConfigHelper) SelectProfile(name string) error
func (*ConfigHelper) WriteConfig ¶
func (ch *ConfigHelper) WriteConfig() error
type ConfigInfo ¶
type ConfigInfo struct { Profiles []*Profile `yaml:"profiles"` CurrentProfile string `yaml:"currentProfile"` }
func (*ConfigInfo) Clone ¶
func (configIn *ConfigInfo) Clone() (configOut *ConfigInfo)
type ExportOutputEncoding ¶
type ExportOutputEncoding int
const ( ExportOutputEncodingRaw ExportOutputEncoding = iota ExportOutputEncodingText ExportOutputEncodingUnknown )
func TextToExportOutputEncoding ¶
func TextToExportOutputEncoding(text string) ExportOutputEncoding
type ExportOutputTarget ¶
type ExportOutputTarget int
const ( ExportOutputTargetConsole ExportOutputTarget = iota ExportOutputTargetClipboard ExportOutputTargetFile ExportOutputTargetUnknown )
func TextToExportOutputTarget ¶
func TextToExportOutputTarget(text string) ExportOutputTarget
type HelpersInfo ¶
HelpersInfo is used to store the command line parameters, as well as transformed values. These are set by the cmd package/cobra, and are used or transformed in the primary logic in the encode package.
type ImportInputSource ¶
type ImportInputSource int
const ( ImportInputSourcePiped ImportInputSource = iota ImportInputSourceClipboard ImportInputSourceFile ImportInputSourceUnknown )
func TextToImportInputSource ¶
func TextToImportInputSource(text string) ImportInputSource
type InputResponseVal ¶
type InputResponseVal int
const ( InputResponseValNull InputResponseVal = iota InputResponseValYes InputResponseValNo )
func GetYesNoInput ¶
func GetYesNoInput(inputMessage string, nullVal InputResponseVal) (InputResponseVal, error)
GetYesNoInput will display an optional message and append "Yes/No", then wait for user input. If input is not valid, it will check again
type Profile ¶
type Profile struct { Name string `yaml:"name"` Path string `yaml:"path"` KeyStorePath string `yaml:"keyStore"` KeyPairStorePath string `yaml:"keyPairStore"` KeyPairStoreEncrypted bool `yaml:"keyPairStoreEncrypted"` // DefaultKeypairName is optional and is the name to use as the sender when using the default key for this profile DefaultKeypairName string `yaml:"defaultKeypairName"` }
type TextScanner ¶
type TextScanner struct {
// contains filtered or unexported fields
}
TextScanner will scan text input and parse bumblebee encrypted data. It will provide a reader interface for that parsed data.
- if no start/end tokens are encountered, it will assume the input is a single, combined data blob and serve accordingly from the read interface.
- This is NOT intended to handle vary large datasets.
func NewTextScanner ¶
func NewTextScanner(data []byte) (*TextScanner, error)
NewTextScanner will return an initialized text scanner. Data is optional. If provided, it will be passed to the Parse method.
func (*TextScanner) Parse ¶
func (ts *TextScanner) Parse(data []byte) error
Parse will try to determine the nature of the data and parse accordingly. It uses this logic:
- Does it contain the hex encoding marker ":start"? If so, parse as hexencoded
- Does it break into lines that are only valid hex characters, ignoring marker lines? If so, parse as one hex encoded combined blob
- Otherwise, parse as a binary blob
type TextWriter ¶
type TextWriter struct {
// contains filtered or unexported fields
}
func NewTextWriter ¶
func NewTextWriter( outputTarget TextWriterTarget, lineWidth int, mode TextWriterMode, headerText, footerText string, onStartFunc, afterFlushFunc TextWriterEventFunc, ) *TextWriter
func (*TextWriter) Flush ¶
func (tw *TextWriter) Flush() (n int, err error)
func (*TextWriter) PostFlushOutputBuffer ¶
func (tw *TextWriter) PostFlushOutputBuffer() []byte
OutputBuffer can only be called once, after which it will return empty bytes. This is because of how the bytes buffer works relating to calling "Bytes()" on the buffer. This includes when using the clipboard for output. After flush, the buffer is drained to the clipboard. This would then return nothing. So, only use this for buffered scenarios that are NOT related to the clipboard. And then ONLY after calling flush.
func (*TextWriter) PrintFooter ¶
func (tw *TextWriter) PrintFooter() error
func (*TextWriter) PrintTextLine ¶
func (tw *TextWriter) PrintTextLine(textLine string) error
func (*TextWriter) Reset ¶
func (tw *TextWriter) Reset(headerText, footerText string)
type TextWriterEventFunc ¶
type TextWriterEventFunc func()
var NilTextWriterEventFunc TextWriterEventFunc = nil
type TextWriterMode ¶
type TextWriterMode int
const ( TextWriterModeBinary TextWriterMode = iota TextWriterModeText )
type TextWriterTarget ¶
type TextWriterTarget int
const ( TextWriterTargetConsole TextWriterTarget = iota TextWriterTargetClipboard TextWriterTargetBuffered )
type YAMLConfig ¶
type YAMLConfig struct {
Config *ConfigInfo `yaml:"BumblebeeSettings"`
}