wsproxysdk

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SDKClient *codersdk.Client
	// contains filtered or unexported fields
}

Client is a HTTP client for a subset of Coder API routes that external proxies need.

func New

func New(serverURL *url.URL) *Client

New creates a external proxy client for the provided primary coder server URL.

func (*Client) DeregisterWorkspaceProxy

func (c *Client) DeregisterWorkspaceProxy(ctx context.Context, req DeregisterWorkspaceProxyRequest) error

func (*Client) DialCoordinator

func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, error)

func (*Client) DialWorkspaceAgent

func (c *Client) DialWorkspaceAgent(ctx context.Context, agentID uuid.UUID, options *workspacesdk.DialAgentOptions) (agentConn *workspacesdk.AgentConn, err error)

DialWorkspaceAgent calls the underlying codersdk.Client's DialWorkspaceAgent method.

func (*Client) IssueSignedAppToken

IssueSignedAppToken issues a new signed app token for the provided app request. The error page will be returned as JSON. For use in external proxies, use IssueSignedAppTokenHTML instead.

func (*Client) IssueSignedAppTokenHTML

IssueSignedAppTokenHTML issues a new signed app token for the provided app request. The error page will be returned as HTML in most cases, and will be written directly to the provided http.ResponseWriter.

func (*Client) RegisterWorkspaceProxyLoop

RegisterWorkspaceProxyLoop will register the workspace proxy and then start a goroutine to keep registering periodically in the background.

The first response is returned immediately, and subsequent responses will be notified to the given CallbackFn. When the loop is Close()d it will stop immediately and an error will be returned to the FailureFn.

When a fatal error is encountered (or the proxy is closed), the proxy will be deregistered (with the same ReplicaID and AttemptTimeout) before calling the FailureFn.

func (*Client) ReportAppStats

func (c *Client) ReportAppStats(ctx context.Context, req ReportAppStatsRequest) error

ReportAppStats reports the given app stats to the primary coder server.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...codersdk.RequestOption) (*http.Response, error)

Request wraps the underlying codersdk.Client's Request method.

func (*Client) RequestIgnoreRedirects

func (c *Client) RequestIgnoreRedirects(ctx context.Context, method, path string, body interface{}, opts ...codersdk.RequestOption) (*http.Response, error)

RequestIgnoreRedirects wraps the underlying codersdk.Client's Request method on the client that ignores redirects.

func (*Client) SessionToken

func (c *Client) SessionToken() string

SessionToken returns the currently set token for the client.

func (*Client) SetSessionToken

func (c *Client) SetSessionToken(token string) error

SetSessionToken sets the session token for the client. An error is returned if the session token is not in the correct format for external proxies.

type CoordinateMessage

type CoordinateMessage struct {
	Type    CoordinateMessageType `json:"type"`
	AgentID uuid.UUID             `json:"agent_id"`
	Node    *agpl.Node            `json:"node"`
}

type CoordinateMessageType

type CoordinateMessageType int
const (
	CoordinateMessageTypeSubscribe CoordinateMessageType = 1 + iota
	CoordinateMessageTypeUnsubscribe
	CoordinateMessageTypeNodeUpdate
)

type CoordinateNodes

type CoordinateNodes struct {
	Nodes []*agpl.Node
}

type DeregisterWorkspaceProxyRequest

type DeregisterWorkspaceProxyRequest struct {
	// ReplicaID is a unique identifier for the replica of the proxy that is
	// deregistering. It should be generated by the client on startup and
	// should've already been passed to the register endpoint.
	ReplicaID uuid.UUID `json:"replica_id"`
}

type IssueSignedAppTokenResponse

type IssueSignedAppTokenResponse struct {
	// SignedTokenStr should be set as a cookie on the response.
	SignedTokenStr string `json:"signed_token_str"`
}

type RegisterWorkspaceProxyLoop added in v2.8.5

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

func (*RegisterWorkspaceProxyLoop) Close added in v2.8.5

func (l *RegisterWorkspaceProxyLoop) Close()

func (*RegisterWorkspaceProxyLoop) RegisterNow added in v2.8.5

RegisterNow asks the registration loop to register immediately. A timeout of 2x the attempt timeout is used to wait for the response.

func (*RegisterWorkspaceProxyLoop) Start added in v2.8.5

Start starts the proxy registration loop. The provided context is only used for the initial registration. Use Close() to stop.

type RegisterWorkspaceProxyLoopOpts

type RegisterWorkspaceProxyLoopOpts struct {
	Logger  slog.Logger
	Request RegisterWorkspaceProxyRequest

	// Interval between registration attempts. Defaults to 30 seconds. Note that
	// the initial registration is not delayed by this interval.
	Interval time.Duration
	// MaxFailureCount is the maximum amount of attempts that the loop will
	// retry registration before giving up. Defaults to 10 (for ~5 minutes).
	MaxFailureCount int
	// AttemptTimeout is the maximum amount of time that the loop will wait for
	// a response from the server before considering the attempt a failure.
	// Defaults to 10 seconds.
	AttemptTimeout time.Duration

	// MutateFn is called before each request to mutate the request struct. This
	// can be used to update fields like ReplicaError.
	MutateFn func(req *RegisterWorkspaceProxyRequest)
	// CallbackFn is called with the response from the server after each
	// successful registration, except the first. The callback function is
	// called in a blocking manner, so it should avoid blocking for too long. If
	// the callback returns an error, the loop will stop immediately and the
	// error will be returned to the FailureFn.
	CallbackFn func(res RegisterWorkspaceProxyResponse) error
	// FailureFn is called with the last error returned from the server if the
	// context is canceled, registration fails for more than MaxFailureCount,
	// or if any permanent values in the response change.
	FailureFn func(err error)
}

type RegisterWorkspaceProxyRequest

type RegisterWorkspaceProxyRequest struct {
	// AccessURL that hits the workspace proxy api.
	AccessURL string `json:"access_url"`
	// WildcardHostname that the workspace proxy api is serving for subdomain apps.
	WildcardHostname string `json:"wildcard_hostname"`
	// DerpEnabled indicates whether the proxy should be included in the DERP
	// map or not.
	DerpEnabled bool `json:"derp_enabled"`
	// DerpOnly indicates whether the proxy should only be included in the DERP
	// map and should not be used for serving apps.
	DerpOnly bool `json:"derp_only"`

	// ReplicaID is a unique identifier for the replica of the proxy that is
	// registering. It should be generated by the client on startup and
	// persisted (in memory only) until the process is restarted.
	ReplicaID uuid.UUID `json:"replica_id"`
	// ReplicaHostname is the OS hostname of the machine that the proxy is running
	// on.  This is only used for tracking purposes in the replicas table.
	ReplicaHostname string `json:"hostname"`
	// ReplicaError is the error that the replica encountered when trying to
	// dial it's peers. This is stored in the replicas table for debugging
	// purposes but does not affect the proxy's ability to register.
	//
	// This value is only stored on subsequent requests to the register
	// endpoint, not the first request.
	ReplicaError string `json:"replica_error"`
	// ReplicaRelayAddress is the DERP address of the replica that other
	// replicas may use to connect internally for DERP meshing.
	ReplicaRelayAddress string `json:"replica_relay_address"`

	// Version is the Coder version of the proxy.
	Version string `json:"version"`
}

type RegisterWorkspaceProxyResponse

type RegisterWorkspaceProxyResponse struct {
	AppSecurityKey      string           `json:"app_security_key"`
	DERPMeshKey         string           `json:"derp_mesh_key"`
	DERPRegionID        int32            `json:"derp_region_id"`
	DERPMap             *tailcfg.DERPMap `json:"derp_map"`
	DERPForceWebSockets bool             `json:"derp_force_websockets"`
	// SiblingReplicas is a list of all other replicas of the proxy that have
	// not timed out.
	SiblingReplicas []codersdk.Replica `json:"sibling_replicas"`
}

type ReportAppStatsRequest

type ReportAppStatsRequest struct {
	Stats []workspaceapps.StatsReport `json:"stats"`
}

Jump to

Keyboard shortcuts

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