utils

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 31 Imported by: 59

Documentation

Index

Constants

View Source
const (
	Rhel = iota
	Debian
	Darwin
)
View Source
const DefaultProcMount = "/proc/mounts"
View Source
const DefaultTLSMinVersion = "VersionTLS12"

DefaultTLSMinVersion minimum TLS version supported

View Source
const LOGSTASH_CONTAINER_DIRECTORY = "/usr/local/serviced/resources/logstash"

The container-local path to the directory for logstash/filebeat configuration. This directory is bind mounted into both isvcs and service containers

View Source
const LOGSTASH_LOCAL_SERVICED_LOG_DIR = "/var/log/serviced"

The container-local path to the directory logstash uses to write application audit logs

View Source
const RESOURCES_CONTAINER_DIRECTORY = "/usr/local/serviced/resources"

The container-local path to the resources directory. This directory is bind mounted into both isvcs and service containers

Variables

View Source
var (

	// ErrInvalidTCPAddress is thrown when a specified address can't be packed
	ErrInvalidTCPAddress = errors.New("Invalid TCP address")
)
View Source
var (
	ErrParseMount = errors.New("could not parse mount data")
)
View Source
var Platform = determinePlatform()

Functions

func AttachAndExec

func AttachAndExec(containerID string, bashcmd []string) error

AttachAndExec attaches to a container and execs the command

func AttachAndRun

func AttachAndRun(containerID string, bashcmd []string) ([]byte, error)

AttachAndRun attaches to a container and runs the command

func Base62

func Base62(n uint) string

func CipherSuites

func CipherSuites(connectionType string) []uint16

CipherSuites the ciphers that can be sued

func CipherSuitesByName

func CipherSuitesByName(c *tls.Config) []string

func CompareVersions

func CompareVersions(v1, v2 string) int

Compare two version strings by splitting by '.', making the slices the same length, then padding the strings with 0's. The string comparison will now work against numeric versioning, as well as "1.5.2b1" style strings.

func ConvertUp

func ConvertUp(oldNumber string, baseAlphabet string) string

ConvertUp converts a hexadecimal UUID string to a base alphabet greater than 16.

func DockerIsLoggedIn

func DockerIsLoggedIn() bool

func ExecDockerExec

func ExecDockerExec(containerID string, bashcmd []string) error

ExecDockerExec execs the command using docker exec

func GetCipherName

func GetCipherName(cipher uint16) string

Get the name of the cipher

func GetDefaultCiphers

func GetDefaultCiphers(connectionType string) []string

GetDefaultCiphers returns the default tls ciphers

func GetExitStatus

func GetExitStatus(err error) (int, bool)

GetExitStatus tries to extract the exit code from an error

func GetGateway

func GetGateway(defaultRPCPort int) string

GetGateway returns the default gateway

func GetIPAddress

func GetIPAddress() (ip string, err error)

GetIPAddress attempts to find the IP address to the default outbound interface.

func GetIPv4Addresses

func GetIPv4Addresses() (ips []string, err error)

GetIPAddresses returns a list of all IPv4 interface addresses

func GetMemorySize

func GetMemorySize() (size uint64, err error)

GetMemorySize attempts to get the size of the installed RAM.

func HostID

func HostID() (hostid string, err error)

HostID retrieves the system's unique id, on linux this maps to /usr/bin/hostid.

func InterfaceArrayToStringArray

func InterfaceArrayToStringArray(inArray []interface{}) ([]string, bool)

Extract all strings from an array of interfaces. If the input array contains items that are not strings, set the output flag (allConverted) to false.

func IsNFSMountStale

func IsNFSMountStale(mountpoint string) bool

func Isatty

func Isatty(f *os.File) bool

Isatty returns true if f is a TTY, false otherwise.

func LocalDir

func LocalDir(p string) string

LocalDir gets the absolute path to a particular directory under ServiceDHome if SERVICED_HOME is not defined then we use the location of the caller

func LockFile

func LockFile(filelockpath string) (*os.File, error)

LockFile opens and locks the file at the given path - it will block and wait for unlock

func MinTLS

func MinTLS(connectionType string) uint16

MinTLS the min tls version that can be used for a given connection type

func NewUUID

func NewUUID() (string, error)

NewUUID generate a new UUID

func NewUUID36

func NewUUID36() (string, error)

NewUUID36 returns a base-36 UUID with no dashes.

func NewUUID62

func NewUUID62() (string, error)

NewUUID62 returns a base-36 UUID with no dashes.

func PackTCPAddress

func PackTCPAddress(ip string, port uint16) ([]byte, error)

PackTCPAddress packs a TCP address (IP and port) to 6 bytes

func PackTCPAddressString

func PackTCPAddressString(address string) ([]byte, error)

PackTCPAddressString packs a TCP address represented as a string ("IP:port") to 6 bytes

func ParseEngineeringNotation

func ParseEngineeringNotation(in string) (uint64, error)

func ParsePercentage

func ParsePercentage(in string, value uint64) (uint64, error)

func ResourcesDir

func ResourcesDir() string

ResourcesDir points to internal services resources directory

func RunDockerExec

func RunDockerExec(containerID string, bashcmd []string) ([]byte, error)

RunDockerExec runs the command using docker exec

func RunTTL

func RunTTL(ttl TTL, cancel <-chan interface{}, min, max time.Duration)

RunTTL purges expired data based upon the time interval

func ServiceDHome

func ServiceDHome() string

ServiceDHome gets the home location of serviced by looking at the environment

func ServicedLogDir

func ServicedLogDir() string

ServicedLogDir gets the serviced log directory

func SetCiphers

func SetCiphers(connectionType string, cipherNames []string) error

SetCiphers that can be used

func SetMinTLS

func SetMinTLS(connectionType string, version string) error

SetMinTLS the min tls that can be used

func SetSysctl

func SetSysctl(key string, value string) ([]byte, error)

SetSysctl tries to set sysctl settings

func ShellQuoteArg

func ShellQuoteArg(arg string) string

Quote a single argument

func ShellQuoteArgs

func ShellQuoteArgs(args []string) string

Quote a list of arguments and join them with spaces

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice test if a string exists in a slice

func StringSliceEquals

func StringSliceEquals(lhs []string, rhs []string) bool

StringSliceEquals compare two string slices for equality

func TempDir

func TempDir(p string) string

TempDir gets the temp serviced directory

func UnpackTCPAddress

func UnpackTCPAddress(packed []byte) (ip string, port uint16)

UnpackTCPAddress unpacks a 6-byte representation of a TCP address produced by PackTCPAddress into an IP and port

func UnpackTCPAddressToString

func UnpackTCPAddressToString(packed []byte) string

UnpackTCPAddressToString unpacks a 6-byte representation of a TCP address produced by PackTCPAddress into a string of the format "IP:port"

Types

type ChannelCond

type ChannelCond struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ChannelCond provides functionality similar to sync.Cond, but is backed by channels instead of a mutex, allowing it to support timeouts and cancellation.

func NewChannelCond

func NewChannelCond() *ChannelCond

NewChannelCond returns a new ChannelCond

func (*ChannelCond) Broadcast

func (c *ChannelCond) Broadcast()

Broadcast notifies all waiting goroutines that this condition has been satisfied

func (*ChannelCond) Wait

func (c *ChannelCond) Wait() <-chan struct{}

Wait returns a channel that will close when the condition is satisfied.

type Clock

type Clock interface {
	After(d time.Duration) <-chan time.Time
}

Clock is an abstraction of a clock, for testing purposes

var (
	RealClock Clock
)

type ConfigReader

type ConfigReader interface {
	StringVal(key, dflt string) string
	StringSlice(key string, dflt []string) []string
	StringNumberedList(key string, dflt []string) []string
	IntVal(key string, dflt int) int
	BoolVal(key string, dflt bool) bool
	GetConfigValues() map[string]ConfigValue
	Float64Val(key string, dflt float64) float64
}

type ConfigValue

type ConfigValue struct {
	Name  string
	Value string
}

type DockerExecError

type DockerExecError struct {
	Command string
	ExecErr error
}

An error type for failed docker exec attempts.

func (DockerExecError) Error

func (err DockerExecError) Error() string

type EngNotation

type EngNotation struct {
	Value uint64
	// contains filtered or unexported fields
}

Structure used for serializing/deserializing values represented as strings in engineering notation (e.g., 1K, 256M, etc.)

func NewEngNotation

func NewEngNotation(value int64) EngNotation

func NewEngNotationFromString

func NewEngNotationFromString(in string) (EngNotation, error)

func (EngNotation) MarshalJSON

func (i EngNotation) MarshalJSON() (text []byte, err error)

func (*EngNotation) UnmarshalJSON

func (e *EngNotation) UnmarshalJSON(b []byte) (err error)

type EnvironConfigReader

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

func NewEnvironConfigReader

func NewEnvironConfigReader(filename, prefix string) (*EnvironConfigReader, error)

func NewEnvironOnlyConfigReader

func NewEnvironOnlyConfigReader(prefix string) *EnvironConfigReader

NewEnvironOnlyConfigReader creates an EnvironConfigReader without parsing a file first.

func (*EnvironConfigReader) BoolVal

func (p *EnvironConfigReader) BoolVal(name string, defaultval bool) bool

func (*EnvironConfigReader) Float64Val

func (p *EnvironConfigReader) Float64Val(name string, defaultval float64) float64

func (*EnvironConfigReader) GetConfigValues

func (p *EnvironConfigReader) GetConfigValues() map[string]ConfigValue

func (*EnvironConfigReader) IntVal

func (p *EnvironConfigReader) IntVal(name string, defaultval int) int

func (*EnvironConfigReader) StringNumberedList

func (p *EnvironConfigReader) StringNumberedList(name string, defaultval []string) []string

func (*EnvironConfigReader) StringSlice

func (p *EnvironConfigReader) StringSlice(name string, defaultval []string) []string

func (*EnvironConfigReader) StringVal

func (p *EnvironConfigReader) StringVal(name string, defaultval string) string

type ExecError

type ExecError struct {
	Command []string
	Output  []byte
	Err     error
}

func (ExecError) Error

func (err ExecError) Error() string

type LinuxMount

type LinuxMount struct {
	ProcMount string
}

LinuxMount loads mount data from a file

func (*LinuxMount) IsMounted

func (m *LinuxMount) IsMounted(path string) (bool, error)

IsMounted returns true if path is a mountpoint or device

func (*LinuxMount) ListAll

func (m *LinuxMount) ListAll() (mounts []MountInfo, err error)

ListAll returns info on all mount points

func (*LinuxMount) Unmount

func (m *LinuxMount) Unmount(path string) error

Unmount unmounts a device or mountpoint

type MountInfo

type MountInfo struct {
	Device     string
	MountPoint string
	FSType     string
	Options    []string
	Dump       int
	Fsck       int
}

MountInfo is the object describing the mount point

func (MountInfo) String

func (mount MountInfo) String() string

type MountProc

type MountProc interface {
	ListAll() ([]MountInfo, error)
	IsMounted(string) (bool, error)
	Unmount(string) error
}

MountProc manages mount info

func GetDefaultMountProc

func GetDefaultMountProc() MountProc

GetDefaultMountProc returns the default mount process manager

type MutexMap

type MutexMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMutexMap

func NewMutexMap() *MutexMap

func (*MutexMap) DeleteKey

func (m *MutexMap) DeleteKey(key string)

func (*MutexMap) LockKey

func (m *MutexMap) LockKey(key string)

func (*MutexMap) RLockKey

func (m *MutexMap) RLockKey(key string)

func (*MutexMap) RUnlockKey

func (m *MutexMap) RUnlockKey(key string)

func (*MutexMap) UnlockKey

func (m *MutexMap) UnlockKey(key string)

type ParseError

type ParseError struct {
	String string
}

func (ParseError) Error

func (err ParseError) Error() string

type RouteEntry

type RouteEntry struct {
	Destination string
	Gateway     string
	Genmask     string
	Flags       string
	Metric      int
	Ref         int
	Use         int
	Iface       string
}

RouteEntry represents a entry from the route command

func RouteCmd

func RouteCmd() (routes []RouteEntry, err error)

RouteCmd wrapper around the route command

type TTL

type TTL interface {
	// Name identifies the TTL instance
	Name() string

	// Purge purges expired data from source
	Purge(time.Duration) (time.Duration, error)
}

TTL manages time-to-live data

type TestClock

type TestClock struct {
	AfterChan chan time.Time
}

func NewBufferedTestClock

func NewBufferedTestClock() TestClock

func NewTestClock

func NewTestClock() TestClock

func (TestClock) After

func (c TestClock) After(d time.Duration) <-chan time.Time

func (TestClock) Fire

func (c TestClock) Fire()

type URL

type URL struct {
	Host string
	Port int
}

URL parses and handles URL typed options

func (*URL) Set

func (u *URL) Set(value string) error

Set converts a URL string to a URL object

func (*URL) String

func (u *URL) String() string

type ValueChangePublisher

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

ValueChangePublisher allows for subscribers to be notified upon change of a value.

func NewValueChangePublisher

func NewValueChangePublisher(initialValue interface{}) ValueChangePublisher

Returns a new ValueChangePublisher

func (*ValueChangePublisher) Get

func (v *ValueChangePublisher) Get() (interface{}, <-chan struct{})

Get returns the current value of the publisher and a channel that will be closed when the value changes.

func (*ValueChangePublisher) Set

func (v *ValueChangePublisher) Set(value interface{})

Set closes the current channel notifying current subscribers of a change and stores the value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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