Documentation ¶
Index ¶
- Constants
- Variables
- func ByteContainsAny(b []byte, l [][]byte) bool
- func ByteIsAny(b byte, l []byte) bool
- func BytesRoughlyContains(input, output []byte) bool
- func GetCleanFunc(platform string) func(r string) string
- func GetEnvIntOrDefault(k string, d int) int
- func GetEnvStrOrDefault(k, d string) string
- func LoadFileLines(f string) ([]string, error)
- func PlatformOK(platforms *string, platformName string) bool
- func ResolveAtFileOrURL(path string) ([]byte, error)
- func ResolveFilePath(f string) (string, error)
- func StringContainsAny(s string, l []string) bool
- func StringContainsAnySubStrs(s string, l []string) string
- func StringSliceContains(ss []string, s string) bool
- func StripANSI(b []byte) []byte
- func TextFsmParse(s, path string) ([]map[string]interface{}, error)
- func TransportOK(transports *string, transportName string) bool
- type Option
- type PayloadTestCase
- type Queue
Constants ¶
const ( // MaxTimeout is the maximum timeout value used in scrapligo. MaxTimeout = 86_400 // All used for test flags for platform/transport. All = "all" // Admin used for functional test user/pass. Admin = "admin" )
Variables ¶
var ( // ErrIgnoredOption is the error returned when attempting to apply an option to a struct that // is not of the expected type. This error should not be exposed to end users. ErrIgnoredOption = errors.New("errIgnoredOption") // ErrConnectionError is the error returned for non auth related connection failures typically // encountered during *in channel ssh authentication* -- things like host key verification // failures and other openssh errors. ErrConnectionError = errors.New("errConnectionError") // ErrBadOption is returned when a bad value is passed to an option function. ErrBadOption = errors.New("errBadOption") // ErrTimeoutError is returned for any scrapligo timeout issues, meaning socket, transport or // channel (ops) timeouts. ErrTimeoutError = errors.New("errTimeoutError") // ErrAuthError is returned if any authentication errors are returned. ErrAuthError = errors.New("errAuthError") // ErrPrivilegeError is returned if there are any issues acquiring a privilege level or a user // requests an invalid privilege level etc.. ErrPrivilegeError = errors.New("errPrivilegeError") // ErrFileNotFoundError is returned if a file cannot be found. ErrFileNotFoundError = errors.New("errFileNotFoundError") // ErrParseError is returned when parsing contents/files fails. ErrParseError = errors.New("errParseError") // ErrPlatformError is returned for any "platform" issues. ErrPlatformError = errors.New("errPlatformError") // ErrNetconfError is a blanket error for NETCONF issues that don't fall into another more // explicit error. ErrNetconfError = errors.New("errNetconfError") // ErrOperationError is returned for any "operation" issues -- mostly meaning ops timeouts. ErrOperationError = errors.New("errOperationError") // ErrNoOp is an error returned when a "no op" event happens -- that is a SendCommands or // SendConfigs method is called with an empty command/config slice provided. ErrNoOp = errors.New("errNoOp") )
Functions ¶
func ByteContainsAny ¶ added in v1.0.0
ByteContainsAny checks if byte slice b is contained in any byte slice in the slice of byte slices l.
func BytesRoughlyContains ¶ added in v1.2.0
BytesRoughlyContains returns true if all bytes from the given byte slice `input` exist in the given `output` byte slice -- the elements must be found in order. This is basically the same as what you can see in @lithammer's(1) fuzzysearch `Match` function (thank you to them!) but converted to work for bytes and to not use a continuation block. Some examples:
input 'aa', output 'b' = false input 'aa', output 'bba' = false input 'aa', output 'bbaa' = true input 'aba', output 'bba' = false
In the context of scrapligo this is basically used for "fuzzy" matching our inputs. This lets us cope with devices that do things like the following srlinux banner entry output:
``` --{ !* candidate shared default }--[ ]-- A:srl# system banner login-banner " ...my banner ...has ...some lines ...that are neat ..." --{ !* candidate shared default }--[ ]--
The "..." at the beginning of each line would historically be problematic for scrapli because in a very brute force/ham-fisted way we would demand to read back exactly what we sent to the device in the output -- so the "..." broke that. Not cool! This can be used to ensure that doesn't happen!
Note: @lithammer's fuzzy search `Match` function here: https://github.com/lithammer/fuzzysearch/blob/ \ b1f37a8c2080703d9fbd3e8989b2855c149a09e4/fuzzy/fuzzy.go#L60-L83.
func GetCleanFunc ¶ added in v1.0.0
GetCleanFunc is only used for testing -- it returns a function that "cleans" output (usually a "show run" type of output) of any data that may change over time -- things like timestamps and password hashes, this allows for comparing the stored "golden" test data against "new" output gleaned from test clab devices.
func GetEnvIntOrDefault ¶ added in v1.0.0
GetEnvIntOrDefault returns the value of the environment variable k as an int *or* the default d if casting fails or the environment variable is not set.
func GetEnvStrOrDefault ¶ added in v1.0.0
GetEnvStrOrDefault returns the value of the environment variable k as a string *or* the default d if casting fails or the environment variable is not set.
func LoadFileLines ¶
LoadFileLines convenience function to load a file and return slice of strings of lines in that file.
func PlatformOK ¶ added in v1.0.0
PlatformOK is only used for testing and checks if the cli flag platforms is either "all" or contains the requested platform name platformName.
func ResolveAtFileOrURL ¶ added in v1.0.0
ResolveAtFileOrURL returns the bytes from `path` where path is either a filepath or URL.
func ResolveFilePath ¶ added in v0.1.2
ResolveFilePath resolves the qualified path to file string f.
func StringContainsAny ¶ added in v1.0.0
StringContainsAny checks if string s is in the string slice l, this function returns a bool indicating inclusion or not.
func StringContainsAnySubStrs ¶ added in v1.0.0
StringContainsAnySubStrs checks if a string s is in the string slice l and returns the first encountered substring. If no match is encountered an empty string is returned.
func StringSliceContains ¶ added in v1.0.0
StringSliceContains checks if the string slice ss contains the substring s.
func TextFsmParse ¶ added in v1.0.0
TextFsmParse parses recorded output w/ a provided textfsm template. the argument is interpreted as URL or filesystem path, for example: response.TextFsmParse("http://example.com/textfsm.template") or response.TextFsmParse("./local/textfsm.template").
func TransportOK ¶ added in v1.0.0
TransportOK is only used for testing and checks if the cli flag transports is either "all" or contains the requested transport name transportName.
Types ¶
type Option ¶ added in v1.0.0
type Option func(interface{}) error
Option is a simple type that accepts an interface and returns an error; this should only be used in the context of applying options to an object.
type PayloadTestCase ¶ added in v1.0.0
PayloadTestCase is a simple struct used in testing only.
type Queue ¶ added in v1.0.0
type Queue struct {
// contains filtered or unexported fields
}
Queue is a simple queue structure to store and queue/requeue/dequeue bytes.
func (*Queue) DequeueAll ¶ added in v1.0.0
DequeueAll returns all bytes in the queue.