utils

package
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OS_READ        = 04
	OS_WRITE       = 02
	OS_EX          = 01
	OS_USER_SHIFT  = 6
	OS_GROUP_SHIFT = 3
	OS_OTH_SHIFT   = 0

	OS_USER_X  = OS_EX << OS_USER_SHIFT
	OS_GROUP_X = OS_EX << OS_GROUP_SHIFT
	OS_OTH_X   = OS_EX << OS_OTH_SHIFT
	OS_ALL_X   = OS_USER_X | OS_GROUP_X | OS_OTH_X
)

Variables

View Source
var (
	// ErrCouldNotExtract occurs when an extraction fails.
	ErrCouldNotExtract = errors.New("could not extract the archive")
	ErrRequestCanceled = errors.New("request conceled")

	// ErrExtractedFileTooBig occurs when a file to extract is too big.
	ErrExtractedFileTooBig = errors.New("could not extract one or more files from the archive: file too big")

	ErrCouldNotWriteToDisk = errors.New("could not write to disk")
)
View Source
var AppNameMap map[uint32]string = map[uint32]string{
	C.DPI_APP_HTTP:          "HTTP",
	C.DPI_APP_SSL:           "SSL",
	C.DPI_APP_SSH:           "SSH",
	C.DPI_APP_DNS:           "DNS",
	C.DPI_APP_DHCP:          "DHCP",
	C.DPI_APP_NTP:           "NTP",
	C.DPI_APP_TFTP:          "TFTP",
	C.DPI_APP_ECHO:          "Echo",
	C.DPI_APP_RTSP:          "RTSP",
	C.DPI_APP_SIP:           "SIP",
	C.DPI_APP_MYSQL:         "MySQL",
	C.DPI_APP_REDIS:         "Redis",
	C.DPI_APP_ZOOKEEPER:     "ZooKeeper",
	C.DPI_APP_CASSANDRA:     "Cassandra",
	C.DPI_APP_MONGODB:       "MongoDB",
	C.DPI_APP_POSTGRESQL:    "PostgreSQL",
	C.DPI_APP_KAFKA:         "Kafka",
	C.DPI_APP_COUCHBASE:     "Couchbase",
	C.DPI_APP_WORDPRESS:     "Wordpress",
	C.DPI_APP_ACTIVEMQ:      "ActiveMQ",
	C.DPI_APP_COUCHDB:       "CouchDB",
	C.DPI_APP_ELASTICSEARCH: "ElasticSearch",
	C.DPI_APP_MEMCACHED:     "Memcached",
	C.DPI_APP_RABBITMQ:      "RabbitMQ",
	C.DPI_APP_RADIUS:        "Radius",
	C.DPI_APP_VOLTDB:        "VoltDB",
	C.DPI_APP_CONSUL:        "Consul",
	C.DPI_APP_SYSLOG:        "Syslog",
	C.DPI_APP_ETCD:          "etcd",
	C.DPI_APP_SPARK:         "Spark",
	C.DPI_APP_APACHE:        "Apache",
	C.DPI_APP_NGINX:         "nginx",
	C.DPI_APP_JETTY:         "Jetty",
	C.DPI_APP_TNS:           "Oracle",
	C.DPI_APP_TDS:           "MSSQL",
	C.DPI_APP_GRPC:          "GRPC",
}

Utilities: find group attribute from the grou's name definitions, based on controller/api/apis.go

View Source
var IPv4Loopback = net.IPv4(127, 0, 0, 1)

Functions

func BenchStatusToStr

func BenchStatusToStr(r share.BenchStatus) string

func CompareSliceWithoutOrder

func CompareSliceWithoutOrder(a, b interface{}) bool

func Decrypt

func Decrypt(encryptionKey, text []byte) ([]byte, error)

func DecryptForURL

func DecryptForURL(key []byte, b64 string) (string, error)

func DecryptFromBase64

func DecryptFromBase64(encryptionKey []byte, b64 string) (string, error)

func DecryptPassword

func DecryptPassword(encrypted string) string

func DecryptPasswordForURL

func DecryptPasswordForURL(encrypted string) string

func DecryptSensitiveForURL

func DecryptSensitiveForURL(encrypted string, key []byte) string

func DoesGroupHavePolicyMode

func DoesGroupHavePolicyMode(name string) bool

func Encrypt

func Encrypt(encryptionKey, text []byte) ([]byte, error)

func EncryptForURL

func EncryptForURL(key, text []byte) (string, error)

func EncryptPassword

func EncryptPassword(password string) string

func EncryptPasswordForURL

func EncryptPasswordForURL(password string) string

func EncryptSensitiveForURL

func EncryptSensitiveForURL(data string, key []byte) string

func EncryptToBase64

func EncryptToBase64(encryptionKey, text []byte) (string, error)

func EnsureBaseDir

func EnsureBaseDir(fpath string) error

func EvaluateApiCfgType

func EvaluateApiCfgType(name string, bCrdType bool) string

func EvaluateGroupType

func EvaluateGroupType(name string) share.TCfgType

func Exec

func Exec(dir string, bin string, args ...string) ([]byte, error)

Exec runs the given binary with arguments

func ExtractAllArchive

func ExtractAllArchive(dst string, r io.Reader, maxFileSize int64) (int64, error)

func ExtractAllArchiveToFiles

func ExtractAllArchiveToFiles(path string, r io.Reader, maxFileSize int64, encryptKey []byte) error

func FileHashCrc32

func FileHashCrc32(path string, size int64) uint32

func FilterIndexKey

func FilterIndexKey(path, regex string) string

func GetAppIDByName

func GetAppIDByName(name string) uint32

func GetCVEDBEncryptKey

func GetCVEDBEncryptKey() []byte

func GetCaller

func GetCaller(skip int, excludes []string) string

func GetFileContentType

func GetFileContentType(buffer []byte) string

GetFileContentType: explore the content type, only work content at least 512 bytes

func GetFunctionName

func GetFunctionName(f interface{}) string

func GetGID

func GetGID() uint64

Should only use for debugging

func GetGuid

func GetGuid() (string, error)

func GetIPEnclosure

func GetIPEnclosure(ips []net.IP) *net.IPNet

func GetLicenseInfo

func GetLicenseInfo(license string) (string, error)

func GetLicenseSymKey

func GetLicenseSymKey() []byte

func GetMd5

func GetMd5(s string) string
func GetPortLink(ipproto uint8, port uint16) string
func GetPortRangeLink(ipproto uint8, port uint16, portR uint16) string

func GetRandomID

func GetRandomID(length int, prefix string) string

func GetStringUUID

func GetStringUUID(s string) string

func GetSupportedTLSCipherSuites

func GetSupportedTLSCipherSuites() []uint16

func GetTimeUUID

func GetTimeUUID(t time.Time) string

func GunzipBytes

func GunzipBytes(buf []byte) []byte

func GzipBytes

func GzipBytes(buf []byte) []byte

func HasGroupProfiles

func HasGroupProfiles(name string) bool

func HashPassword

func HashPassword(password string) string

func HashStringToInt32

func HashStringToInt32(s string, slots int) int

func Htonl

func Htonl(v uint32) uint32

func IPNet2Subnet

func IPNet2Subnet(ipnet *net.IPNet) *net.IPNet

func IPNet2SubnetLoose

func IPNet2SubnetLoose(ipnet *net.IPNet, scope string) *net.IPNet

func IPv42Int

func IPv42Int(ip net.IP) uint32

func Int2IPv4

func Int2IPv4(addr uint32) net.IP

func InterpretIP

func InterpretIP(ip, ipR net.IP) string

func IsCustomProfileGroup

func IsCustomProfileGroup(group string) bool

func IsExecutable

func IsExecutable(info os.FileInfo, path string) bool

func IsExecutableLinkableFile

func IsExecutableLinkableFile(path string) bool

IsExecutableLinkableFile: explore ELF header

func IsGroupLearned

func IsGroupLearned(name string) bool

func IsGroupNodes

func IsGroupNodes(name string) bool

func IsIPv4

func IsIPv4(ip net.IP) bool

func IsIPv6

func IsIPv6(ip net.IP) bool

func IsMountPoint

func IsMountPoint(path string) bool

Determine if a directory is a mountpoint, by comparing the device for the directory with the device for it's parent. If they are the same, it's not a mountpoint, if they're different, it is.

func IsNativeLittleEndian

func IsNativeLittleEndian() bool

func JoinCommand

func JoinCommand(cmds []string) string

func MakeServiceName

func MakeServiceName(namespace, name string) string

func MakeTar

func MakeTar(files []TarFileInfo) (*bytes.Buffer, error)

func MakeUserFullname

func MakeUserFullname(server, username string) string

func MergeSpecialSubnet

func MergeSpecialSubnet(subnets map[string]share.CLUSSpecSubnet, snet share.CLUSSubnet, iptype string) bool

func MergeSubnet

func MergeSubnet(subnets map[string]share.CLUSSubnet, snet share.CLUSSubnet) bool

func NormalizeForURL

func NormalizeForURL(name string) string

func ParseIPRange

func ParseIPRange(value string) (net.IP, net.IP)
func ParsePortRangeLink(name string) (uint8, uint16, uint16, error)

func PerfProfile

func PerfProfile(req *share.CLUSProfilingRequest, prefix string)

func Proto2Name

func Proto2Name(ipproto uint8) string

func ResolveAddrList

func ResolveAddrList(addr string, skipLoopback bool) ([]string, bool)

func ResolveIP

func ResolveIP(name string) ([]net.IP, error)

func ReverseBytesInPlace

func ReverseBytesInPlace(a []byte) []byte

func SelectivelyExtractArchive

func SelectivelyExtractArchive(r io.Reader, selected func(string) bool, maxFileSize int64) (map[string][]byte, error)

SelectivelyExtractArchive extracts the specified files and folders from targz data read from the given reader and store them in a map indexed by file paths

func SelectivelyExtractModules

func SelectivelyExtractModules(r io.Reader, lastfix string, maxFileSize int64) (map[string][]byte, error)

func SelectivelyExtractToFile

func SelectivelyExtractToFile(r io.Reader, selected func(string) bool, dir string) (map[string]string, error)

func SelectivelyExtractToFile(r io.Reader, prefix string, toExtract []string, dir string) (map[string]string, error) {

func SelectivelyExtractToFiles

func SelectivelyExtractToFiles(r io.Reader, dir string, selected func(string) bool, maxFileSize int64) (map[string]string, error)

func SetReady

func SetReady(value string) error

func SubnetContains

func SubnetContains(n1, n2 *net.IPNet) (bool, int)

The first value indicate if two subnets contains one or another, if true then, the second value returns 1 if n1 contains n2, -1 if n2 contains n1, 0 if equal.

func TCPStateString

func TCPStateString(state uint8) string

func UnsetReady

func UnsetReady() error

func Unzip

func Unzip(src string, dest string) error

Unzip will decompress a zip archive, moving all files and folders within the zip file (parameter 1) to an output directory (parameter 2).

func UnzipDataIfValid

func UnzipDataIfValid(value []byte) ([]byte, bool)

Types

type EnvironParser

type EnvironParser struct {
	// contains filtered or unexported fields
}

func NewEnvironParser

func NewEnvironParser(envs []string) *EnvironParser

func (EnvironParser) GetKVPairs

func (p EnvironParser) GetKVPairs() map[string]string

func (EnvironParser) GetPlatformEnv

func (p EnvironParser) GetPlatformEnv() map[string][]string

func (EnvironParser) GetPlatformIntf

func (p EnvironParser) GetPlatformIntf(port string) []string

func (EnvironParser) GetPlatformName

func (p EnvironParser) GetPlatformName() (string, string)

func (EnvironParser) GetSystemGroups

func (p EnvironParser) GetSystemGroups() []*regexp.Regexp

func (EnvironParser) Value

func (p EnvironParser) Value(key string) (string, bool)

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

type LogFormatter

type LogFormatter struct {
	Module string
}

func (*LogFormatter) Format

func (f *LogFormatter) Format(entry *log.Entry) ([]byte, error)

type Set

type Set interface {
	// Adds an element to the set. Returns whether
	// the item was added.
	Add(i interface{}) bool

	// Returns the number of elements in the set.
	Cardinality() int

	// Removes all elements from the set, leaving
	// the emtpy set.
	Clear()

	// Returns a clone of the set using the same
	// implementation, duplicating all keys.
	Clone() Set

	// Returns whether the given items
	// are all in the set.
	Contains(i ...interface{}) bool

	// Returns the difference between this set
	// and other. The returned set will contain
	// all elements of this set that are not also
	// elements of other.
	//
	// Note that the argument to Difference
	// must be of the same type as the receiver
	// of the method. Otherwise, Difference will
	// panic.
	Difference(other Set) Set

	// Determines if two sets are equal to each
	// other. If they have the same cardinality
	// and contain the same elements, they are
	// considered equal. The order in which
	// the elements were added is irrelevant.
	//
	// Note that the argument to Equal must be
	// of the same type as the receiver of the
	// method. Otherwise, Equal will panic.
	Equal(other Set) bool

	// Returns a new set containing only the elements
	// that exist only in both sets.
	//
	// Note that the argument to Intersect
	// must be of the same type as the receiver
	// of the method. Otherwise, Intersect will
	// panic.
	Intersect(other Set) Set

	// Determines if every element in the other set
	// is in this set.
	//
	// Note that the argument to IsSubset
	// must be of the same type as the receiver
	// of the method. Otherwise, IsSubset will
	// panic.
	IsSubset(other Set) bool

	// Determines if every element in this set is in
	// the other set.
	//
	// Note that the argument to IsSuperset
	// must be of the same type as the receiver
	// of the method. Otherwise, IsSuperset will
	// panic.
	IsSuperset(other Set) bool

	// Returns a channel of elements that you can
	// range over.
	Iter() threadUnsafeSet

	// Remove a single element from the set.
	Remove(i interface{})

	// Provides a convenient string representation
	// of the current state of the set.
	String() string

	// Returns a new set with all elements which are
	// in either this set or the other set but not in both.
	//
	// Note that the argument to SymmetricDifference
	// must be of the same type as the receiver
	// of the method. Otherwise, SymmetricDifference
	// will panic.
	SymmetricDifference(other Set) Set

	// Returns a new set with all elements in both sets.
	//
	// Note that the argument to Union must be of the
	// same type as the receiver of the method.
	// Otherwise, IsSuperset will panic.
	Union(other Set) Set

	// Returns the members of the set as a slice.
	ToSlice() []interface{}
	ToInt32Slice() []int32
	ToStringSlice() []string

	// Returns one member of the set.
	Any() interface{}
}

func NewSet

func NewSet(s ...interface{}) Set

func NewSetFromSlice

func NewSetFromSlice(s []interface{}) Set

func NewSetFromSliceKind

func NewSetFromSliceKind(slice interface{}) Set

type TarFileInfo

type TarFileInfo struct {
	Name string
	Body []byte
}

type TarReadCloser

type TarReadCloser struct {
	*tar.Reader
	io.Closer
}

TarReadCloser embeds a *tar.Reader and the related io.Closer It is the caller's responsibility to call Close on TarReadCloser when done.

func (*TarReadCloser) Close

func (r *TarReadCloser) Close() error

type TimerTask

type TimerTask interface {
	Expire()
}

type TimerWheel

type TimerWheel struct {
	// contains filtered or unexported fields
}

func NewTimerWheel

func NewTimerWheel() *TimerWheel

func NewTimerWheelWithTick

func NewTimerWheelWithTick(tick time.Duration) *TimerWheel

func (*TimerWheel) AddTask

func (t *TimerWheel) AddTask(task TimerTask, delay time.Duration) (string, error)

func (*TimerWheel) RemoveTask

func (t *TimerWheel) RemoveTask(taskId string) error

func (*TimerWheel) Start

func (t *TimerWheel) Start()

func (*TimerWheel) Stop

func (t *TimerWheel) Stop()

type WheelTimeOut

type WheelTimeOut struct {
	// contains filtered or unexported fields
}

type XzReader

type XzReader struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

XzReader is an io.ReadCloser which decompresses xz compressed data.

func NewXzReader

func NewXzReader(r io.Reader) (*XzReader, error)

NewXzReader shells out to a command line xz executable (if available) to decompress the given io.Reader using the xz compression format and returns an *XzReader. It is the caller's responsibility to call Close on the XzReader when done.

func (*XzReader) Close

func (r *XzReader) Close() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL