sshx

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package sshx implements the managed ssh/scp/sftp surface: system OpenSSH client, ssh-domain authorization, and local fs preflight delegated to the embedding host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrustedBinary

func TrustedBinary() (string, error)

TrustedBinary 返回系统 OpenSSH 客户端的绝对路径。

Types

type Deps

type Deps struct {
	Processes *vbox.Manager
	// Run 覆盖进程执行(测试注入);nil 用 Processes。
	Run ProcessRunner
	// Allowed 判定 ssh 域目标准入(host 接 permissionState.sshAllowed)。
	Allowed func(ctx context.Context, hostport string) bool
	// CheckLocal 是本地路径的 fs 域预检(scp/sftp 读写前)。
	CheckLocal func(ctx context.Context, inv *commands.Invocation, name string, write bool) error
}

Deps 是 Runner 的宿主依赖。

type ProcessRunner

type ProcessRunner func(context.Context, vbox.StartOptions, io.Reader, io.Writer, io.Writer) (int, error)

ProcessRunner 是 SSH 传输进程的执行入口(host 注入 procs 或测试替身)。

type Runner

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

Runner 是托管 SSH 命令面的执行器(ssh/scp/sftp 共用)。

func New

func New(deps Deps) *Runner

func (*Runner) Options

func (r *Runner) Options(ctx context.Context, raw string, port int) (vbox.StartOptions, error)

Options 构造一次 SSH 调用的进程参数(含授权检查与 ssh 配置解析)。

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, opts vbox.StartOptions, in io.Reader, out, errout io.Writer) (int, error)

Run 执行一次 SSH 传输进程。

func (*Runner) SCP

func (s *Runner) SCP(ctx context.Context, inv *commands.Invocation) error

SCP 执行 scp [-r] <src> <dst>(恰一端为远端)。

func (*Runner) SFTP

func (s *Runner) SFTP(ctx context.Context, inv *commands.Invocation) error

SFTP 执行 sftp -b <file|-> <target>(批模式)。

func (*Runner) SSH

func (r *Runner) SSH(ctx context.Context, inv *commands.Invocation) error

SSH 执行 ssh <target> <remote command>。

type Target

type Target struct {
	Host, User     string
	Port           int
	Identities     []string
	IdentitiesOnly bool
	Home           string
}

Target 是解析后的 SSH 目标(host/port/user/密钥)。

func ParseTarget

func ParseTarget(raw string) (Target, error)

ParseTarget 解析 [user@]host[:port](不含 ssh config 展开)。

func ResolveTarget

func ResolveTarget(raw, home string, port int) (Target, error)

ResolveTarget 按 ssh config 展开目标(只解析数据,不执行 ssh -G)。

Jump to

Keyboard shortcuts

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