host

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// Execute runs a command and returns its standard output as a string.
	// It should return an error if the command fails to execute or exits with a non-zero status.
	Execute(ctx context.Context, cmd string) (string, error)

	// Close cleans up any resources associated with the executor.
	Close() error
}

Executor defines an interface for running commands on a target host.

func NewExecutorFromURI

func NewExecutorFromURI(ctx context.Context, target string, opts ExecutorOptions) (Executor, error)

NewExecutorFromURI creates a new Executor based on the provided target URI and options.

type ExecutorOptions

type ExecutorOptions struct {
	IdentityFile string
	PasswordEnv  string
	AskPass      bool
	Insecure     bool
	Timeout      time.Duration
}

ExecutorOptions holds configuration for creating an Executor.

type LocalExecutor

type LocalExecutor struct{}

LocalExecutor executes commands on the local machine.

func NewLocalExecutor

func NewLocalExecutor() *LocalExecutor

NewLocalExecutor returns a new LocalExecutor.

func (*LocalExecutor) Close

func (e *LocalExecutor) Close() error

Close is a no-op for LocalExecutor.

func (*LocalExecutor) Execute

func (e *LocalExecutor) Execute(ctx context.Context, cmd string) (string, error)

Execute runs the given command locally using the appropriate shell.

type OSFamily

type OSFamily string

OSFamily represents the package management family of an OS.

const (
	FamilyDeb     OSFamily = "debian"
	FamilyRPM     OSFamily = "rpm"
	FamilyAlpine  OSFamily = "alpine"
	FamilyWindows OSFamily = "windows"
	FamilyUnknown OSFamily = "unknown"
)

type OSInfo

type OSInfo struct {
	Family  OSFamily
	Distro  string // For Linux: ID from os-release
	Version string // For Linux: VERSION_ID from os-release
	OSName  string // For Windows: Caption
}

OSInfo holds the fingerprinted operating system data.

type SSHExecutor

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

SSHExecutor executes commands on a remote host via SSH.

func NewSSHExecutor

func NewSSHExecutor(opts SSHOptions) (*SSHExecutor, error)

NewSSHExecutor connects to an SSH server and returns an SSHExecutor.

func (*SSHExecutor) Close

func (e *SSHExecutor) Close() error

Close closes the underlying SSH connection.

func (*SSHExecutor) Execute

func (e *SSHExecutor) Execute(ctx context.Context, cmd string) (string, error)

Execute runs the command on the remote host over SSH.

type SSHOptions

type SSHOptions struct {
	Host         string
	Port         string
	User         string
	IdentityFile string
	Password     string //nolint:gosec // false positive for struct field name
	Insecure     bool
	Timeout      time.Duration
}

SSHOptions holds the configuration for an SSH connection.

type Scanner

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

Scanner performs host inventory scanning.

func NewScanner

func NewScanner(exec Executor) *Scanner

NewScanner creates a new Scanner using the provided Executor.

func (*Scanner) DetectOS

func (s *Scanner) DetectOS(ctx context.Context) (*OSInfo, error)

DetectOS attempts to determine the target's operating system using the executor.

func (*Scanner) GatherPackages

func (s *Scanner) GatherPackages(ctx context.Context, info *OSInfo) ([]string, error)

GatherPackages retrieves the list of installed packages or updates based on the OS family.

type WinRMExecutor

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

WinRMExecutor executes commands on a remote Windows host via WinRM.

func NewWinRMExecutor

func NewWinRMExecutor(opts WinRMOptions) (*WinRMExecutor, error)

NewWinRMExecutor connects to a WinRM endpoint and returns a WinRMExecutor.

func (*WinRMExecutor) Close

func (e *WinRMExecutor) Close() error

Close is a no-op for WinRMExecutor as the client does not maintain an active TCP connection pool.

func (*WinRMExecutor) Execute

func (e *WinRMExecutor) Execute(ctx context.Context, cmd string) (string, error)

Execute runs the command on the remote host over WinRM.

type WinRMOptions

type WinRMOptions struct {
	Host     string
	Port     string
	User     string
	Password string //nolint:gosec // false positive for struct field name
	HTTPS    bool
	Insecure bool
	Timeout  time.Duration
}

WinRMOptions holds the configuration for a WinRM connection.

Jump to

Keyboard shortcuts

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