conncontroller

package
v0.11.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Status_Init         = "init"
	Status_Connecting   = "connecting"
	Status_Connected    = "connected"
	Status_Disconnected = "disconnected"
	Status_Error        = "error"
)
View Source
const DefaultConnectionTimeout = 60 * time.Second

Variables

View Source
var ConnServerCmdTemplate = strings.TrimSpace(
	strings.Join([]string{
		"%s version 2> /dev/null || (echo -n \"not-installed \"; uname -sm);",
		"exec %s connserver",
	}, "\n"))

Functions

func DisconnectClient

func DisconnectClient(opts *remote.SSHOpts) error

func EnsureConnection

func EnsureConnection(ctx context.Context, connName string) error

Convenience function for ensuring a connection is established

func GetAllConnStatus

func GetAllConnStatus() []wshrpc.ConnStatus

func GetConnectionsFromConfig

func GetConnectionsFromConfig() ([]string, error)

func GetConnectionsFromInternalConfig added in v0.10.0

func GetConnectionsFromInternalConfig() []string

func GetConnectionsList

func GetConnectionsList() ([]string, error)

func GetNumSSHHasConnected added in v0.9.3

func GetNumSSHHasConnected() int

func IsWshVersionUpToDate added in v0.11.0

func IsWshVersionUpToDate(logCtx context.Context, wshVersionLine string) (bool, string, string, error)

expects the output of `wsh version` which looks like `wsh v0.10.4` or "not-installed os [arch]" returns (up-to-date, semver, osArchStr, error) if not up to date, or error, version might be ""

func WithLockRtn added in v0.11.0

func WithLockRtn[T any](conn *SSHConn, fn func() T) T

Types

type SSHConn

type SSHConn struct {
	Lock               *sync.Mutex
	Status             string
	WshEnabled         *atomic.Bool
	Opts               *remote.SSHOpts
	Client             *ssh.Client
	DomainSockName     string // if "", then no domain socket
	DomainSockListener net.Listener
	ConnController     *ssh.Session
	Error              string
	WshError           string
	NoWshReason        string
	WshVersion         string
	HasWaiter          *atomic.Bool
	LastConnectTime    int64
	ActiveConnNum      int
}

func GetConn

func GetConn(ctx context.Context, opts *remote.SSHOpts, connFlags *wshrpc.ConnKeywords) *SSHConn

does NOT connect, can return nil if connection does not exist

func (*SSHConn) ClearWshError added in v0.11.0

func (conn *SSHConn) ClearWshError()

func (*SSHConn) Close

func (conn *SSHConn) Close() error

func (*SSHConn) Connect

func (conn *SSHConn) Connect(ctx context.Context, connFlags *wshrpc.ConnKeywords) error

does not return an error since that error is stored inside of SSHConn

func (*SSHConn) Debugf added in v0.11.0

func (conn *SSHConn) Debugf(ctx context.Context, format string, args ...any)

func (*SSHConn) DeriveConnStatus

func (conn *SSHConn) DeriveConnStatus() wshrpc.ConnStatus

func (*SSHConn) FireConnChangeEvent

func (conn *SSHConn) FireConnChangeEvent()

func (*SSHConn) GetClient

func (conn *SSHConn) GetClient() *ssh.Client

func (*SSHConn) GetConfigShellPath added in v0.11.0

func (conn *SSHConn) GetConfigShellPath() string

func (*SSHConn) GetDomainSocketName

func (conn *SSHConn) GetDomainSocketName() string

func (*SSHConn) GetName

func (conn *SSHConn) GetName() string

func (*SSHConn) GetStatus

func (conn *SSHConn) GetStatus() string

func (*SSHConn) Infof added in v0.11.0

func (conn *SSHConn) Infof(ctx context.Context, format string, args ...any)

func (*SSHConn) InstallWsh added in v0.11.0

func (conn *SSHConn) InstallWsh(ctx context.Context, osArchStr string) error

func (*SSHConn) OpenDomainSocketListener

func (conn *SSHConn) OpenDomainSocketListener(ctx context.Context) error

func (*SSHConn) SetWshError added in v0.11.0

func (conn *SSHConn) SetWshError(err error)

func (*SSHConn) StartConnServer

func (conn *SSHConn) StartConnServer(ctx context.Context, afterUpdate bool) (bool, string, string, error)

returns (needsInstall, clientVersion, osArchStr, error) if wsh is not installed, the clientVersion will be "not-installed", and it will also return an osArchStr if clientVersion is set, then no osArchStr will be returned

func (*SSHConn) UpdateWsh added in v0.11.0

func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, remoteInfo *wshrpc.RemoteInfo) error

func (*SSHConn) WaitForConnect

func (conn *SSHConn) WaitForConnect(ctx context.Context) error

func (*SSHConn) WithLock

func (conn *SSHConn) WithLock(fn func())

type WshCheckResult added in v0.11.0

type WshCheckResult struct {
	WshEnabled    bool
	ClientVersion string
	NoWshReason   string
	WshError      error
}

type WshInstallOpts

type WshInstallOpts struct {
	Force        bool
	NoUserPrompt bool
}

Jump to

Keyboard shortcuts

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