Documentation ¶
Index ¶
- Constants
- Variables
- func AskForBool(question string, defaultAnswer string) bool
- func AskForPassword(question string) string
- func BinaryEndian() binary.ByteOrder
- func CertFingerprint(cert *x509.Certificate) string
- func CertFingerprintStr(c string) (string, error)
- func CompareSlicesOrdered[T comparable](a, b []T) bool
- func CompareSlicesUnordered[T comparable](a, b []T) bool
- func CreateBzip2Tarball(workingDir, outputPath string, content []string) error
- func CreateZip(workingDir, outputPath string, content []string) error
- func DirCopy(source string, dest string) error
- func FileCopy(source string, dest string) error
- func FileMove(oldPath string, newPath string) error
- func GenerateFingerprint(reader io.ReadSeeker) (string, error)
- func GenerateFingerprintForFile(path string) (string, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomString(s int) (string, error)
- func GetByteSizeString(input int64, precision uint) string
- func GetFileSize(path string) (int64, error)
- func GetFreePort() (int, error)
- func GetFreePorts(count int) ([]int, error)
- func GetOwnerMode(fInfo os.FileInfo) (os.FileMode, int, int)
- func GetRemoteCertificate(address string) (*x509.Certificate, error)
- func GetRemoteCertificateWithTLSConfig(address string, tlsConfig *tls.Config) (*x509.Certificate, error)
- func GetTLS13Config(tlsClientCertFile, tlsClientKeyFile, tlsClientCAFile string, ...) (*tls.Config, error)
- func GetTLSConfig(tlsClientCertFile, tlsClientKeyFile, tlsClientCAFile string, ...) (*tls.Config, error)
- func GetTLSConfigMem(tlsClientCert string, tlsClientKey string, tlsClientCA string, ...) (*tls.Config, error)
- func Hash(value string) (string, error)
- func ImageArchToNodeArch(Arch string) string
- func InitTLS13Config() *tls.Config
- func InitTLSConfig() *tls.Config
- func ListAvailableAddresses() ([]string, error)
- func ListFilesInDir(dirPath string, recursive bool) ([]string, error)
- func LoadFromFile(configPath string, cfg interface{}) error
- func NewCancelableReader(ctx context.Context, other io.Reader) io.Reader
- func NodeArchToImageArch(Arch string) string
- func ParseByteSizeString(input string) (int64, error)
- func PathExists(name string) bool
- func ProxyFromConfig(httpsProxy string, httpProxy string, noProxy string) func(req *http.Request) (*url.URL, error)
- func ProxyFromEnvironment(req *http.Request) (*url.URL, error)
- func RFC3493Dialer(network, address string) (net.Conn, error)
- func RandomCryptoString() (string, error)
- func ReaderToChannel(r io.Reader, bufferSize int) <-chan []byte
- func RunningAsSnap() bool
- func SetSize(fd int, width int, height int) (err error)
- func StringInSlice(key string, list []string) bool
- func StripUserPasswordFromURL(value string) string
- func ValidateHash(hashed, value string) error
- func ValueOrDefault(value string, defaultValue string) string
- func VarPath(path ...string) string
- func WebsocketConsoleMirror(conn *websocket.Conn, w io.WriteCloser, r io.ReadCloser) (chan bool, chan bool)
- func WebsocketMirror(conn *websocket.Conn, w io.WriteCloser, r io.ReadCloser, ...) (chan bool, chan bool)
- func WebsocketProxy(source *websocket.Conn, target *websocket.Conn) chan bool
- func WebsocketRecvStream(w io.Writer, conn *websocket.Conn) chan bool
- func WebsocketSendStream(conn *websocket.Conn, r io.Reader, bufferSize int) chan bool
- func WriteFileAtomic(targetPath string, content []byte, mode os.FileMode) error
- type AtomicFile
- type BufferedReader
- type Locker
- type RevertFunc
- type Reverter
- type WebSocketMirrorReader
- type WebSocketMirrorWriter
Constants ¶
const ( // DefaultTransportTimeout stands for the default value for client requests to wait for a reply DefaultTransportTimeout = 30 * time.Second )
const (
// ValidActivityNamePattern represents the pattern of valid Android activity name
ValidActivityNamePattern = `(^([A-Za-z]{1}[A-Za-z\d_]*\.){2,}|^(\.){1})[A-Za-z][A-Za-z\d_]*$`
)
Variables ¶
var WebsocketUpgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, }
WebsocketUpgrader websocket.Upgrader
Functions ¶
func AskForBool ¶
AskForBool asks a question and expect a yes/no answer.
func AskForPassword ¶
AskForPassword asks the user to enter a password.
func BinaryEndian ¶
BinaryEndian returns machine native binary endian
func CertFingerprint ¶
func CertFingerprint(cert *x509.Certificate) string
CertFingerprint returns the sha256 fingerprint of the given x509.Certificate
func CertFingerprintStr ¶
CertFingerprintStr decodes the given string to x509.Certificate and then generates a sha256 fingerprint
func CompareSlicesOrdered ¶
func CompareSlicesOrdered[T comparable](a, b []T) bool
CompareSlicesOrdered does an ordered comparison of the elements of two slices. It returns true if all the elements of slice A match all elements of slice B.
func CompareSlicesUnordered ¶
func CompareSlicesUnordered[T comparable](a, b []T) bool
CompareSlicesUnordered does an unordered comparison of the elements of two slices. It returns true if all the elements of slice A match all elements of slice B.
func CreateBzip2Tarball ¶
CreateBzip2Tarball creates a bzip2 tarball file with given files path
func FileMove ¶
FileMove tries to move a file by using os.Rename, if that fails it tries to copy the file and remove the source.
func GenerateFingerprint ¶
func GenerateFingerprint(reader io.ReadSeeker) (string, error)
GenerateFingerprint generates a fingerprint for the given reader
func GenerateFingerprintForFile ¶
GenerateFingerprintForFile generates a fingerprint (sha256) for the given file
func GenerateRandomBytes ¶
GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func GenerateRandomString ¶
GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func GetByteSizeString ¶
GetByteSizeString returns a string with the given byte size formatted and the right unit added.
func GetFileSize ¶
GetFileSize returns the size of the file at the given path
func GetFreePort ¶
GetFreePort asks the kernel for a free open port that is ready to use.
func GetFreePorts ¶
GetFreePorts asks the kernel for a number of free open ports that are ready to use.
func GetOwnerMode ¶
GetOwnerMode retrieves the file mode and owner of a given file object
func GetRemoteCertificate ¶
func GetRemoteCertificate(address string) (*x509.Certificate, error)
GetRemoteCertificate connects to the server and returns its certificate
func GetRemoteCertificateWithTLSConfig ¶
func GetRemoteCertificateWithTLSConfig(address string, tlsConfig *tls.Config) (*x509.Certificate, error)
GetRemoteCertificateWithTLSConfig connects to the server and returns its certificate
func GetTLS13Config ¶
func GetTLS13Config(tlsClientCertFile, tlsClientKeyFile, tlsClientCAFile string, tlsRemoteCert *x509.Certificate) (*tls.Config, error)
GetTLS13Config returns a tls 1.3 config
func GetTLSConfig ¶
func GetTLSConfig(tlsClientCertFile, tlsClientKeyFile, tlsClientCAFile string, tlsRemoteCert *x509.Certificate) (*tls.Config, error)
GetTLSConfig returns a tls 1.2 config
func GetTLSConfigMem ¶
func GetTLSConfigMem(tlsClientCert string, tlsClientKey string, tlsClientCA string, tlsRemoteCertPEM string, insecureSkipVerify, useTLS12 bool) (*tls.Config, error)
GetTLSConfigMem returns a tls config
func Hash ¶
Hash creates a hash of 192 chars from a value. A random salt of 32 bytes is used. The result is that salt plus the hashed result encoded to hexadecimal
func ImageArchToNodeArch ¶
ImageArchToNodeArch converts the architecture of an image which is used in simplestream to node machine architecture
func InitTLS13Config ¶
InitTLS13Config returns a tls.Config populated with TLS1.3 as the minimum TLS version for TLS configuration
func InitTLSConfig ¶
InitTLSConfig returns a tls.Config populated with default encryption parameters. This is used as baseline config server certificate
func ListAvailableAddresses ¶
ListAvailableAddresses returns a list of IPv4 network addresses the host has. It ignores the loopback device
func ListFilesInDir ¶
ListFilesInDir lists all files in one specific directory recursively
func LoadFromFile ¶
LoadFromFile loads a configuration from the given file path
func NewCancelableReader ¶
NewCancelableReader creates a new cancelable io.Reader
func NodeArchToImageArch ¶
NodeArchToImageArch converts the architecture of node machine architecture to the architecture of an image which is used in simplestream
func ParseByteSizeString ¶
ParseByteSizeString parses a size string in bytes (e.g. 200kB or 5GB) into the number of bytes it represents. Supports suffixes up to EB. "" == 0.
func ProxyFromConfig ¶
func ProxyFromConfig(httpsProxy string, httpProxy string, noProxy string) func(req *http.Request) (*url.URL, error)
ProxyFromConfig configures the proxy from the given values. If all values are empty a call is equals to ProxyFromEnvironment()
func ProxyFromEnvironment ¶
ProxyFromEnvironment This is basically the same as golang's ProxyFromEnvironment, except it doesn't fall back to http_proxy when https_proxy isn't around, which is incorrect behavior. It still respects HTTP_PROXY, HTTPS_PROXY, and NO_PROXY.
func RFC3493Dialer ¶
RFC3493Dialer dialer
func RandomCryptoString ¶
RandomCryptoString returns a random base64 encoded string from crypto/rand.
func ReaderToChannel ¶
ReaderToChannel reads from websocket and sends to a channel
func RunningAsSnap ¶
func RunningAsSnap() bool
RunningAsSnap detects if the ams service runs as a snap
func StringInSlice ¶
StringInSlice returns true if the searched string key is into slice
func StripUserPasswordFromURL ¶
StripUserPasswordFromURL removes user/password from the given URL
func ValidateHash ¶
ValidateHash decodes hexadecimal hashed, extracts the salt from the first 32 bytes and hashes the value param using that salt. The result of that hash function should match the rest of the decoded secret buffer. Otherwise the validation fails
func ValueOrDefault ¶
ValueOrDefault returns the value if it has a size greater than zero or defaultValue otherwise
func VarPath ¶
VarPath returns the provided path elements joined by a slash and appended to the end of $SNAP_COMMON, which defaults to /var/lib/ams.
func WebsocketConsoleMirror ¶
func WebsocketConsoleMirror(conn *websocket.Conn, w io.WriteCloser, r io.ReadCloser) (chan bool, chan bool)
WebsocketConsoleMirror console mirror
func WebsocketMirror ¶
func WebsocketMirror(conn *websocket.Conn, w io.WriteCloser, r io.ReadCloser, Reader WebSocketMirrorReader, Writer WebSocketMirrorWriter) (chan bool, chan bool)
WebsocketMirror allows mirroring a reader to a websocket and taking the result and writing it to a writer. This function allows for multiple mirrorings and correctly negotiates stream endings. However, it means any websocket.Conns passed to it are live when it returns, and must be closed explicitly.
func WebsocketProxy ¶
WebsocketProxy proxies a websocket connection
func WebsocketRecvStream ¶
WebsocketRecvStream manages the recv stream of the socket
func WebsocketSendStream ¶
WebsocketSendStream manages the send stream of the websocket
Types ¶
type AtomicFile ¶
AtomicFile allows operation on a file to happen atomicly. Changes must be committed in the end before the final file will appear at its target location
func NewAtomicFile ¶
func NewAtomicFile(targetPath string, mode os.FileMode) (*AtomicFile, error)
NewAtomicFile creates a new AtomicFile with the given target path and mode
func (*AtomicFile) Cancel ¶
func (af *AtomicFile) Cancel() error
Cancel all changes made. Is a no-op when Commit was already called
func (*AtomicFile) Commit ¶
func (af *AtomicFile) Commit() error
Commit commits changes made to the file and moves the temporary file to its final location
type BufferedReader ¶
BufferedReader represents a reader with buf size
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker represents a locker which acquires the lock only if it is not held by another goroutine at the time of invocation.
func NewLocker ¶
func NewLocker() *Locker
NewLocker returns a new Locker which can be used by a goroutine to hold the internal lock and perform task which can not be invoked by other goroutine
type RevertFunc ¶
RevertFunc describes a function used to revert an operation
type Reverter ¶
type Reverter struct {
// contains filtered or unexported fields
}
Reverter provides functionality to automatically revert a set of executed operations. It can be used this way:
r := shared.NewReverter() defer r.Finish()
doOperation()
r.Add(func(ctx context.Context) error { revertOperation() return nil }) if err := doOtherOperation(); err != nil { return err }
r.Defuse()
func (*Reverter) Add ¶
func (r *Reverter) Add(f ...RevertFunc)
Add adds a new revert function to the reverter which will be called when Finish() is called unless the reverter gets defused.
type WebSocketMirrorReader ¶
type WebSocketMirrorReader func(conn *websocket.Conn, r io.ReadCloser, readDone chan<- bool)
WebSocketMirrorReader mirror reader
type WebSocketMirrorWriter ¶
type WebSocketMirrorWriter func(conn *websocket.Conn, w io.WriteCloser, writeDone chan<- bool)
WebSocketMirrorWriter mirror writer