client

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// ClientCapabilitiesHeader carries the optional behaviors a WebSocket
	// connection supports, as a comma-separated list.
	ClientCapabilitiesHeader = "X-Alpacon-Client-Capabilities"

	// CapabilityWebsocketReconnect says the client re-dials a new channel and
	// resumes the session when the connection drops, so closing the connection
	// for a transient reason does not take the session with it.
	CapabilityWebsocketReconnect = "websocket-reconnect"

	// CapabilityIdleWarning says the client handles idle warnings without printing raw frames.
	CapabilityIdleWarning = "idle-warning"

	// CapabilityRefusalFrame says the client reads a refusal sent as a text frame
	// apart from terminal output or tunnel data, so the server may send one.
	CapabilityRefusalFrame = "refusal-frame"
)
View Source
const (
	// SignerURLEnvVar overrides the signer's base URL; nothing advertises where
	// a self-hosted signer is.
	SignerURLEnvVar = "ALPACON_AI_URL"
	// DefaultSignerURL is the signer serving Alpacon Cloud workspaces.
	DefaultSignerURL = "https://alpacon.ai"

	// SignerAudienceEnvVar overrides the Auth0 audience a signer token is
	// requested for, for a self-hosted signer behind its own API identifier.
	SignerAudienceEnvVar = "ALPACON_AI_AUDIENCE"
	// DefaultSignerAudience is the Alpacon Cloud signer's Auth0 audience, matched
	// character for character, trailing slash included.
	DefaultSignerAudience = "https://alpacon.ai/"
)

Variables

This section is empty.

Functions

func CheckSignerURL added in v1.18.0

func CheckSignerURL(raw string) error

CheckSignerURL refuses a signer URL the token must not be sent to: anything but https, except plain http to a loopback host.

func NormalizeRawEndpoint added in v1.14.2

func NormalizeRawEndpoint(path string) (string, error)

func SignerAudience added in v1.18.0

func SignerAudience() string

SignerAudience returns the Auth0 audience a signer token is requested for, verbatim.

func SignerURL added in v1.18.0

func SignerURL() string

SignerURL returns the signer's base URL, without a trailing slash: the path owns its leading one.

func ValidateRawRequestHeaders added in v1.14.2

func ValidateRawRequestHeaders(method string, header http.Header) error

ValidateRawRequestHeaders checks special headers that net/http does not send from Request.Header.

Types

type AlpaconClient

type AlpaconClient struct {
	HTTPClient    *http.Client
	BaseURL       string
	WorkspaceName string // the workspace BaseURL points at; config can be rewritten mid-flight
	BaseDomain    string // loaded with BaseURL, so console links use the same workspace identity
	Token         string

	Privileges string
	Username   string
	UserAgent  string
	// Insecure records that this workspace was configured to skip TLS
	// verification, so a credential written for another client (a kubeconfig)
	// can say the same instead of failing where this client succeeds.
	Insecure bool
	// contains filtered or unexported fields
}

func NewAlpaconAPIClient

func NewAlpaconAPIClient() (*AlpaconClient, error)

func NewSignerClient added in v1.18.0

func NewSignerClient(accessToken string) *AlpaconClient

NewSignerClient builds a signer client carrying only the signer token. It never renews on a 401 and always verifies the certificate, whatever the workspace chose.

func (*AlpaconClient) AccessToken

func (ac *AlpaconClient) AccessToken() string

AccessToken returns the token a request should carry. It locks because sendRequest can swap the token mid-flight.

func (*AlpaconClient) IsBearerAuth added in v1.12.0

func (ac *AlpaconClient) IsBearerAuth() bool

IsBearerAuth reports whether requests carry an Auth0 bearer token rather than a legacy API key. Some endpoints refuse the API key outright, and their refusal arrives with no error code, so a caller rewriting it has to know which credential it sent.

func (*AlpaconClient) IsUsingHTTPS

func (ac *AlpaconClient) IsUsingHTTPS() (bool, error)

func (*AlpaconClient) IsWorkspaceResponse added in v1.21.0

func (ac *AlpaconClient) IsWorkspaceResponse(resp *http.Response) bool

IsWorkspaceResponse reports whether resp came from this client's workspace origin.

func (*AlpaconClient) LoadCurrentUser added in v1.4.8

func (ac *AlpaconClient) LoadCurrentUser() error

func (*AlpaconClient) LocalSignalOrigin added in v1.20.0

func (ac *AlpaconClient) LocalSignalOrigin() localsignal.ConsoleOrigin

func (*AlpaconClient) RefreshToken added in v1.3.0

func (ac *AlpaconClient) RefreshToken() error

RefreshToken refreshes the access token using the stored refresh token. Uses ac.BaseURL (not config's WorkspaceURL) to stay consistent with the client's target.

func (*AlpaconClient) SaveActiveWorkSession added in v1.20.2

func (ac *AlpaconClient) SaveActiveWorkSession(uuid string) error

SaveActiveWorkSession makes uuid the active work session of this client's workspace, unless another login has replaced the one the client was built with (config.ErrLoginChanged).

func (*AlpaconClient) SendDeleteRequest

func (ac *AlpaconClient) SendDeleteRequest(url string) ([]byte, error)

func (*AlpaconClient) SendDeleteRequestWithBody added in v1.12.0

func (ac *AlpaconClient) SendDeleteRequestWithBody(url string, body any) ([]byte, error)

SendDeleteRequestWithBody sends a DELETE carrying a JSON body: an endpoint wanting a justification takes it there rather than in a query parameter, so it stays out of access logs, proxy logs and shell history. createRequest sets the content type only for methods that always carry a body, so this sets it here.

A DELETE entity-body is legal but unusual: an intermediary that strips one still leaves a 204 and an audit row with an empty reason, undetectable from here.

func (*AlpaconClient) SendDeleteRequestWithContext added in v1.16.0

func (ac *AlpaconClient) SendDeleteRequestWithContext(ctx context.Context, url string) ([]byte, error)

SendDeleteRequestWithContext is SendDeleteRequest bounded by ctx, a token renewal it runs included: a renewal that outlasts ctx leaves the request's 401 as its result.

func (*AlpaconClient) SendGetRequest

func (ac *AlpaconClient) SendGetRequest(url string) ([]byte, error)

SendGetRequest sends a GET request to the workspace.

func (*AlpaconClient) SendGetRequestToURL added in v1.4.2

func (ac *AlpaconClient) SendGetRequestToURL(absoluteURL string) ([]byte, error)

SendGetRequestToURL sends a GET request to an absolute URL (e.g., an external service) using the client's authentication headers.

func (*AlpaconClient) SendGetRequestWithContext added in v1.18.0

func (ac *AlpaconClient) SendGetRequestWithContext(ctx context.Context, url string) ([]byte, error)

SendGetRequestWithContext is SendGetRequest bounded by ctx, a token renewal it runs included: a renewal that outlasts ctx leaves the request's 401 as its result.

func (*AlpaconClient) SendPatchRequest

func (ac *AlpaconClient) SendPatchRequest(url string, body any) ([]byte, error)

func (*AlpaconClient) SendPatchRequestWithStatus added in v1.20.0

func (ac *AlpaconClient) SendPatchRequestWithStatus(url string, body any) ([]byte, int, error)

SendPatchRequestWithStatus exposes the difference between an applied and a queued change.

func (*AlpaconClient) SendPostRequest

func (ac *AlpaconClient) SendPostRequest(url string, body any) ([]byte, error)

SendPostRequest sends body as JSON in a POST request to the workspace.

func (*AlpaconClient) SendPostRequestWithContext added in v1.20.0

func (ac *AlpaconClient) SendPostRequestWithContext(ctx context.Context, url string, body any) ([]byte, error)

SendPostRequestWithContext is SendPostRequest bounded by ctx, as SendGetRequestWithContext is.

func (*AlpaconClient) SendPostRequestWithStatus added in v1.14.0

func (ac *AlpaconClient) SendPostRequestWithStatus(url string, body any) ([]byte, int, error)

SendPostRequestWithStatus is SendPostRequest plus the response's HTTP status code. Use it only where the status carries meaning the body cannot be trusted to (e.g. work-session extend's 200 vs 202, whose body may carry a field from before the status existed); every other caller wants SendPostRequest.

func (*AlpaconClient) SendRawRequest added in v1.14.2

func (ac *AlpaconClient) SendRawRequest(method, path string, body io.Reader, header http.Header) (*RawResponse, error)

SendRawRequest sends a workspace request. A 429 with a body read error returns the received status, headers, and available bytes alongside the error.

func (*AlpaconClient) SetAccessToken added in v1.13.1

func (ac *AlpaconClient) SetAccessToken(token string)

SetAccessToken installs the token every later request carries. It is exported so tests in other packages can build an authenticated client without writing the field directly and skipping tokenMu.

func (*AlpaconClient) SetWebsocketHeader

func (ac *AlpaconClient) SetWebsocketHeader() http.Header

SetWebsocketHeader builds the header for a WebSocket dial, declaring a detected AI agent as every HTTP request does. gorilla sends no User-Agent of its own, so a client whose UserAgent is empty falls back to the HTTP requests' string.

func (*AlpaconClient) SetWebsocketHeaderWithCapabilities added in v1.13.0

func (ac *AlpaconClient) SetWebsocketHeaderWithCapabilities(capabilities ...string) http.Header

SetWebsocketHeaderWithCapabilities is SetWebsocketHeader plus the capabilities this connection supports, so the server can tell a client that re-dials a dropped connection from one that ends the session on it. Only a caller that actually implements a capability may advertise it; a server that does not read the header is unaffected either way.

type CurrentUserResponse added in v1.11.2

type CurrentUserResponse struct {
	Username    string `json:"username"`
	IsStaff     bool   `json:"is_staff"`
	IsSuperuser bool   `json:"is_superuser"`
}

type RawResponse added in v1.14.2

type RawResponse struct {
	Status     string
	StatusCode int
	Proto      string
	Header     http.Header
	Body       []byte
}

Jump to

Keyboard shortcuts

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