Movatterモバイル変換


[0]ホーム

URL:


workspacesdk

package
v2.23.0Latest Latest
Warning

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

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

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

View Source
const (AgentSSHPort             =tailnet.WorkspaceAgentSSHPortAgentStandardSSHPort     =tailnet.WorkspaceAgentStandardSSHPortAgentReconnectingPTYPort =tailnet.WorkspaceAgentReconnectingPTYPortAgentSpeedtestPort       =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 forrunning 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

funcExistsViaCoderConnectadded inv2.22.0

func ExistsViaCoderConnect(ctxcontext.Context, hostnamestring) (bool,error)

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

funcWithTestOnlyCoderContextResolveradded inv2.22.0

func WithTestOnlyCoderContextResolver(ctxcontext.Context, rResolver)context.Context

Types

typeAgentConn

type AgentConn struct {*tailnet.Conn// contains filtered or unexported fields}

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

funcNewAgentConn

func NewAgentConn(conn *tailnet.Conn, optsAgentConnOptions) *AgentConn

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

func (*AgentConn)AwaitReachable

func (c *AgentConn) AwaitReachable(ctxcontext.Context)bool

AwaitReachable waits for the agent to be reachable.

func (*AgentConn)Close

func (c *AgentConn) Close()error

Close ends the connection to the workspace agent.

func (*AgentConn)DebugLogs

func (c *AgentConn) DebugLogs(ctxcontext.Context) ([]byte,error)

DebugLogs returns up to the last 10MB of `/tmp/coder-agent.log`

func (*AgentConn)DebugMagicsock

func (c *AgentConn) DebugMagicsock(ctxcontext.Context) ([]byte,error)

DebugMagicsock makes a request to the workspace agent's magicsock debug endpoint.

func (*AgentConn)DebugManifest

func (c *AgentConn) DebugManifest(ctxcontext.Context) ([]byte,error)

DebugManifest returns the agent's in-memory manifest. Unfortunately this mustbe returns as a []byte to avoid an import cycle.

func (*AgentConn)DialContext

func (c *AgentConn) DialContext(ctxcontext.Context, networkstring, addrstring) (net.Conn,error)

DialContext dials the address provided in the workspace agent.The network must be "tcp" or "udp".

func (*AgentConn)GetPeerDiagnostics

func (c *AgentConn) GetPeerDiagnostics()tailnet.PeerDiagnostics

func (*AgentConn)ListContainersadded inv2.20.0

ListContainers returns a response from the agent's containers endpoint

func (*AgentConn)ListeningPorts

ListeningPorts lists the ports that are currently in use by the workspace.

func (*AgentConn)Netcheckadded inv2.15.0

Netcheck returns a network check report from the workspace agent.

func (*AgentConn)Ping

Ping pings the agent and returns the round-trip time.The bool returns true if the ping was made P2P.

func (*AgentConn)PrometheusMetrics

func (c *AgentConn) PrometheusMetrics(ctxcontext.Context) ([]byte,error)

PrometheusMetrics returns a response from the agent's prometheus metrics endpoint

func (*AgentConn)ReconnectingPTY

func (c *AgentConn) ReconnectingPTY(ctxcontext.Context, iduuid.UUID, height, widthuint16, commandstring, initOpts ...AgentReconnectingPTYInitOption) (net.Conn,error)

ReconnectingPTY spawns a new reconnecting terminal session.`ReconnectingPTYRequest` should be JSON marshaled and written to the returned net.Conn.Raw terminal output will be read from the returned net.Conn.

func (*AgentConn)RecreateDevcontaineradded inv2.23.0

func (c *AgentConn) RecreateDevcontainer(ctxcontext.Context, containerIDOrNamestring) (codersdk.Response,error)

RecreateDevcontainer recreates a devcontainer with the given container.This is a blocking call and will wait for the container to be recreated.

func (*AgentConn)SSH

SSH pipes the SSH protocol over the returned net.Conn.This connects to the built-in SSH server in the workspace agent.

func (*AgentConn)SSHClient

func (c *AgentConn) SSHClient(ctxcontext.Context) (*ssh.Client,error)

SSHClient calls SSH to create a client

func (*AgentConn)SSHClientOnPortadded inv2.20.0

func (c *AgentConn) SSHClientOnPort(ctxcontext.Context, portuint16) (*ssh.Client,error)

SSHClientOnPort calls SSH to create a client on a specific port

func (*AgentConn)SSHOnPortadded inv2.20.0

func (c *AgentConn) SSHOnPort(ctxcontext.Context, portuint16) (*gonet.TCPConn,error)

SSHOnPort pipes the SSH protocol over the returned net.Conn.This connects to the built-in SSH server in the workspace agent on the specified port.

func (*AgentConn)Speedtest

func (c *AgentConn) Speedtest(ctxcontext.Context, directionspeedtest.Direction, durationtime.Duration) ([]speedtest.Result,error)

Speedtest runs a speedtest against the workspace agent.

typeAgentConnOptions

type AgentConnOptions struct {AgentIDuuid.UUIDCloseFunc func()error}

@typescript-ignore AgentConnOptions

typeAgentConnectionInfo

type AgentConnectionInfo struct {DERPMap                  *tailcfg.DERPMap `json:"derp_map"`DERPForceWebSocketsbool             `json:"derp_force_websockets"`DisableDirectConnectionsbool             `json:"disable_direct_connections"`HostnameSuffixstring           `json:"hostname_suffix,omitempty"`}

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

typeAgentReconnectingPTYInit

type AgentReconnectingPTYInit struct {IDuuid.UUIDHeightuint16Widthuint16Commandstring// Container, if set, will attempt to exec into a running container visible to the agent.// This should be a unique container ID (implementation-dependent).Containerstring// 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.ContainerUserstringBackendTypestring}

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

typeAgentReconnectingPTYInitOptionadded inv2.21.0

type AgentReconnectingPTYInitOption func(*AgentReconnectingPTYInit)

AgentReconnectingPTYInitOption is a functional option for AgentReconnectingPTYInit.

funcAgentReconnectingPTYInitWithContaineradded inv2.21.0

func AgentReconnectingPTYInitWithContainer(container, containerUserstring)AgentReconnectingPTYInitOption

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

typeClient

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

funcNew

func New(c *codersdk.Client) *Client

func (*Client)AgentConnectionInfo

func (c *Client) AgentConnectionInfo(ctxcontext.Context, agentIDuuid.UUID) (AgentConnectionInfo,error)

func (*Client)AgentConnectionInfoGeneric

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

func (*Client)AgentReconnectingPTY

func (c *Client) AgentReconnectingPTY(ctxcontext.Context, optsWorkspaceAgentReconnectingPTYOpts) (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(dialCtxcontext.Context, agentIDuuid.UUID, options *DialAgentOptions) (agentConn *AgentConn, errerror)

func (*Client)IsCoderConnectRunningadded inv2.22.0

func (c *Client) IsCoderConnectRunning(ctxcontext.Context, oCoderConnectQueryOptions) (bool,error)

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

typeCoderConnectQueryOptionsadded inv2.22.0

type CoderConnectQueryOptions struct {HostnameSuffixstring}

typeDialAgentOptions

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

@typescript-ignore DialAgentOptions

typeReconnectingPTYRequest

type ReconnectingPTYRequest struct {Datastring `json:"data,omitempty"`Heightuint16 `json:"height,omitempty"`Widthuint16 `json:"width,omitempty"`}

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

typeResolveradded inv2.22.0

type Resolver interface {LookupIP(ctxcontext.Context, network, hoststring) ([]net.IP,error)}

typeWebsocketDialeradded inv2.18.0

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

funcNewWebsocketDialeradded inv2.18.0

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

func (*WebsocketDialer)Connectedadded inv2.18.0

func (w *WebsocketDialer) Connected() <-chanerror

func (*WebsocketDialer)Dialadded inv2.18.0

typeWebsocketDialerOptionadded inv2.18.0

type WebsocketDialerOption func(*WebsocketDialer)

funcWithWorkspaceUpdatesadded inv2.18.0

func WithWorkspaceUpdates(req *proto.WorkspaceUpdatesRequest)WebsocketDialerOption

typeWorkspaceAgentReconnectingPTYOpts

type WorkspaceAgentReconnectingPTYOpts struct {AgentIDuuid.UUIDReconnectuuid.UUIDWidthuint16Heightuint16Commandstring// 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.SignedTokenstring// 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".ContainerstringContainerUserstring// 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".BackendTypestring}

@typescript-ignore:WorkspaceAgentReconnectingPTYOpts

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp