sshx

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package sshx implements native SSH connectivity and SFTP-backed filesystems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentEndpoint

func AgentEndpoint(explicit string) string

AgentEndpoint returns an explicit SSH_AUTH_SOCK value or the native platform default when the platform defines one.

func DeployHelper

func DeployHelper(ctx context.Context, connection *Connection, platform Platform, binaryPath, digest string) (*sftp.Client, io.Closer, error)

DeployHelper uploads a verified Courier binary and starts its embedded SFTP server. The returned closer removes the remote staging directory.

func DetectPlatform

func DetectPlatform(ctx context.Context, runner Runner) (Platform, Archiver, error)

DetectPlatform probes POSIX first, then Windows, and discovers archivers.

Types

type Archiver

type Archiver struct {
	Name    string
	BuiltIn bool
}

Archiver is either a discovered remote executable or the built-in fallback.

func SelectArchiver

func SelectArchiver(platform Platform, available []string) Archiver

SelectArchiver deterministically picks a platform-appropriate executable.

type CapabilityError

type CapabilityError struct {
	Capability string
	Cause      error
}

CapabilityError identifies a remote feature gap eligible for an optional helper.

func (*CapabilityError) Error

func (e *CapabilityError) Error() string

func (*CapabilityError) Unwrap

func (e *CapabilityError) Unwrap() error

type Config

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

Config wraps the established OpenSSH config parser with Courier resolution.

func EmptyConfig

func EmptyConfig(home string) *Config

EmptyConfig returns valid configuration for hosts without a user config file.

func LoadConfig

func LoadConfig(name, home string) (*Config, error)

LoadConfig loads OpenSSH configuration, including Host patterns and Include.

func (*Config) Resolve

func (c *Config) Resolve(alias, explicitUser, defaultUser, knownHosts string) (Target, error)

Resolve applies first-value OpenSSH semantics for required scalar fields.

type Connection

type Connection struct {
	Target Target
	SFTP   *sftp.Client
	SSH    *ssh.Client
	// contains filtered or unexported fields
}

Connection owns SFTP and every SSH hop used to reach it.

func (*Connection) Close

func (c *Connection) Close() error

Close releases SFTP, SSH hops in reverse order, and agent connections.

func (*Connection) Run

func (c *Connection) Run(ctx context.Context, command string) ([]byte, error)

Run executes a fixed remote capability probe with cancellation.

type Factory

type Factory struct {
	Config       *Config
	DefaultUser  string
	KnownHosts   string
	AgentSocket  string
	Prompt       SecretPrompt
	ReadFile     func(string) ([]byte, error)
	DialContext  func(context.Context, string, string) (net.Conn, error)
	DialAgent    func(string) (net.Conn, error)
	NewSFTP      func(*ssh.Client) (*sftp.Client, error)
	SFTPFallback func(context.Context, *Connection, *CapabilityError) (*sftp.Client, io.Closer, error)
	ClientConfig func(Target, []ssh.AuthMethod) (*ssh.ClientConfig, error)
}

Factory resolves configuration and opens independently authenticated clients.

func (Factory) Open

func (f Factory) Open(ctx context.Context, alias, explicitUser string) (*Connection, error)

Open creates a verified ProxyJump chain and SFTP client.

type Jump

type Jump struct {
	User string
	Host string
	Port int
}

Jump is one ProxyJump hop before config resolution.

type Platform

type Platform struct {
	OS   string
	Arch string
}

Platform is a normalized remote operating system and architecture.

type Runner

type Runner interface {
	Run(context.Context, string) ([]byte, error)
}

Runner executes constant remote capability probes.

type SFTPBackend

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

SFTPBackend adapts an authenticated SFTP client to fsx.Backend.

func NewSFTPBackend

func NewSFTPBackend(client *sftp.Client) *SFTPBackend

NewSFTPBackend constructs a POSIX-path remote filesystem.

func (*SFTPBackend) Chmod

func (s *SFTPBackend) Chmod(name string, mode fs.FileMode) error

func (*SFTPBackend) Chtimes

func (s *SFTPBackend) Chtimes(name string, atime, mtime time.Time) error

func (*SFTPBackend) CommitAbsent added in v0.2.0

func (s *SFTPBackend) CommitAbsent(stagePath, destination string) error

CommitAbsent uses the standard SFTP v3 rename, whose contract requires the destination not to exist, instead of the overwrite-capable POSIX extension.

func (*SFTPBackend) Create

func (s *SFTPBackend) Create(name string, mode fs.FileMode) (fsx.Writable, error)

func (*SFTPBackend) Dir

func (*SFTPBackend) Dir(name string) string

func (*SFTPBackend) Join

func (*SFTPBackend) Join(parts ...string) string

func (*SFTPBackend) Lstat

func (s *SFTPBackend) Lstat(name string) (fs.FileInfo, error)

func (*SFTPBackend) MkdirAll

func (s *SFTPBackend) MkdirAll(name string, mode fs.FileMode) error

func (*SFTPBackend) Open

func (s *SFTPBackend) Open(name string) (io.ReadCloser, error)

func (*SFTPBackend) ReadDir

func (s *SFTPBackend) ReadDir(name string) ([]fs.DirEntry, error)
func (s *SFTPBackend) Readlink(name string) (string, error)

func (*SFTPBackend) RemoveAll

func (s *SFTPBackend) RemoveAll(name string) error

func (*SFTPBackend) Rename

func (s *SFTPBackend) Rename(oldPath, newPath string) error
func (s *SFTPBackend) Symlink(target, name string) error

type SecretPrompt

type SecretPrompt func(label string) ([]byte, error)

SecretPrompt obtains a password or key passphrase without command-line use.

type Target

type Target struct {
	Alias          string
	Host           string
	User           string
	Port           int
	IdentityFiles  []string
	ProxyJump      []Jump
	KnownHostsFile string
}

Target is the effective connection configuration for one SSH alias.

func (Target) Address

func (t Target) Address() string

Address returns a host:port network address.

Jump to

Keyboard shortcuts

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