Documentation ¶
Overview ¶
Package util provides a multitude of support functions to help make development easier. Use of these functions should be preferred, as it allows for easier maintenance.
Index ¶
- Constants
- Variables
- func CombineConfig(entries []string) string
- func ConvertToStringMap(data map[string]interface{}) map[string]string
- func CopyMap(m map[string]interface{}) (map[string]interface{}, error)
- func DisplayBanner()
- func Distances(pnts []Point) [][]float64
- func Distribute(nodes []string, dist []int) ([][]string, error)
- func ExtractJwt(r *http.Request) (string, error)
- func ExtractStringMap(in map[string]interface{}, key string) (map[string]interface{}, bool)
- func FormatError(res string, err error) error
- func GenerateDependentMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateNoDuplicateMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateUniformRandMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateWorstCaseNetwork(nodes int) [][]int
- func GetGateway(server int, network int) string
- func GetGateways(server int, networks int) []string
- func GetInfoFromIP(ipStr string) (int, int, int)
- func GetJSONInt64(data map[string]interface{}, field string, out *int64) error
- func GetJSONString(data map[string]interface{}, field string, out *string) error
- func GetKidFromJwt(jwt string) (string, error)
- func GetNetworkAddress(server int, network int) string
- func GetNodeIP(server int, network int, index int) (string, error)
- func GetPath(path string) string
- func GetServiceNetwork() (string, string, error)
- func GetSubnet() int
- func GetUUIDString() (string, error)
- func GetUniqueStrings(in []string) []string
- func GetWholeNetworkIP(server int) string
- func HTTPRequest(method string, url string, bodyData string) ([]byte, error)
- func Inc(ip net.IP)
- func InetNtoa(ip uint32) string
- func JwtHTTPRequest(method string, url string, jwt string, bodyData string) (string, error)
- func LogError(err error) error
- func Lsr(_dir string) ([]string, error)
- func MergeStringMaps(m1 map[string]interface{}, m2 map[string]interface{}) map[string]interface{}
- func Rm(directories ...string) error
- func ValidNormalCharacter(chr rune) bool
- func ValidateASCII(str string) error
- func ValidateCommandLine(str string) error
- func ValidateFilePath(path string) error
- func ValidateNormalASCII(str string) error
- type Command
- type Config
- type EndPoint
- type GCPFormatter
- type KeyPair
- type Point
- type Resources
- func (res Resources) GetMemory() (int64, error)
- func (res Resources) GetParsedPortMappings() map[string]string
- func (res Resources) NoCPULimits() bool
- func (res Resources) NoLimits() bool
- func (res Resources) NoMemoryLimits() bool
- func (res Resources) Validate() error
- func (res Resources) ValidateAndSetDefaults() error
Constants ¶
const ReservedIps uint32 = 3
ReservedIps indicates the number of ip addresses reserved in a cluster's subnet
Variables ¶
var NodesPerCluster uint32
NodesPerCluster represents the maximum number of nodes allowed in a cluster
Functions ¶
func CombineConfig ¶
CombineConfig combines an Array with \n as the delimiter. Useful for generating configuration files. DEPRECATED
func ConvertToStringMap ¶
ConvertToStringMap converts a map of string to interface to a map of string to json
func Distribute ¶
Distribute generates a roughly uniform random distribution for connections among nodes.
func ExtractJwt ¶
ExtractJwt will attempt to extract and return the jwt from the auth header
func ExtractStringMap ¶ added in v1.6.5
ExtractStringMap extracts a map[string]interface from a map[string]interface
func FormatError ¶
FormatError produced a standard error for execution.
func GenerateDependentMeshNetwork ¶ added in v1.7.2
GenerateDependentMeshNetwork generates a random mesh network that ensures the if built in order, each node will be given a list of peers which is already up and running. Note: This means that the first node will have an empty list
func GenerateNoDuplicateMeshNetwork ¶ added in v1.7.2
GenerateNoDuplicateMeshNetwork generates a random mesh network that ensures that peering there is always a path between all the nodes, without any duplication. That is, if 1 contains 3, 3 won't contain 1 by elimination
func GenerateUniformRandMeshNetwork ¶
GenerateUniformRandMeshNetwork generates a random mesh network that ensures that there is always a path between all the nodes
func GenerateWorstCaseNetwork ¶ added in v1.8.2
GenerateWorstCaseNetwork generates a random path through all nodes
func GetGateway ¶
GetGateway calculates the gateway IP address for a node, base on the current IP scheme
func GetGateways ¶
GetGateways calculates the gateway IP addresses for all of the nodes on a server.
func GetInfoFromIP ¶
GetInfoFromIP returns the server number and the node number calculated from the given IPv4 address based on the current IP scheme. (server,network,index)
func GetJSONInt64 ¶
GetJSONInt64 checks and extracts a int64 from data[field]. Will return an error if data[field] does not exist or is of the wrong type.
func GetJSONString ¶
GetJSONString checks and extracts a string from data[field]. Will return an error if data[field] does not exist or is of the wrong type.
func GetKidFromJwt ¶
GetKidFromJwt will attempt to extract the kid from the given jwt
func GetNetworkAddress ¶
GetNetworkAddress gets the network address of the cluster the given node belongs to.
func GetServiceNetwork ¶
GetServiceNetwork gets the network address in CIDR of the service network
func GetUniqueStrings ¶ added in v1.6.5
GetUniqueStrings returns the given slice of strings without the duplicates
func GetWholeNetworkIP ¶ added in v1.6.5
GetWholeNetworkIP gets the network ip of the whole network for a server.
func HTTPRequest ¶ added in v1.6.5
HTTPRequest Sends a HTTP request and returns the body. Gives an error if the http request failed or returned a non success code.
func InetNtoa ¶
InetNtoa converts the IP address, given in network byte order, to a string in IPv4 dotted-decimal notation.
func JwtHTTPRequest ¶ added in v1.6.5
JwtHTTPRequest is similar to HttpRequest, but it have the content-type set as application/json and it will put the given jwt in the auth header
func LogError ¶ added in v1.7.1
LogError takes in an error, logs that error and returns that error. Used to help reduce code clutter and unify the error handling in the code. Has no effect if err == nil
func MergeStringMaps ¶
MergeStringMaps merges two maps of string to interface together and returns it If there are conflicting keys, the value in m2 will be chosen.
func ValidNormalCharacter ¶
ValidNormalCharacter checks to make sure a character is within a safe range to naively prevent most bash injects (Not for security, only for debugging)
func ValidateASCII ¶ added in v1.6.5
ValidateASCII checks if the given string only contains standard ASCII characters, which can fit in a signed char
func ValidateCommandLine ¶
ValidateCommandLine naively checks for ppntential accidental bash injections. Like ValidNormalCharacter, is not too be considered useful for security, only for picking up on potential bugs.
func ValidateFilePath ¶
ValidateFilePath check to make sure there is nothing malicous in the file path
func ValidateNormalASCII ¶ added in v1.6.5
ValidateNormalASCII is similar to ValidateAscii, except that it excludes control characters from the set of acceptable characters. Any character 127 > c > 31 is considered valid
Types ¶
type Config ¶
type Config struct { SSHUser string `mapstructure:"sshUser"` SSHKey string `mapstructure:"sshKey"` SSHHost string `mapstructure:"sshHost"` ServerBits uint32 `mapstructure:"serverBits"` ClusterBits uint32 `mapstructure:"clusterBits"` NodeBits uint32 `mapstructure:"nodeBits"` IPPrefix uint32 `mapstructure:"ipPrefix"` Listen string `mapstructure:"listen"` Verbosity string `mapstructure:"verbosity"` DockerOutputFile string `mapstructure:"dockerOutputFile"` Influx string `mapstructure:"influx"` //No default InfluxUser string `mapstructure:"influxUser"` //No default InfluxPassword string `mapstructure:"influxPassword"` //No default ServiceNetwork string `mapstructure:"serviceNetwork"` ServiceNetworkName string `mapstructure:"serviceNetworkName"` NodePrefix string `mapstructure:"nodePrefix"` NodeNetworkPrefix string `mapstructure:"nodeNetworkPrefix"` ServicePrefix string `mapstructure:"servicePrefix"` NodesPublicKey string `mapstructure:"nodesPublicKey"` //No default NodesPrivateKey string `mapstructure:"nodesPrivateKey"` //No default HandleNodeSSHKeys bool `mapstructure:"handleNodeSshKeys"` MaxNodes int `mapstructure:"maxNodes"` MaxNodeMemory string `mapstructure:"maxNodeMemory"` MaxNodeCPU float64 `mapstructure:"maxNodeCpu"` BridgePrefix string `mapstructure:"bridgePrefix"` APIEndpoint string `mapstructure:"apiEndpoint"` NibblerEndPoint string `mapstructure:"nibblerEndPoint"` LogJSON bool `mapstructure:"logJson"` PrometheusConfig string `mapstructure:"prometheusConfig"` PrometheusPort int `mapstructure:"prometheusPort"` GanacheCLIOptions string `mapstructure:"ganacheCLIOptions"` GanacheRPCPort int `mapstructure:"ganacheRPCPort"` MaxRunAttempts int `mapstructure:"maxRunAttempts"` MaxConnections int `mapstructure:"maxConnections"` DataDirectory string `mapstructure:"datadir"` DisableNibbler bool `mapstructure:"disableNibbler"` DisableTestnetReporting bool `mapstructure:"disableTestnetReporting"` RequireAuth bool `mapstructure:"requireAuth"` MaxCommandOutputLogSize int `mapstructure:"maxCommandOutputLogSize"` ResourceDir string `mapstructure:"resourceDir"` RemoveNodesOnFailure bool `mapstructure:"removeNodesOnFailure"` NibblerRetries uint `mapstructure:"nibblerRetries"` KillRetries uint `mapstructure:"killRetries"` EnablePortForwarding bool `mapstructure:"enablePortForwarding"` EnableDockerVolumes bool `mapstructure:"enableDockerVolumes"` EnableImageBuilding bool `mapstructure:"enableImageBuilding"` }
Config groups all of the global configuration parameters into a single struct
type EndPoint ¶
type EndPoint struct { URL string `json:"url"` User string `json:"user"` Pass string `json:"pass"` }
EndPoint represents an endpoint with basic auth
type GCPFormatter ¶ added in v1.8.3
type GCPFormatter struct { JSON *log.JSONFormatter ConstantFields log.Fields }
GCPFormatter enables the ability to use genesis logging with Stackdriver
type Point ¶
type Point struct { //X represents the position on the x axis X int `json:"x"` //Y represents the position on the y axis Y int `json:"y"` }
Point represents a basic 2D coordinate point
type Resources ¶
type Resources struct { // Cpus should be a floating point value represented as a string, and // is equivalent to the percentage of a single cores time which can be used // by a node. Can be more than 1.0, meaning the node can use multiple cores at // a time. Cpus string `json:"cpus"` // Memory supports values up to Terrabytes (tb). If the unit is omitted, then it // is assumed to be bytes. This is not case sensitive. Memory string `json:"memory"` // Volumes to be used by each node. Volumes []string `json:"volumes"` // Ports to be opened for each node, each item associated with one node. Ports []string `json:"ports"` // BoundCpus are the cpus which the node will be set with an affinity for. BoundCPUs []int `json:"boundCPUs,omitonempty"` }
Resources represents the maximum amount of resources that a node can use.
func (Resources) GetParsedPortMappings ¶ added in v1.8.16
GetParsedPortMappings fetches the port mappings in a form which is easy to use, using the source port as the key
func (Resources) NoCPULimits ¶ added in v1.6.5
NoCPULimits checks if the resources object doesn't specify any cpu limits
func (Resources) NoMemoryLimits ¶
NoMemoryLimits checks if the resources object doesn't specify any memory limits
func (Resources) Validate ¶
Validate ensures that the given resource object is valid, and allowable.
func (Resources) ValidateAndSetDefaults ¶
ValidateAndSetDefaults calls Validate, and if it is valid, fills any missing information. Helps to ensure that the Maximum limits are enforced.