Thanks to visit codestin.com
Credit goes to pkg.go.dev

workspacesdk

package
v2.26.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentSSHPort             = tailnet.WorkspaceAgentSSHPort
	AgentStandardSSHPort     = tailnet.WorkspaceAgentStandardSSHPort
	AgentReconnectingPTYPort = tailnet.WorkspaceAgentReconnectingPTYPort
	AgentSpeedtestPort       = tailnet.WorkspaceAgentSpeedtestPort
	// AgentHTTPAPIServerPort serves a HTTP server with endpoints for e.g.
	// gathering agent statistics.
	AgentHTTPAPIServerPort = 4

	// AgentMinimumListeningPort is the minimum port that the listening-ports
	// endpoint will return to the client, and the minimum port that is accepted
	// by the proxy applications endpoint. Coder consumes ports 1-4 at the
	// moment, and we reserve some extra ports for future use. Port 9 and up are
	// available for the user.
	//
	// This is not enforced in the CLI intentionally as we don't really care
	// *that* much. The user could bypass this in the CLI by using SSH instead
	// anyways.
	AgentMinimumListeningPort = 9
)
View Source
const (
	AgentAPIMismatchMessage = "Unknown or unsupported API version"

	CoordinateAPIInvalidResumeToken = "Invalid resume token"
)

Variables

View Source
var AgentIgnoredListeningPorts = map[uint16]struct{}{
	0: {},

	1: {},
	2: {},
	3: {},
	4: {},
	5: {},
	6: {},
	7: {},
	8: {},

	20: {},
	21: {},

	22: {},

	23: {},

	25: {},

	53: {},

	110: {},

	143: {},

	179: {},

	389: {},
	636: {},

	465: {},

	587: {},

	989: {},
	990: {},

	993: {},

	995: {},

	3306: {},

	3389: {},

	5432: {},

	27017: {},
	27018: {},
	27019: {},
	28017: {},
}

AgentIgnoredListeningPorts contains a list of ports to ignore when looking for running applications inside a workspace. We want to ignore non-HTTP servers, so we pre-populate this list with common ports that are not HTTP servers.

This is implemented as a map for fast lookup.

View Source
var ErrSkipClose = xerrors.New("skip tailnet close")

Functions

func ExistsViaCoderConnect added in v2.22.0

func ExistsViaCoderConnect(ctx context.Context, hostname string) (bool, error)

ExistsViaCoderConnect checks if the given hostname exists via Coder Connect. This doesn't guarantee the workspace is actually reachable, if, for example, its agent is unhealthy, but rather that Coder Connect knows about the workspace and advertises the hostname via DNS.

func WithTestOnlyCoderContextResolver added in v2.22.0

func WithTestOnlyCoderContextResolver(ctx context.Context, r Resolver) context.Context

Types

type AgentConn

type AgentConn interface {
	TailnetConn() *tailnet.Conn

	AwaitReachable(ctx context.Context) bool
	Close() error
	DebugLogs(ctx context.Context) ([]byte, error)
	DebugMagicsock(ctx context.Context) ([]byte, error)
	DebugManifest(ctx context.Context) ([]byte, error)
	DialContext(ctx context.Context, network string, addr string) (net.Conn, error)
	GetPeerDiagnostics() tailnet.PeerDiagnostics
	ListContainers(ctx context.Context) (codersdk.WorkspaceAgentListContainersResponse, error)
	ListeningPorts(ctx context.Context) (codersdk.WorkspaceAgentListeningPortsResponse, error)
	Netcheck(ctx context.Context) (healthsdk.AgentNetcheckReport, error)
	Ping(ctx context.Context) (time.Duration, bool, *ipnstate.PingResult, error)
	PrometheusMetrics(ctx context.Context) ([]byte, error)
	ReconnectingPTY(ctx context.Context, id uuid.UUID, height uint16, width uint16, command string, initOpts ...AgentReconnectingPTYInitOption) (net.Conn, error)
	RecreateDevcontainer(ctx context.Context, devcontainerID string) (codersdk.Response, error)
	SSH(ctx context.Context) (*gonet.TCPConn, error)
	SSHClient(ctx context.Context) (*ssh.Client, error)
	SSHClientOnPort(ctx context.Context, port uint16) (*ssh.Client, error)
	SSHOnPort(ctx context.Context, port uint16) (*gonet.TCPConn, error)
	Speedtest(ctx context.Context, direction speedtest.Direction, duration time.Duration) ([]speedtest.Result, error)
	WatchContainers(ctx context.Context, logger slog.Logger) (<-chan codersdk.WorkspaceAgentListContainersResponse, io.Closer, error)
}

AgentConn represents a connection to a workspace agent. @typescript-ignore AgentConn

func NewAgentConn

func NewAgentConn(conn *tailnet.Conn, opts AgentConnOptions) AgentConn

NewAgentConn creates a new WorkspaceAgentConn. `conn` may be unique to the WorkspaceAgentConn, or it may be shared in the case of coderd. If the conn is shared and closing it is undesirable, you may return ErrNoClose from opts.CloseFunc. This will ensure the underlying conn is not closed.

type AgentConnOptions

type AgentConnOptions struct {
	AgentID   uuid.UUID
	CloseFunc func() error
}

@typescript-ignore AgentConnOptions

type AgentConnectionInfo

type AgentConnectionInfo struct {
	DERPMap                  *tailcfg.DERPMap `json:"derp_map"`
	DERPForceWebSockets      bool             `json:"derp_force_websockets"`
	DisableDirectConnections bool             `json:"disable_direct_connections"`
	HostnameSuffix           string           `json:"hostname_suffix,omitempty"`
}

AgentConnectionInfo returns required information for establishing a connection with a workspace. @typescript-ignore AgentConnectionInfo

type AgentReconnectingPTYInit

type AgentReconnectingPTYInit struct {
	ID      uuid.UUID
	Height  uint16
	Width   uint16
	Command string
	// Container, if set, will attempt to exec into a running container visible to the agent.
	// This should be a unique container ID (implementation-dependent).
	Container string
	// ContainerUser, if set, will set the target user when execing into a container.
	// This can be a username or UID, depending on the underlying implementation.
	// This is ignored if Container is not set.
	ContainerUser string

	BackendType string
}

AgentReconnectingPTYInit initializes a new reconnecting PTY session. @typescript-ignore AgentReconnectingPTYInit

type AgentReconnectingPTYInitOption added in v2.21.0

type AgentReconnectingPTYInitOption func(*AgentReconnectingPTYInit)

AgentReconnectingPTYInitOption is a functional option for AgentReconnectingPTYInit.

func AgentReconnectingPTYInitWithContainer added in v2.21.0

func AgentReconnectingPTYInitWithContainer(container, containerUser string) AgentReconnectingPTYInitOption

AgentReconnectingPTYInitWithContainer sets the container and container user for the reconnecting PTY session.

type Client

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

func New

func New(c *codersdk.Client) *Client

func (*Client) AgentConnectionInfo

func (c *Client) AgentConnectionInfo(ctx context.Context, agentID uuid.UUID) (AgentConnectionInfo, error)

func (*Client) AgentConnectionInfoGeneric

func (c *Client) AgentConnectionInfoGeneric(ctx context.Context) (AgentConnectionInfo, error)

func (*Client) AgentReconnectingPTY

func (c *Client) AgentReconnectingPTY(ctx context.Context, opts WorkspaceAgentReconnectingPTYOpts) (net.Conn, error)

AgentReconnectingPTY spawns a PTY that reconnects using the token provided. It communicates using `agent.ReconnectingPTYRequest` marshaled as JSON. Responses are PTY output that can be rendered.

func (*Client) DialAgent

func (c *Client) DialAgent(dialCtx context.Context, agentID uuid.UUID, options *DialAgentOptions) (agentConn AgentConn, err error)

func (*Client) IsCoderConnectRunning added in v2.22.0

func (c *Client) IsCoderConnectRunning(ctx context.Context, o CoderConnectQueryOptions) (bool, error)

IsCoderConnectRunning checks if Coder Connect (OS level tunnel to workspaces) is running on the system. If you already know the hostname suffix your deployment uses, you can pass it in the CoderConnectQueryOptions to avoid an API call to AgentConnectionInfoGeneric.

func (*Client) RewriteDERPMap added in v2.25.0

func (c *Client) RewriteDERPMap(derpMap *tailcfg.DERPMap)

RewriteDERPMap rewrites the DERP map to use the configured access URL of the client as the "embedded relay" access URL.

See tailnet.RewriteDERPMapDefaultRelay for more details on why this is necessary.

type CoderConnectQueryOptions added in v2.22.0

type CoderConnectQueryOptions struct {
	HostnameSuffix string
}

type DialAgentOptions

type DialAgentOptions struct {
	Logger slog.Logger
	// BlockEndpoints forced a direct connection through DERP. The Client may
	// have DisableDirect set which will override this value.
	BlockEndpoints bool
	// CaptureHook is a callback that captures Disco packets and packets sent
	// into the tailnet tunnel.
	CaptureHook capture.Callback
	// Whether the client will send network telemetry events.
	// Enable instead of Disable so it's initialized to false (in tests).
	EnableTelemetry bool
}

@typescript-ignore DialAgentOptions

type ReconnectingPTYRequest

type ReconnectingPTYRequest struct {
	Data   string `json:"data,omitempty"`
	Height uint16 `json:"height,omitempty"`
	Width  uint16 `json:"width,omitempty"`
}

ReconnectingPTYRequest is sent from the client to the server to pipe data to a PTY. @typescript-ignore ReconnectingPTYRequest

type Resolver added in v2.22.0

type Resolver interface {
	LookupIP(ctx context.Context, network, host string) ([]net.IP, error)
}

type WebsocketDialer added in v2.18.0

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

func NewWebsocketDialer added in v2.18.0

func NewWebsocketDialer(
	logger slog.Logger, u *url.URL, websocketOptions *websocket.DialOptions,
	dialerOptions ...WebsocketDialerOption,
) *WebsocketDialer

func (*WebsocketDialer) Connected added in v2.18.0

func (w *WebsocketDialer) Connected() <-chan error

func (*WebsocketDialer) Dial added in v2.18.0

type WebsocketDialerOption added in v2.18.0

type WebsocketDialerOption func(*WebsocketDialer)

func WithWorkspaceUpdates added in v2.18.0

func WithWorkspaceUpdates(req *proto.WorkspaceUpdatesRequest) WebsocketDialerOption

type WorkspaceAgentReconnectingPTYOpts

type WorkspaceAgentReconnectingPTYOpts struct {
	AgentID   uuid.UUID
	Reconnect uuid.UUID
	Width     uint16
	Height    uint16
	Command   string

	// SignedToken is an optional signed token from the
	// issue-reconnecting-pty-signed-token endpoint. If set, the session token
	// on the client will not be sent.
	SignedToken string

	// Experimental: Container, if set, will attempt to exec into a running container
	// visible to the agent. This should be a unique container ID
	// (implementation-dependent).
	// ContainerUser is the user as which to exec into the container.
	// NOTE: This feature is currently experimental and is currently "opt-in".
	// In order to use this feature, the agent must have the environment variable
	// CODER_AGENT_DEVCONTAINERS_ENABLE set to "true".
	Container     string
	ContainerUser string

	// BackendType is the type of backend to use for the PTY. If not set, the
	// workspace agent will attempt to determine the preferred backend type.
	// Supported values are "screen" and "buffered".
	BackendType string
}

@typescript-ignore:WorkspaceAgentReconnectingPTYOpts

Directories

Path Synopsis
Package agentconnmock is a generated GoMock package.
Package agentconnmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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