Documentation ¶
Index ¶
- func CopyDirectory(source, destination string, overWrite bool) (err error)
- func CopyFiles(sourcePath, destinationPath string, doOverWrite bool) (err error)
- func CreateDirectory(path string, modTime time.Time) (result string, err error)
- func DeleteDirectory(directory string) (err error)
- func DeletePath(path string) error
- func GetDefaultProcessName() string
- func GetDiskStat(path string) (*types.DiskStat, error)
- func GetEmptyFiles(directory string) (result []string, err error)
- func GetFileInfo(path string) (result fs.FileInfo, err error)
- func GetKernelRelease() (string, error)
- func GetOSDistro() (result string, err error)
- func GetSystemBlockDevices() (result map[string]types.BlockDeviceInfo, err error)
- func Gettid() int
- func LockFile(path string) (result *os.File, err error)
- func ReadDirectory(directory string) (result []fs.DirEntry, err error)
- func ReadFileContent(filePath string) (result string, err error)
- func RunFunc(fn func() (interface{}, error), timeout time.Duration) (interface{}, error)
- func Sync() (err error)
- func SyncFile(filePath string) (err error)
- func WriteFile(filePath, data string) error
- type Executor
- func (nsexec *Executor) Cryptsetup(args []string, timeout time.Duration) (stdout string, err error)
- func (nsexec *Executor) CryptsetupWithPassphrase(passphrase string, args []string, timeout time.Duration) (stdout string, err error)
- func (nsexec *Executor) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error)
- func (nsexec *Executor) ExecuteWithStdin(envs []string, binary string, args []string, stdinString string, ...) (string, error)
- func (nsexec *Executor) ExecuteWithStdinPipe(envs []string, binary string, args []string, stdinString string, ...) (string, error)
- func (nsexec *Executor) LuksClose(volume string, timeout time.Duration) (stdout string, err error)
- func (nsexec *Executor) LuksFormat(devicePath, passphrase, keyCipher, keyHash, keySize, pbkdf string, ...) (stdout string, err error)
- func (nsexec *Executor) LuksOpen(volume, devicePath, passphrase string, timeout time.Duration) (stdout string, err error)
- func (nsexec *Executor) LuksResize(volume, passphrase string, timeout time.Duration) (stdout string, err error)
- func (nsexec *Executor) LuksStatus(volume string, timeout time.Duration) (stdout string, err error)
- type FileLock
- type Joiner
- type JoinerDescriptor
- type JoinerInterface
- type Joiners
- type NewJoinerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyDirectory ¶
CopyDirectory switches to the host namespace and copies the content from source to destination. It will overwrite the destination if overWrite is true. Top level directory is prohibited.
func CopyFiles ¶
CopyFiles switches to the host namespace and copies the all files from source to destination. It will overwrite the destination if overWrite is true.
func CreateDirectory ¶
CreateDirectory switches to the host namespace and creates a directory at the specified path.
func DeleteDirectory ¶
DeleteDirectory switches to the host namespace and removes the directory at the specified path.
func DeletePath ¶
DeletePath switches to the host namespace and removes the file or directory at the specified path.
func GetDefaultProcessName ¶
func GetDefaultProcessName() string
GetDefaultProcessName returns the default process name for namespace switching based on the OS distro.
func GetDiskStat ¶
GetDiskStat switches to the host namespace and returns the disk stat of the disk at the specified path.
func GetEmptyFiles ¶
GetEmptyFiles switches to the host namespace and retrieves a list of paths for all empty files within the specified directory.
func GetFileInfo ¶
GetFileInfo switches to the host namespace and returns the file info of the file at the specified path.
func GetKernelRelease ¶
GetKernelRelease switches to the host namespace and retrieves the kernel release.
func GetOSDistro ¶
GetOSDistro switches to the host namespace and retrieves the OS distro.
func GetSystemBlockDevices ¶
func GetSystemBlockDevices() (result map[string]types.BlockDeviceInfo, err error)
GetSystemBlockDevices switches to the host namespace and retrieves the system block devices.
func LockFile ¶
LockFile switches to the host namespace and locks a file at the specified path. It returns the file handle.
func ReadDirectory ¶
ReadDirectory switches to the host namespace and reads the content of the directory at the specified path.
func ReadFileContent ¶
ReadFileContent switches to the host namespace and returns the content of the file at the specified path.
func RunFunc ¶
RunFunc runs the given function in the host namespace. Returns the result of the function and any error that occurred.
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor is a struct resonpsible for executing commands in a specific namespace using nsenter.
func NewNamespaceExecutor ¶
func NewNamespaceExecutor(processName, procDirectory string, namespaces []types.Namespace) (*Executor, error)
NewNamespaceExecutor creates a new namespace executor for the given process name, namespaces and proc directory. If the process name is not empty, it will try to use the process namespace directory. Otherwise, it will use the host namespace directory. The namespaces are the namespaces to enter. The proc directory is the directory where the process information is stored. It will also verify the existence of the nsenter binary.
func (*Executor) Cryptsetup ¶
Cryptsetup runs cryptsetup without passphrase. It will return 0 on success and a non-zero value on error.
func (*Executor) CryptsetupWithPassphrase ¶
func (nsexec *Executor) CryptsetupWithPassphrase(passphrase string, args []string, timeout time.Duration) (stdout string, err error)
CryptsetupWithPassphrase runs cryptsetup with passphrase. It will return 0 on success and a non-zero value on error. 1 wrong parameters, 2 no permission (bad passphrase), 3 out of memory, 4 wrong device specified, 5 device already exists or device is busy.
func (*Executor) Execute ¶
func (nsexec *Executor) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error)
Execute executes the command in the namespace. If NsDirectory is empty, it will execute the command in the current namespace.
func (*Executor) ExecuteWithStdin ¶
func (nsexec *Executor) ExecuteWithStdin(envs []string, binary string, args []string, stdinString string, timeout time.Duration) (string, error)
ExecuteWithStdin executes the command in the namespace with stdin. If NsDirectory is empty, it will execute the command in the current namespace.
func (*Executor) ExecuteWithStdinPipe ¶
func (nsexec *Executor) ExecuteWithStdinPipe(envs []string, binary string, args []string, stdinString string, timeout time.Duration) (string, error)
ExecuteWithStdinPipe executes the command in the namespace with stdin pipe. If NsDirectory is empty, it will execute the command in the current namespace.
func (*Executor) LuksFormat ¶
func (nsexec *Executor) LuksFormat(devicePath, passphrase, keyCipher, keyHash, keySize, pbkdf string, timeout time.Duration) (stdout string, err error)
LuksFormat runs cryptsetup luksFormat with the given passphrase and returns the stdout and error.
func (*Executor) LuksOpen ¶
func (nsexec *Executor) LuksOpen(volume, devicePath, passphrase string, timeout time.Duration) (stdout string, err error)
LuksOpen runs cryptsetup luksOpen with the given passphrase and returns the stdout and error.
type FileLock ¶
type FileLock struct { FilePath string // The path of the file to lock. File *os.File // The file handle acquired after successful lock. Timeout time.Duration // The maximum time to wait for lock acquisition. // contains filtered or unexported fields }
FileLock is a struct responsible for locking a file.
type Joiner ¶
type Joiner struct {
// contains filtered or unexported fields
}
Joiner is a context with information about a namespace.
type JoinerDescriptor ¶
type JoinerDescriptor struct {
// contains filtered or unexported fields
}
JoinerDescriptor is a struct that holds information about the namespaces to join.
func (*JoinerDescriptor) Join ¶
func (jd *JoinerDescriptor) Join() (err error)
Join joins the target namespaces.
func (*JoinerDescriptor) OpenNamespaceFiles ¶
func (jd *JoinerDescriptor) OpenNamespaceFiles() (err error)
OpenNamespaceFiles opens required namespace files.
func (*JoinerDescriptor) Revert ¶
func (jd *JoinerDescriptor) Revert() (err error)
Revert reverts to the original namespaces.
func (*JoinerDescriptor) Run ¶
func (jd *JoinerDescriptor) Run(fn func() (interface{}, error)) (interface{}, error)
Run executes the function in the target namespace. The function is executed in a goroutine with a locked OS thread to ensure namespace isolation.
type JoinerInterface ¶
type Joiners ¶
type Joiners []*Joiner
func (*Joiners) CloseFiles ¶
func (joiners *Joiners) CloseFiles()
CloseFiles closes all the files in the Joiners.
func (*Joiners) JoinReverse ¶
JoinReverse joins all the namespaces in the Joiners in reverse order.
func (*Joiners) ReverseOrder ¶
ReverseOrder returns a reversed copy of the Joiners.
type NewJoinerFunc ¶
type NewJoinerFunc func(string, time.Duration) (JoinerInterface, error)
var NewJoiner NewJoinerFunc = newJoiner
NewJoiner is a variable holding the function responsible for creating a new JoinerInterface. By using a variable for the creation function, it allows for easier unit testing by substituting a mock implementation.