common

package
v0.0.0-...-03200e1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 13 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MessageSuccess = "SUCCESS"
	MessageFailure = "FAILURE"
)

SUCCESS & FAILURE will end a client connection (no?)

View Source
const (
	MessageError   = "ERROR"
	MessageWarning = "WARNING"
	MessageInfo    = "INFO"
	MessageTrace   = "TRACE"
	MessageNoop    = "NOOP" // MessageNoop is used for keep-alive messages
)

Message types

View Source
const (
	MessageNoTarget   = ""
	MessageAllTargets = "*"
)

Special message targets

View Source
const (
	MessagePrintTarget   = true
	MessagePrintNoTarget = false
)

Message.Print target

View Source
const (
	MessageMatchDefault = false
	MessageMatchExact   = true
)

Message.MatchTarget options

View Source
const FalseStr = "false"
View Source
const TrueStr = "true"

TrueStr is the true truth.

Variables

This section is empty.

Functions

func CleanURL

func CleanURL(urlIn string) (string, error)

CleanURL clean the URL using path.Clean rules

func FileContains

func FileContains(filepath string, text string) (bool, error)

FileContains returns true if file contain text

func InterfaceValueToString

func InterfaceValueToString(iv interface{}) string

InterfaceValueToString converts most interface types to string

func MapStringToInterface

func MapStringToInterface(ms map[string]string) map[string]interface{}

MapStringToInterface convert a map[string]string to a map[string]interface{}

func PathExist

func PathExist(path string) bool

PathExist returns true if a file or directory exists

func RemoveAPIKeyFromString

func RemoveAPIKeyFromString(in string, key string) string

RemoveAPIKeyFromString replace any API key appearance in the string

func StringExpandVariables

func StringExpandVariables(str string, variables map[string]interface{}) string

StringExpandVariables expands "variables" ($test, for instance) in str and returns a new string

func StringFindVariables

func StringFindVariables(str string) []string

StringFindVariables returns a deduplicated slice of all "variables" ($test) in the string

func StringIsVariable

func StringIsVariable(s string, varName string) (bool, string)

StringIsVariable returns true and the value if the string's like: FOOBAR=dummy (returns true and "dummy" if varName is "FOOBAR")

Types

type APIBackupListEntries

type APIBackupListEntries []APIBackupListEntry

APIBackupListEntries is a list of entries for "backup list" command

type APIBackupListEntry

type APIBackupListEntry struct {
	DiskName  string
	VMName    string
	Created   time.Time
	Expire    time.Time
	AuthorKey string
	Size      uint64
	AllocSize uint64
}

APIBackupListEntry is an entry for a backup

type APIKeyListEntries

type APIKeyListEntries []APIKeyListEntry

APIKeyListEntries is a list of entries for "backup list" command

type APIKeyListEntry

type APIKeyListEntry struct {
	Comment string
}

APIKeyListEntry is an entry for a backup

type APIKeyRightEntries

type APIKeyRightEntries []string

APIKeyRightEntries is a list of entries for "key right list" command

type APIOperation

type APIOperation struct {
	Origin        string
	Action        string
	Ressource     string
	RessourceName string
	StartTime     time.Time
}

APIOperation is currently exactly matching Operation struct

type APIOrigin

type APIOrigin struct {
	Name string
	Type string
	Path string
}

type APISSHConnection

type APISSHConnection struct {
	FromIP    string
	FromUser  string
	ToUser    string
	ToVMName  string
	StartTime time.Time
}

APISSHConnection describes a proxied SSH connection to a VM

type APISSHPair

type APISSHPair struct {
	Private string
	Public  string
}

APISSHPair is an OpenSSH formatted key pair

type APISecretListEntries

type APISecretListEntries []APISecretListEntry

type APISecretListEntry

type APISecretListEntry struct {
	Key       string
	Modified  time.Time
	AuthorKey string
}

type APISecretUsageEntries

type APISecretUsageEntries []APISecretUsageEntry

type APISecretUsageEntry

type APISecretUsageEntry struct {
	Key         string
	LocalCount  int
	RemoteCount int
}

type APISeedListEntries

type APISeedListEntries []APISeedListEntry

APISeedListEntries is a list of entries for "seeds" command

type APISeedListEntry

type APISeedListEntry struct {
	Name         string
	Ready        bool
	Size         uint64
	LastModified time.Time
}

APISeedListEntry is an entry for a Seed

type APISeedStatus

type APISeedStatus struct {
	Name         string
	File         string
	Ready        bool
	URL          string
	Seeder       string
	Size         uint64
	StatusTime   time.Time
	Status       string
	LastModified time.Time
	PausedUntil  time.Time
}

APISeedStatus expose seed informations

type APIStatus

type APIStatus struct {
	StartTime          time.Time
	VMs                int
	ActiveVMs          int
	HostCPUs           int
	VMCPUs             int
	VMActiveCPUs       int
	HostMemoryTotalMB  int
	VMMemMB            int
	VMActiveMemMB      int
	TotalStorageMB     int
	FreeStorageMB      int
	FreeBackupMB       int
	TotalBackupMB      int
	ProvisionedDisksMB int
	AllocatedDisksMB   int
	Origins            []APIOrigin
	SSHConnections     []APISSHConnection
	Operations         []APIOperation
}

APIStatus describes host status

type APIVMBasicListEntries

type APIVMBasicListEntries []APIVMBasicListEntry

APIVMBasicListEntries is a light variant of APIVMListEntries This is useful for quick requests (like completion)

type APIVMBasicListEntry

type APIVMBasicListEntry struct {
	Name string
}

APIVMBasicListEntry is a basic (light) entry for a VM

type APIVMDoListEntries

type APIVMDoListEntries []APIVMDoListEntry

APIVMDoListEntries is a list of actions for "do" command

type APIVMDoListEntry

type APIVMDoListEntry struct {
	Name        string
	User        string
	Description string
}

APIVMDoListEntry is an entry for an action

type APIVMInfos

type APIVMInfos struct {
	Name                string
	Revision            int
	Active              bool
	Up                  bool
	Seed                string
	CPUCount            int
	RAMSizeMB           uint64
	DiskSizeMB          uint64
	AllocatedDiskSizeMB uint64
	BackupDiskSizeMB    uint64
	Hostname            string
	Domains             []string
	SuperUser           string
	AppUser             string
	InitDate            time.Time
	LastRebuildDuration time.Duration
	LastRebuildDowntime time.Duration
	AuthorKey           string
	Locked              bool
	AssignedIPv4        string
	AssignedMAC         string
	DoActions           []string
	Tags                []string
}

APIVMInfos expose a few VM informations

type APIVMListEntries

type APIVMListEntries []APIVMListEntry

APIVMListEntries is a list of entries for "vm list" command

type APIVMListEntry

type APIVMListEntry struct {
	Name      string
	Revision  int
	Active    bool
	LastIP    string `json:"last_ip"`
	State     string
	Locked    bool
	WIP       string
	SuperUser string
	AppUser   string
}

APIVMListEntry is an entry for a VM

type AsyncCallback

type AsyncCallback struct {
	Action   string
	Target   string
	Success  bool
	Error    string
	Duration time.Duration
}

AsyncCallback are used by mulchd to notify an URL of the result of an asynchronous request

func (*AsyncCallback) AsURLValue

func (ac *AsyncCallback) AsURLValue() url.Values

AsURLValue generate a url.Values version of an AsyncCallback so it can be easily POSTed

type Domain

type Domain struct {
	Name            string
	VMName          string
	RedirectTo      string
	RedirectCode    int
	DestinationHost string
	DestinationPort int
	RedirectToHTTPS bool

	// used internaly by Mulch reverse proxy server
	ReverseProxy *httputil.ReverseProxy `json:"-"`
	TargetURL    string
	Chained      bool
}

Domain defines a route for the reverse-proxy request handler

type FakeWriteCloser

type FakeWriteCloser struct {
	io.Writer
}

FakeWriteCloser allows to create a WriteCloser with a fake Close() from a Writer

func (*FakeWriteCloser) Close

func (fake *FakeWriteCloser) Close() error

Close is a no-op method

type Message

type Message struct {
	Time    time.Time `json:"time"`
	Type    string    `json:"type"`
	Target  string    `json:"target"`
	Message string    `json:"message"`
}

Message describe a message between mulch client and mulchd server

func NewMessage

func NewMessage(mtype string, target string, message string) *Message

NewMessage creates a new Message instance

func (*Message) MatchTarget

func (message *Message) MatchTarget(target string, exact bool) bool

MatchTarget returns true if the message matches the target exact searches are usefull for specific target logs (excluding all "global" messages)

func (*Message) Print

func (message *Message) Print(showTime MessageTimestamp, showTarget bool) error

Print the formatted message

type MessageTimestamp

type MessageTimestamp int

MessagePrintTimestamp is the timestamp type (see MessagePrint*)

const (
	MessagePrintNoTime MessageTimestamp = iota
	MessagePrintTime
	MessagePrintDateTime
)

Message.Print time option

type ProxyChainConflictingDomain

type ProxyChainConflictingDomain struct {
	Domain string
	Owner  string
}

ProxyChainConflictingDomain describes a conflicting domain

type ProxyChainConflictingDomains

type ProxyChainConflictingDomains []ProxyChainConflictingDomain

ProxyChainConflictingDomains is a list of conflicting domains

type ProxyChainDomains

type ProxyChainDomains struct {
	Domains   []string
	ForwardTo string
}

ProxyChainDomains list domains to forward to a target proxy

type TCPForwarder

type TCPForwarder struct {
	Dest           *net.TCPAddr
	PROXYProtoPort uint16
}

type TCPPortListener

type TCPPortListener struct {
	// example: net.ResolveTCPAddr("10.104.0.1:9001")
	ListenAddr *net.TCPAddr

	// the key is the client VM IPv4, value is the forward destination
	Forwards map[string]*TCPForwarder
}

TCPPortListener describe how the TCP proxy will listen on a port

type TCPPortListeners

type TCPPortListeners map[uint16]*TCPPortListener

TCPPortListeners is a map of TCPPortListener instances, with the port as key

type WriteCounter

type WriteCounter struct {
	Total uint64
	CB    WriteCounterCallback
	Step  uint64
	// contains filtered or unexported fields
}

WriteCounter counts the number of bytes written to it. It implements to the io.Writer interface and we can pass this into io.TeeReader() which will report progress on each write cycle.

func (*WriteCounter) Write

func (wc *WriteCounter) Write(p []byte) (int, error)

type WriteCounterCallback

type WriteCounterCallback func(current uint64, total uint64)

WriteCounterCallback is a user callback, called by WriteCounter during writing process

Jump to

Keyboard shortcuts

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