ollie/toolsrv/remote.go

53 lines
1.4 KiB
Go

// Package toolsrv remote types.
//
// RemoteConfig and HostInfo are used by the transport layer and session
// creation. The actual client implementation lives in conn.go; the
// transport (SSH bootstrap) lives in transport.go.
package toolsrv
import (
"context"
)
// HostInfo holds environment details from the remote host.
type HostInfo struct {
Platform string `json:"platform"`
Arch string `json:"arch"`
IsGitRepo bool `json:"is_git_repo"`
}
// RemoteConfig holds the parameters for connecting to a remote host.
type RemoteConfig struct {
// SSHTarget is the SSH destination (e.g., "user@host" or an SSH config alias).
SSHTarget string
// CWD is the working directory on the remote host.
CWD string
// ToolsPath overrides the remote tool scripts path.
ToolsPath string
// Yolo disables sandbox enforcement on the remote.
Yolo bool
}
// RemoteDial opens an SSH connection to the remote host and returns a *Conn.
// Convenience wrapper: spawns the remote process and dials a single connection.
func RemoteDial(ctx context.Context, cfg RemoteConfig) (*Conn, error) {
proc, err := SpawnRemote(ctx, cfg)
if err != nil {
return nil, err
}
conn, err := Dial(ctx, proc.Socket)
if err != nil {
proc.Close()
return nil, err
}
origClose := conn.cleanup
conn.cleanup = func() {
if origClose != nil {
origClose()
}
proc.Close()
}
conn.Info = proc.Info
return conn, nil
}