Documentation
¶
Index ¶
- Constants
- func NormalizeRawEndpoint(path string) (string, error)
- func ValidateRawRequestHeaders(method string, header http.Header) error
- type AlpaconClient
- func (ac *AlpaconClient) AccessToken() string
- func (ac *AlpaconClient) IsBearerAuth() bool
- func (ac *AlpaconClient) IsUsingHTTPS() (bool, error)
- func (ac *AlpaconClient) LoadCurrentUser() error
- func (ac *AlpaconClient) RefreshToken() error
- func (ac *AlpaconClient) SendDeleteRequest(url string) ([]byte, error)
- func (ac *AlpaconClient) SendDeleteRequestWithBody(url string, body any) ([]byte, error)
- func (ac *AlpaconClient) SendDeleteRequestWithContext(ctx context.Context, url string) ([]byte, error)
- func (ac *AlpaconClient) SendGetRequest(url string) ([]byte, error)
- func (ac *AlpaconClient) SendGetRequestForDownload(url string) (*http.Response, error)
- func (ac *AlpaconClient) SendGetRequestToURL(absoluteURL string) ([]byte, error)
- func (ac *AlpaconClient) SendMultipartStreamRequest(url, contentType string, body io.Reader, contentLength int64) ([]byte, error)
- func (ac *AlpaconClient) SendPatchRequest(url string, body any) ([]byte, error)
- func (ac *AlpaconClient) SendPostRequest(url string, body any) ([]byte, error)
- func (ac *AlpaconClient) SendPostRequestWithStatus(url string, body any) ([]byte, int, error)
- func (ac *AlpaconClient) SendRawRequest(method, path string, body io.Reader, header http.Header) (*RawResponse, error)
- func (ac *AlpaconClient) SetAccessToken(token string)
- func (ac *AlpaconClient) SetWebsocketHeader() http.Header
- func (ac *AlpaconClient) SetWebsocketHeaderWithCapabilities(capabilities ...string) http.Header
- type CurrentUserResponse
- type RawResponse
Constants ¶
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" )
Variables ¶
This section is empty.
Functions ¶
func NormalizeRawEndpoint ¶ added in v1.14.2
Types ¶
type AlpaconClient ¶
type AlpaconClient struct {
HTTPClient *http.Client
BaseURL string
WorkspaceName string // the workspace BaseURL points at; config can be rewritten mid-flight
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 (*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) LoadCurrentUser ¶ added in v1.4.8
func (ac *AlpaconClient) LoadCurrentUser() error
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) 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 the request runs is not: it waits out the grant as any other request does.
func (*AlpaconClient) SendGetRequest ¶
func (ac *AlpaconClient) SendGetRequest(url string) ([]byte, error)
Get Request to Alpacon Server
func (*AlpaconClient) SendGetRequestForDownload ¶
func (ac *AlpaconClient) SendGetRequestForDownload(url string) (*http.Response, error)
SendGetRequestForDownload returns the raw *http.Response so callers can stream the body. Auth errors (401/403) are handled here; all other status codes are left to the caller.
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) SendMultipartStreamRequest ¶ added in v1.5.0
func (*AlpaconClient) SendPatchRequest ¶
func (ac *AlpaconClient) SendPatchRequest(url string, body any) ([]byte, error)
func (*AlpaconClient) SendPostRequest ¶
func (ac *AlpaconClient) SendPostRequest(url string, body any) ([]byte, error)
POST Request to Alpacon Server
func (*AlpaconClient) SendPostRequestWithStatus ¶ added in v1.14.0
SendPostRequestWithStatus is SendPostRequest plus the response's HTTP status code on success. Use it only where the status code itself carries meaning the body cannot be trusted to (e.g. work-session extend's 200-vs-202 contract, where the body may still carry a field from before the status existed to disambiguate it)—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)
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. gorilla sends no User-Agent of its own, so a client assembled without one—every client outside NewAlpaconAPIClient—would dial anonymously; fall back to the same string the HTTP requests carry. The handshake declares a detected AI agent the same way every HTTP request does.
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.