ui

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 52 Imported by: 0

Documentation

Overview

Package ui implements the bubbletea TUI, SSH helpers, and CUE recipe execution for honey.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialSSHLeafForRecord added in v0.2.7

func DialSSHLeafForRecord(user string, r hosts.Record) (*ssh.Client, func(), error)

DialSSHLeafForRecord returns a leaf *ssh.Client for SSH to hosts.Record.PrimaryIP (same transport as the TUI). Kubernetes pod records are not supported for raw SSH in this helper.

func FormatTargetForDryRun

func FormatTargetForDryRun(r hosts.Record) string

FormatTargetForDryRun returns a string describing how the target will be connected to.

func PrintStaticTable added in v0.2.6

func PrintStaticTable(records []hosts.Record) error

PrintStaticTable prints the records as an ASCII table to stdout and exits.

func ResizeFromColsRows added in v0.2.7

func ResizeFromColsRows(cols, rows int) *remotecommand.TerminalSize

ResizeFromColsRows returns a terminal size for k8s remotecommand, or nil if cols or rows are non-positive.

func RunCueRecipeSteps

func RunCueRecipeSteps(out io.Writer, recipe cuetry.Recipe, recipeDir string, records []hosts.Record, sshUser string, execute bool, cliEnv map[string]string) error

RunCueRecipeSteps executes a CUE recipe over a slice of target records without streaming. cliEnv is merged into each command/script step's remote env (overrides recipe env on duplicate keys); nil is treated as empty.

func RunK8sPodWebTTY added in v0.2.7

func RunK8sPodWebTTY(
	ctx context.Context,
	r hosts.Record,
	stdin io.Reader,
	stdout, stderr io.Writer,
	cols, rows int,
	resizeCh <-chan *remotecommand.TerminalSize,
) error

RunK8sPodWebTTY runs an interactive shell in a Kubernetes pod with TTY over stdin/stdout/stderr, using the same dial path as the CLI (ephemeral debug container). Resize events are consumed from resizeCh.

func RunTable

func RunTable(records []hosts.Record, sshUser string) error

RunTable shows an interactive table and optionally execs ssh. After SSH/Tunnel disconnects, it returns to the UI.

func StreamCueRecipeSteps

func StreamCueRecipeSteps(recipe cuetry.Recipe, recipeDir string, records []hosts.Record, sshUser string, cliEnv map[string]string, out chan<- HostExecResult) error

StreamCueRecipeSteps executes a CUE recipe step-by-step, streaming results.

func StreamSFTPDownloadParallel

func StreamSFTPDownloadParallel(user string, jobs []SFTPDownloadJob, maxConc int, out chan<- HostExecResult, cache *ClientCache) error

StreamSFTPDownloadParallel downloads files from multiple hosts in parallel.

func StreamSFTPUploadParallel

func StreamSFTPUploadParallel(user string, recs []hosts.Record, localAbs, remotePath string, maxConc int, out chan<- HostExecResult, cache *ClientCache) error

StreamSFTPUploadParallel uploads the same local file to remotePath on each record (SFTP over DialHoneyClient). Failures on one host do not cancel others.

func StreamSSHParallel

func StreamSSHParallel(user string, jobs []hosts.Record, remoteCmdFunc func(hosts.Record) string, maxConc int, out chan<- HostExecResult, cache *ClientCache) error

StreamSSHParallel runs the command on records and streams results to out channel. It does not close the channel itself.

func StreamScriptUploadRunParallel

func StreamScriptUploadRunParallel(user string, recs []hosts.Record, localAbs, remotePath string, remoteCmdFunc func(hosts.Record) string, maxConc int, out chan<- HostExecResult, cache *ClientCache) error

StreamScriptUploadRunParallel uploads a script and executes it on multiple hosts in parallel.

Types

type ClientCache

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

ClientCache maintains a pool of open HostClient connections for reuse across steps.

func NewClientCache

func NewClientCache() *ClientCache

NewClientCache creates a new initialized ClientCache.

func (*ClientCache) CloseAll

func (c *ClientCache) CloseAll()

CloseAll closes all cached connections and clears the cache.

func (*ClientCache) GetOrDial

func (c *ClientCache) GetOrDial(user string, r hosts.Record) (HostClient, error)

GetOrDial returns an existing connection or dials a new one and stores it.

type Executor

type Executor interface {
	Dial(user string, r hosts.Record) (HostClient, error)
	RunInteractive(user string, r hosts.Record) error
	RunTunnel(user string, r hosts.Record, localFwd string) error
}

Executor defines the interface for creating HostClients and running interactive sessions.

var DefaultExecutor Executor = defaultSSHExecutor{}

DefaultExecutor is the default implementation for remote execution.

func GetExecutor

func GetExecutor(r hosts.Record) Executor

GetExecutor returns the appropriate Executor for a host record.

type HoneyClient

type HoneyClient struct {
	*goph.Client
	// contains filtered or unexported fields
}

HoneyClient wraps goph.Client so Close() also shuts down ProxyJump bastion clients.

func DialHoneyClient

func DialHoneyClient(userOverride, hostAlias string) (*HoneyClient, error)

DialHoneyClient opens SSH using ~/.ssh/config (User, HostName, Port, IdentityFile, ProxyJump, StrictHostKeyChecking, UserKnownHostsFile, GlobalKnownHostsFile) and known_hosts verification via golang.org/x/crypto/ssh/knownhosts (see hostKeyCallbackForAlias).

func (*HoneyClient) Close

func (h *HoneyClient) Close() error

Close closes the target session transport, then any bastion SSH clients (reverse order).

type HostClient

type HostClient interface {
	Run(cmd string) ([]byte, error)
	Upload(localPath, remotePath string) error
	Download(remotePath, localPath string) error
	Close() error
}

HostClient defines the interface for executing commands and transferring files on a host.

type HostExecResult

type HostExecResult struct {
	Name     string
	IP       string
	Provider string
	Success  bool
	ExitCode int
	Output   string
	ErrMsg   string // transport / spawn failure (not remote stderr)
}

HostExecResult is the outcome of one non-interactive ssh run.

func ExecuteSFTPDownloadParallel

func ExecuteSFTPDownloadParallel(user string, jobs []SFTPDownloadJob, maxConc int) ([]HostExecResult, error)

ExecuteSFTPDownloadParallel runs each download job (possibly different local paths per host) in parallel.

func ExecuteSFTPUploadParallel

func ExecuteSFTPUploadParallel(user string, recs []hosts.Record, localAbs, remotePath string, maxConc int) ([]HostExecResult, error)

ExecuteSFTPUploadParallel executes an SFTP upload in parallel across multiple hosts and returns results synchronously.

func ExecuteSSHParallel

func ExecuteSSHParallel(user string, recs []hosts.Record, remoteCmdFunc func(hosts.Record) string, maxConc int) ([]HostExecResult, error)

ExecuteSSHParallel runs the same remote shell command on every record that has PrimaryIP set. Failures on individual hosts do not cancel others. It uses DialHoneyClient (golang.org/x/crypto/ssh + ~/.ssh/config) with known_hosts verification.

func ExecuteScriptUploadRunParallel

func ExecuteScriptUploadRunParallel(user string, recs []hosts.Record, localAbs, remotePath, remoteCmd string, maxConc int) ([]HostExecResult, error)

ExecuteScriptUploadRunParallel uploads localAbs to remotePath on each host over SFTP, then runs remoteCmd on the same SSH connection (one session per host per step).

func SortHostExecForUI

func SortHostExecForUI(s []HostExecResult) []HostExecResult

SortHostExecForUI orders failures first, then host name (case-insensitive).

type SFTPDownloadJob

type SFTPDownloadJob struct {
	Record     hosts.Record
	LocalAbs   string
	RemotePath string
}

SFTPDownloadJob is one remote→local file copy for a specific host.

Jump to

Keyboard shortcuts

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