Documentation ¶
Overview ¶
Package util provides a multitude of support functions to help make development easier. Use of these functions should be prefered, as it allows for easier maintainence.
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 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 GenerateUniformRandMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateworstCaseNetwork(nodes int) [][]int
- func GetGateway(server int, node int) string
- func GetGateways(server int, nodes int) []string
- func GetInfoFromIP(ipStr string) (int, int)
- func GetJSONBool(data map[string]interface{}, field string, out *bool) error
- func GetJSONInt64(data map[string]interface{}, field string, out *int64) error
- func GetJSONNumber(data map[string]interface{}, field string) (json.Number, error)
- func GetJSONString(data map[string]interface{}, field string, out *string) error
- func GetJSONStringArr(data map[string]interface{}, field string, out *[]string) error
- func GetKidFromJwt(jwt string) (string, error)
- func GetNetworkAddress(server int, node int) string
- func GetNodeIP(server int, node int) string
- func GetPath(path string) string
- func GetServiceIps(services []Service) (map[string]string, error)
- 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 InetNtoa(ip uint32) string
- func JwtHTTPRequest(method string, url string, jwt string, bodyData string) (string, 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 KeyPair
- type Point
- type Resources
- type Service
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 GenerateUniformRandMeshNetwork ¶
GenerateUniformRandMeshNetwork generates a random mesh network that ensures that there is always a path between all the nodes
func GenerateworstCaseNetwork ¶
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.
func GetJSONBool ¶
GetJSONBool checks and extracts a bool from data[field]. Will return an error if data[field] does not exist or is of the wrong type.
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 GetJSONNumber ¶
GetJSONNumber checks and extracts a json.Number 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 GetJSONStringArr ¶
GetJSONStringArr 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 GetServiceIps ¶
GetServiceIps creates a map of the service names to their ip addresses. Useful for determining the ip address of a service.
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 MergeStringMaps ¶
MergeStringMaps merges two maps of string to interface together and returns it If there are conflicting keys, the value in m2 will be choosen.
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 `json:"ssh-user"` SSHKey string `json:"ssh-key"` ServerBits uint32 `json:"server-bits"` ClusterBits uint32 `json:"cluster-bits"` NodeBits uint32 `json:"node-bits"` IPPrefix uint32 `json:"ip-prefix"` Listen string `json:"listen"` Verbose bool `json:"verbose"` ThreadLimit int64 `json:"thread-limit"` DockerOutputFile string `json:"docker-output-file"` Influx string `json:"influx"` InfluxUser string `json:"influx-user"` InfluxPassword string `json:"influx-password"` ServiceNetwork string `json:"service-network"` ServiceNetworkName string `json:"service-network-name"` NodePrefix string `json:"node-prefix"` NodeNetworkPrefix string `json:"node-network-prefix"` ServicePrefix string `json:"service-prefix"` NodesPublicKey string `json:"nodes-public-key"` NodesPrivateKey string `json:"nodes-private-key"` HandleNodeSSHKeys bool `json:"handle-node-ssh-keys"` MaxNodes int `json:"max-nodes"` MaxNodeMemory string `json:"max-node-memory"` MaxNodeCPU float64 `json:"max-node-cpu"` BridgePrefix string `json:"bridge-prefix"` }
Config groups all of the global configuration parameters into a single struct
func GetConfig ¶
func GetConfig() *Config
GetConfig gets a pointer to the global config object. Do not modify c object
func (*Config) AutoFillMissing ¶
func (c *Config) AutoFillMissing()
AutoFillMissing fills in the missing essential values with the defaults.
func (*Config) LoadFromEnv ¶
func (c *Config) LoadFromEnv()
LoadFromEnv loads the configuration from the Environment
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 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 ommited, then it // is assumed to be bytes. This is not case sensitive. Memory string `json:"memory"` }
Resources represents the maximum amount of resources that a node can use.
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.