host

package
v0.0.0-alpha16 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	// Path is the path of the command to run.
	//
	// This is the only field that must be set to a non-zero
	// value. If Path is relative, it is evaluated relative
	// to Dir.
	Path string

	// Args holds command line arguments, including the command as Args[0].
	// If the Args field is empty or nil, Run uses {Path}.
	Args []string

	// Env specifies the environment of the process.
	// Each entry is of the form "key=value".
	// If Env is nil, the new process uses LANG=en_US.UTF-8
	// If Env contains duplicate environment keys, only the last
	// value in the slice for each duplicate key is used.
	Env []string

	// Dir specifies the working directory of the command.
	// If Dir is the empty string, Run runs the command in /tmp
	Dir string

	// Stdin specifies the process's standard input.
	//
	// If Stdin is nil, the process reads from the null device (os.DevNull).
	//
	// If Stdin is an *os.File, the process's standard input is connected
	// directly to that file.
	//
	// Otherwise, during the execution of the command a separate
	// goroutine reads from Stdin and delivers that data to the command
	// over a pipe. In this case, Wait does not complete until the goroutine
	// stops copying, either because it has reached the end of Stdin
	// (EOF or a read error), or because writing to the pipe returned an error,
	// or because a nonzero WaitDelay was set and expired.
	Stdin io.Reader
}

Cmd represents a command to be run.

func (Cmd) String

func (c Cmd) String() string

type Host

type Host interface {
	// Chmod works similar to os.Chmod.
	Chmod(ctx context.Context, name string, mode os.FileMode) error

	// Chown works similar to os.Chown.
	Chown(ctx context.Context, name string, uid, gid int) error

	// Lookup works similar to os/user.Lookup in its pure Go version,
	// that reads from /etc/passwd.
	Lookup(ctx context.Context, username string) (*user.User, error)

	// LookupGroup works similar to os/user.LookupGroup in its pure Go version,
	// that reads from /etc/group.
	LookupGroup(ctx context.Context, name string) (*user.Group, error)

	// Lstat works similar to os.Lstat, but returns HostFileInfo with some
	// extra methods.
	Lstat(ctx context.Context, name string) (HostFileInfo, error)

	// Mkdir works similar to os.Mkdir.
	Mkdir(ctx context.Context, name string, perm os.FileMode) error

	// ReadFile works similar to os.ReadFile.
	ReadFile(ctx context.Context, name string) ([]byte, error)

	// Remove works similar to os.Remove.
	Remove(ctx context.Context, name string) error

	// Run starts the specified command and waits for it to complete.
	// Returns WaitStatus, stdout, stderr, error
	Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

	// WriteFile works similar to os.WriteFile.
	WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

	// A string representation of the host which uniquely identifies it, eg, its FQDN.
	String() string
}

Host defines an interface for interacting with a host.

type HostFileInfo

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

func NewHostFileInfo

func NewHostFileInfo(
	name string,
	size int64,
	mode fs.FileMode,
	modTime time.Time,
	isDir bool,
	uid uint32,
	gid uint32,
) HostFileInfo

func (HostFileInfo) Gid

func (hfi HostFileInfo) Gid() uint32

func (HostFileInfo) IsDir

func (hfi HostFileInfo) IsDir() bool

func (HostFileInfo) ModTime

func (hfi HostFileInfo) ModTime() time.Time

func (HostFileInfo) Mode

func (hfi HostFileInfo) Mode() fs.FileMode

func (HostFileInfo) Name

func (hfi HostFileInfo) Name() string

func (HostFileInfo) Size

func (hfi HostFileInfo) Size() int64

func (HostFileInfo) Sys

func (hfi HostFileInfo) Sys() any

func (HostFileInfo) Uid

func (hfi HostFileInfo) Uid() uint32

type Local

type Local struct{}

Local interacts with the local machine running the code.

func (Local) Chmod

func (l Local) Chmod(ctx context.Context, name string, mode os.FileMode) error

func (Local) Chown

func (l Local) Chown(ctx context.Context, name string, uid, gid int) error

func (Local) Lookup

func (l Local) Lookup(ctx context.Context, username string) (*user.User, error)

func (Local) LookupGroup

func (l Local) LookupGroup(ctx context.Context, name string) (*user.Group, error)

func (Local) Lstat

func (l Local) Lstat(ctx context.Context, name string) (HostFileInfo, error)

func (Local) Mkdir

func (l Local) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (Local) ReadFile

func (l Local) ReadFile(ctx context.Context, name string) ([]byte, error)

func (Local) Remove

func (l Local) Remove(ctx context.Context, name string) error

func (Local) Run

func (l Local) Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

func (Local) String

func (l Local) String() string

func (Local) WriteFile

func (l Local) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

type Run

type Run struct {
	Host Host
	// contains filtered or unexported fields
}

Run implements Host interface by having all methods rely on an underlying Host.Run.

func NewRun

func NewRun(host Host) Run

func (Run) Chmod

func (br Run) Chmod(ctx context.Context, name string, mode os.FileMode) error

func (Run) Chown

func (br Run) Chown(ctx context.Context, name string, uid, gid int) error

func (Run) Lookup

func (br Run) Lookup(ctx context.Context, username string) (*user.User, error)

func (Run) LookupGroup

func (br Run) LookupGroup(ctx context.Context, name string) (*user.Group, error)

func (Run) Lstat

func (br Run) Lstat(ctx context.Context, name string) (HostFileInfo, error)

func (Run) Mkdir

func (br Run) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (Run) ReadFile

func (br Run) ReadFile(ctx context.Context, name string) ([]byte, error)

func (Run) Remove

func (br Run) Remove(ctx context.Context, name string) error

func (Run) Run

func (r Run) Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

func (Run) String

func (r Run) String() string

func (Run) WriteFile

func (br Run) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

type Ssh

type Ssh struct {
	Hostname string
}

Ssh interacts with a remote machine connecting to it via SSH protocol.

func (Ssh) Chmod

func (s Ssh) Chmod(ctx context.Context, name string, mode os.FileMode) error

func (Ssh) Chown

func (s Ssh) Chown(ctx context.Context, name string, uid, gid int) error

func (Ssh) Lookup

func (s Ssh) Lookup(ctx context.Context, username string) (*user.User, error)

func (Ssh) LookupGroup

func (s Ssh) LookupGroup(ctx context.Context, name string) (*user.Group, error)

func (Ssh) Lstat

func (s Ssh) Lstat(ctx context.Context, name string) (HostFileInfo, error)

func (Ssh) Mkdir

func (s Ssh) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (Ssh) ReadFile

func (s Ssh) ReadFile(ctx context.Context, name string) ([]byte, error)

func (Ssh) Remove

func (s Ssh) Remove(ctx context.Context, name string) error

func (Ssh) Run

func (s Ssh) Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

func (Ssh) String

func (s Ssh) String() string

func (Ssh) WriteFile

func (s Ssh) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

type Sudo

type Sudo struct {
	Host Host
	// contains filtered or unexported fields
}

Sudo implements Host interface by having all methods rely on an underlying Host.Run, and preceding all commands with sudo.

func NewSudo

func NewSudo(ctx context.Context, host Host) (Sudo, error)

func (Sudo) Chmod

func (br Sudo) Chmod(ctx context.Context, name string, mode os.FileMode) error

func (Sudo) Chown

func (br Sudo) Chown(ctx context.Context, name string, uid, gid int) error

func (Sudo) Lookup

func (br Sudo) Lookup(ctx context.Context, username string) (*user.User, error)

func (Sudo) LookupGroup

func (br Sudo) LookupGroup(ctx context.Context, name string) (*user.Group, error)

func (Sudo) Lstat

func (br Sudo) Lstat(ctx context.Context, name string) (HostFileInfo, error)

func (Sudo) Mkdir

func (br Sudo) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (Sudo) ReadFile

func (br Sudo) ReadFile(ctx context.Context, name string) ([]byte, error)

func (Sudo) Remove

func (br Sudo) Remove(ctx context.Context, name string) error

func (Sudo) Run

func (s Sudo) Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

func (Sudo) String

func (s Sudo) String() string

func (Sudo) WriteFile

func (br Sudo) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

type WaitStatus

type WaitStatus struct {
	// ExitCode returns the exit code of the exited process, or -1 if the process hasn't exited or was terminated by a signal.
	ExitCode int
	// Exited reports whether the program has exited. On Unix systems this reports true if the program exited due to calling exit, but false if the program terminated due to a signal.
	Exited bool
	// Signal describes a process signal.
	Signal string
}

WaitStatus

func (*WaitStatus) String

func (ws *WaitStatus) String() string

func (*WaitStatus) Success

func (ws *WaitStatus) Success() bool

Success reports whether the program exited successfully, such as with exit status 0 on Unix.

Jump to

Keyboard shortcuts

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