transport

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

internal/transport/docker.go

internal/transport/ssh.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseArch

func ParseArch(output string) string

func ParsePlatform

func ParsePlatform(output string) string

func ParsePwshArch

func ParsePwshArch(output string) string

func ParsePwshVersion

func ParsePwshVersion(output string) (int, bool)

func ParseShellName

func ParseShellName(output string) string

func PwshArchCommand

func PwshArchCommand() string

func PwshPlatformCommand

func PwshPlatformCommand() string

func StripAnsi

func StripAnsi(s string) string

Types

type DockerTransport

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

DockerTransport implements Transport using the Docker Engine API.

func NewDockerTransport

func NewDockerTransport(cfg target.TargetConfig) *DockerTransport

NewDockerTransport creates a new Docker transport for the given config.

func (*DockerTransport) Close

func (t *DockerTransport) Close() error

Close closes the Docker client.

func (*DockerTransport) Connect

func (t *DockerTransport) Connect(ctx context.Context) error

Connect verifies the container is running and detects the remote environment.

func (*DockerTransport) Exec

func (t *DockerTransport) Exec(ctx context.Context, command string, opts *ExecOptions) (*ExecResult, error)

Exec executes a command in the container via the Docker Exec API.

func (*DockerTransport) HealthCheck

func (t *DockerTransport) HealthCheck(ctx context.Context) error

HealthCheck verifies the container is still running.

func (*DockerTransport) Info

func (t *DockerTransport) Info() *RemoteInfo

func (*DockerTransport) ReadFile

func (t *DockerTransport) ReadFile(ctx context.Context, path string) ([]byte, error)

ReadFile reads a file from the container using CopyFromContainer.

func (*DockerTransport) State

func (t *DockerTransport) State() TransportState

func (*DockerTransport) Type

func (t *DockerTransport) Type() TransportType

func (*DockerTransport) WriteFile

func (t *DockerTransport) WriteFile(ctx context.Context, path string, content []byte) error

WriteFile writes a file to the container using CopyToContainer.

type ExecOptions

type ExecOptions struct {
	Timeout int
	Stdin   io.Reader
}

type ExecResult

type ExecResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type RemoteInfo

type RemoteInfo struct {
	Shell    string
	Platform string
	Arch     string
	Homedir  string
}

type SSHTransport

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

SSHTransport implements Transport over SSH using golang.org/x/crypto/ssh.

func NewSSHTransport

func NewSSHTransport(cfg target.TargetConfig) *SSHTransport

NewSSHTransport creates a new SSH transport for the given config.

func (*SSHTransport) Close

func (t *SSHTransport) Close() error

Close terminates the SSH connection.

func (*SSHTransport) Connect

func (t *SSHTransport) Connect(ctx context.Context) error

Connect establishes the SSH connection, SFTP subsystem, and detects remote environment.

func (*SSHTransport) Exec

func (t *SSHTransport) Exec(ctx context.Context, command string, opts *ExecOptions) (*ExecResult, error)

Exec executes a command on the remote host via a new SSH session channel.

func (*SSHTransport) ForwardPort

func (t *SSHTransport) ForwardPort(localAddr, remoteAddr string) (net.Listener, error)

ForwardPort creates a local TCP listener that forwards to a remote address via SSH. Returns the listener (caller must close it) and starts forwarding in the background.

func (*SSHTransport) HealthCheck

func (t *SSHTransport) HealthCheck(ctx context.Context) error

HealthCheck verifies the connection is still alive.

func (*SSHTransport) Info

func (t *SSHTransport) Info() *RemoteInfo

func (*SSHTransport) ReadFile

func (t *SSHTransport) ReadFile(ctx context.Context, path string) ([]byte, error)

ReadFile reads a file from the remote via SFTP.

func (*SSHTransport) State

func (t *SSHTransport) State() TransportState

func (*SSHTransport) Type

func (t *SSHTransport) Type() TransportType

func (*SSHTransport) WriteFile

func (t *SSHTransport) WriteFile(ctx context.Context, path string, content []byte) error

WriteFile writes a file on the remote via SFTP.

type Transport

type Transport interface {
	Type() TransportType
	State() TransportState
	Connect(ctx context.Context) error
	Close() error
	Exec(ctx context.Context, command string, opts *ExecOptions) (*ExecResult, error)
	ReadFile(ctx context.Context, path string) ([]byte, error)
	WriteFile(ctx context.Context, path string, content []byte) error
	Info() *RemoteInfo
	HealthCheck(ctx context.Context) error
}

func NewTransport

func NewTransport(cfg target.TargetConfig) (Transport, error)

NewTransport creates the appropriate transport for a target config.

type TransportState

type TransportState string
const (
	StateConnecting   TransportState = "connecting"
	StateConnected    TransportState = "connected"
	StateDisconnected TransportState = "disconnected"
	StateError        TransportState = "error"
)

type TransportType

type TransportType string
const (
	TransportSSH    TransportType = "ssh"
	TransportDocker TransportType = "docker"
)

Jump to

Keyboard shortcuts

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