61 lines
1.7 KiB
Go
61 lines
1.7 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.
|
|
// For session-level use, prefer SpawnRemote() + Dial() separately.
|
|
func RemoteDial(ctx context.Context, cfg RemoteConfig) (*Conn, error) {
|
|
proc, err := SpawnRemote(ctx, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
conn, err := Dial(ctx, LocalAddr(proc.Socket))
|
|
if err != nil {
|
|
proc.Close()
|
|
return nil, err
|
|
}
|
|
// Wrap: closing this conn also closes the process.
|
|
origClose := conn.cleanup
|
|
conn.cleanup = func() {
|
|
if origClose != nil {
|
|
origClose()
|
|
}
|
|
proc.Close()
|
|
}
|
|
conn.Info = proc.Info
|
|
return conn, nil
|
|
}
|
|
|
|
// DialSSH connects to a remote tool server via SSH with full config control.
|
|
// Alias for RemoteDial.
|
|
func DialSSH(ctx context.Context, cfg RemoteConfig) (*Conn, error) {
|
|
return RemoteDial(ctx, cfg)
|
|
}
|