transport

package
v0.0.0-...-dd62abe Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package transport contains types and interfaces related to transport mechanisms used to connect to managed hosts in Forge.

Index

Constants

View Source
const (
	DefaultSSHPort               uint16        = 22
	DefaultUseKnownHostsFile     bool          = true
	DefaultAddUnknownHostsToFile bool          = true
	DefaultSSHConnectionTimeout  time.Duration = 10 * time.Second
)

Variables

This section is empty.

Functions

func DefaultKnownHostsPath

func DefaultKnownHostsPath() string

Types

type Escalation

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

Escalation defines the privilege escalation configuration for a transport action.

func NewEscalation

func NewEscalation(password string) *Escalation

NewEscalation creates a new escalation that just escalates privileges, does not impersonate a user, and requires a password.

func NewImpersonation

func NewImpersonation(username, password string) *Escalation

NewImpersonation creates a new escalation that impersonates the given user.

func NewNoPasswordEscalation

func NewNoPasswordEscalation() *Escalation

NewNoPasswordEscalation creates a new escalation that escalates privileges, does not impersonate a user, and does not require a password.

func NewNoPasswordImpersonation

func NewNoPasswordImpersonation(username string) *Escalation

NewNoPasswordImpersonation creates a new escalation that impersonates the given user and does not require a password.

func (*Escalation) Pass

func (i *Escalation) Pass() string

Pass implements Escalation.

func (*Escalation) User

func (i *Escalation) User() string

User implements Escalation.

type MockTransport

type MockTransport struct {
	TransportType TransportType
}

MockTransport is a mock implementation of the Transport interface for testing purposes.

func NewMockTransport

func NewMockTransport() *MockTransport

NewMockTransport creates a new instance of MockTransport with default settings.

func (*MockTransport) Arch

func (m *MockTransport) Arch() (string, error)

Arch implements Transport.

func (*MockTransport) Close

func (m *MockTransport) Close() error

Close implements Transport.

func (*MockTransport) Connect

func (m *MockTransport) Connect() error

Connect implements Transport.

func (*MockTransport) OS

func (m *MockTransport) OS() (string, error)

OS implements Transport.

func (*MockTransport) StartPluginSession

func (w *MockTransport) StartPluginSession(
	ctx context.Context,
	basePath string,
	namespace string,
	pluginName string,
	escalation *Escalation,
) (plugin.Session, error)

StartPluginSession implements Transport.

func (*MockTransport) Type

func (m *MockTransport) Type() TransportType

Type implements Transport.

type SSHTransportBuilder

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

SSHTransportBuilder is a builder for constructing SSH transport instances.

func NewSSHBuilder

func NewSSHBuilder() *SSHTransportBuilder

NewSSHBuilder creates a new SSHTransportBuilder with default settings.

func (*SSHTransportBuilder) Build

func (b *SSHTransportBuilder) Build() (Transport, error)

Build constructs the SSHTransport based on the builder's configuration.

func (*SSHTransportBuilder) DontUseKnownHosts

func (b *SSHTransportBuilder) DontUseKnownHosts() *SSHTransportBuilder

DontUseKnownHosts disables the use of a known hosts file for the SSH transport.

func (*SSHTransportBuilder) UseKnownHosts

func (b *SSHTransportBuilder) UseKnownHosts(knownHostsPath string) *SSHTransportBuilder

UseKnownHosts enables the use of a known hosts file for the SSH transport, adding unknown hosts to the file.

func (*SSHTransportBuilder) UseStrictKnownHosts

func (b *SSHTransportBuilder) UseStrictKnownHosts(knownHostsPath string) *SSHTransportBuilder

UseStrictKnownHosts enables the use of a known hosts file for the SSH transport, enforcing strict host key checking.

func (*SSHTransportBuilder) WithConnectionTimeout

func (b *SSHTransportBuilder) WithConnectionTimeout(timeout time.Duration) *SSHTransportBuilder

WithConnectionTimeout sets the connection timeout for the SSH transport.

func (*SSHTransportBuilder) WithHost

func (b *SSHTransportBuilder) WithHost(host string) *SSHTransportBuilder

WithHost sets the host for the SSH transport.

func (*SSHTransportBuilder) WithPasswordAuth

func (b *SSHTransportBuilder) WithPasswordAuth(password string) *SSHTransportBuilder

WithPasswordAuth disables password authentication for the SSH transport.

func (*SSHTransportBuilder) WithPort

func (b *SSHTransportBuilder) WithPort(port uint16) *SSHTransportBuilder

WithPort sets the port for the SSH transport.

func (*SSHTransportBuilder) WithPublicKeyAuth

func (b *SSHTransportBuilder) WithPublicKeyAuth(privateKey []byte) *SSHTransportBuilder

WithPublicKeyAuth enables public key authentication for the SSH transport.

func (*SSHTransportBuilder) WithPublicKeyAuthWithPass

func (b *SSHTransportBuilder) WithPublicKeyAuthWithPass(privateKey []byte, privateKeyPass string) *SSHTransportBuilder

WithPublicKeyAuthWithPass enables public key authentication with a passphrase for the SSH transport.

func (*SSHTransportBuilder) WithTempPath

func (b *SSHTransportBuilder) WithTempPath(tempPath string) *SSHTransportBuilder

WithTempPath sets the temporary path for the SSH transport.

func (*SSHTransportBuilder) WithUser

func (b *SSHTransportBuilder) WithUser(user string) *SSHTransportBuilder

WithUser sets the user for the SSH transport.

func (*SSHTransportBuilder) WithoutPasswordAuth

func (b *SSHTransportBuilder) WithoutPasswordAuth() *SSHTransportBuilder

WithoutPasswordAuth disables password authentication for the SSH transport.

func (*SSHTransportBuilder) WithoutPublicKeyAuth

func (b *SSHTransportBuilder) WithoutPublicKeyAuth() *SSHTransportBuilder

WithoutPublicKeyAuth disables public key authentication for the SSH transport.

type Transport

type Transport interface {
	Type() TransportType   // Type returns the type of transport.  This is used for testing only.
	OS() (string, error)   // OS returns the operating system of the managed system.
	Arch() (string, error) // Arch returns the architecture of the managed system.

	Connect() error // Connect establishes the transport connection.
	Close() error   // Close terminates the transport connection.

	// StartPluginSession initializes a plugin session.
	//
	// basePath specifies the base path for plugins.
	//
	// namespace specifies the namespace of the plugin in the filename.
	//
	// pluginName specifies the name of the plugin in the filename.
	// The OS, architecture, and extension, if applicable, will be appended to this path.
	//
	// escalation specifies the escalation method to use when starting the plugin session, if any.
	// This is nil if no escalation is needed.
	//
	// It returns a plugin.Session that represents the running plugin process and provides access to its standard input,
	// output, and error streams.
	StartPluginSession(
		ctx context.Context,
		basePath string,
		namespace string,
		pluginName string,
		escalation *Escalation,
	) (plugin.Session, error)
}

Transport defines the transport mechanism for interacting a managed system.

var (
	LocalTransport Transport = &localTransport{}
)

type TransportType

type TransportType string

TransportType represents the type of transport used for connecting to managed systems.

const (
	TransportTypeLocal TransportType = "local"
	TransportTypeSSH   TransportType = "ssh"
)

Jump to

Keyboard shortcuts

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