utils

package
v0.0.0-...-5b8b77a Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RSABitSize = 4096
)

Defaults

View Source
const RootFSCopyBufferSize = 4 * 1024 * 1024

RootFSCopyBufferSize is the buffer size for root file system copy operation.

Variables

This section is empty.

Functions

func CheckIfExistsAndIsDirectory

func CheckIfExistsAndIsDirectory(path string) (fs.FileInfo, error)

CheckIfExistsAndIsDirectory checks is a path points at a directory.

func CheckIfExistsAndIsRegular

func CheckIfExistsAndIsRegular(path string) (fs.FileInfo, error)

CheckIfExistsAndIsRegular checks is a path points at a regular file.

func CopyFile

func CopyFile(source, dest string, bufferSize int) error

CopyFile copies a file at the source path to the dest path.

func CreateRootFSFile

func CreateRootFSFile(path string, size int) error

CreateRootFSFile uses dd to create a rootfs file of given size at a given path.

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte

EncodePrivateKeyToPEM encodes Private Key from RSA to PEM format.

func GenerateRSAPrivateKey

func GenerateRSAPrivateKey(bitSize int) (*rsa.PrivateKey, error)

GenerateRSAPrivateKey generates a new RSA private key.

func GetConfiguredOrSuitableInterfaceName

func GetConfiguredOrSuitableInterfaceName(configured string) (string, error)

GetConfiguredOrSuitableInterfaceName returns the configured interface name, if not empty, or tries retrieving first suitable interface name.

func GetFirstUpBroadcastInterface

func GetFirstUpBroadcastInterface() (net.Interface, error)

GetFirstUpBroadcastInterface retrieves the first suitable up broadact capable interface.

func GetInterfaceV4Addr

func GetInterfaceV4Addr(interfaceName string) (addr string, err error)

GetInterfaceV4Addr fetches an IPv4 address of an interface.

func GetSSHKey

func GetSSHKey(privatekey *rsa.PrivateKey) (ssh.PublicKey, error)

GetSSHKey generates an SSH public key for the given private key.

func GetUpBroadcastInterfaces

func GetUpBroadcastInterfaces() ([]net.Interface, error)

GetUpBroadcastInterfaces retrieves the list of up broadcast interfaces. These are internally sorted by an index so the output is always deterministic.

func GetenvOrDefault

func GetenvOrDefault(key, fallback string) string

GetenvOrDefault calls os>lookup for a key and returns a fallback only if variable wasn't set.

func IsValidHostname

func IsValidHostname(host string) bool

IsValidHostname validates if a string is a valid host name.

func IsValidTag

func IsValidTag(input string) bool

IsValidTag checks if the given image tag is valid.

func MarshalSSHPublicKey

func MarshalSSHPublicKey(key ssh.PublicKey) []byte

MarshalSSHPublicKey marshals SSH public key to the OpenSSH format so it can be used for authorized_keys file.

func MkfsExt4

func MkfsExt4(path string) error

MkfsExt4 uses mkfs.ext4 to create an EXT4 file system in a given file.

func Mount

func Mount(file, dir string) error

Mount sudo mounts a rootfs file at a location.

func MoveFile

func MoveFile(source, target string) error

MoveFile moves file from source to destination. os.Rename does not allow moving between drives hence we have to rewrite the file. Intermediate target directories will be created.

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if path exists.

func RandStringBytes

func RandStringBytes(n int) string

RandStringBytes returns a random string of length n.

func RandStringWithDigitsBytes

func RandStringWithDigitsBytes(n int) string

RandStringWithDigitsBytes returns a random string of length n.

func RandomHostname

func RandomHostname() string

RandomHostname returns a new random host name.

func RunShellCommandNoSudo

func RunShellCommandNoSudo(command string) (int, error)

RunShellCommandNoSudo runs a shell command without sudo.

func RunShellCommandSudo

func RunShellCommandSudo(command string) (int, error)

RunShellCommandSudo runs a shell command with sudo.

func SSHPublicKeyFromBytes

func SSHPublicKeyFromBytes(b []byte) (ssh.PublicKey, error)

SSHPublicKeyFromBytes reads an SSH public key from bytes.

func SSHPublicKeyFromFile

func SSHPublicKeyFromFile(path string) (ssh.PublicKey, error)

SSHPublicKeyFromFile reads an SSH public key from a PEM file.

func TagDecompose

func TagDecompose(input string) (bool, string, string, string)

TagDecompose decomposes the tag into the image components.

func Umount

func Umount(dir string) error

Umount sudo umounts a location.

Types

type Defers

type Defers interface {
	// Add the function to the deferred list of functions.
	// The new function will be instered at the beginning of the list.
	Add(func())
	// CallAll calls all deferred functions in the reverse order.
	CallAll()
	// Calling Trigger(false) causes the instance not to process the defers.
	Trigger(bool)
}

Defers maintains ordered LIFO list of functions to handle on the defer call.

func NewDefers

func NewDefers() Defers

NewDefers returns a new instance of Defers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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