Documentation
¶
Overview ¶
Package notcodersdk contains manually-vendored code from github.com/coder/coder/v2/codersdk.
This code is currently required for sending workspace build logs to coder. It was manually vendored to avoid dependency issues.
If the direct integration is moved outside of envbuilder, this package can safely be removed. See the below issues for context: - https://github.com/coder/envbuilder/issues/178 - https://github.com/coder/coder/issues/11342 - https://github.com/coder/envbuilder/issues/193
Index ¶
- Constants
- Variables
- func ExpectJSONMime(res *http.Response) error
- func LogsSender(sourceID uuid.UUID, patchLogs func(ctx context.Context, req PatchLogs) error, ...) (sendLog func(ctx context.Context, log ...Log) error, ...)deprecated
- func ReadBodyAsError(res *http.Response) error
- type AgentSubsystem
- type Client
- type Error
- type Log
- type LogLevel
- type PatchLogs
- type RequestOption
- type Response
- type ValidationError
Constants ¶
const (
SessionTokenHeader = "Coder-Session-Token"
)
Variables ¶
var ExternalLogSourceID = uuid.MustParse("3b579bf4-1ed8-4b99-87a8-e9a1e3410410")
ExternalLogSourceID is the statically-defined ID of a log-source that appears as "External" in the dashboard.
This is to support legacy API-consumers that do not create their own log-source. This should be removed in the future.
Functions ¶
func ExpectJSONMime ¶
ExpectJSONMime is a helper function that will assert the content type of the response is application/json.
func LogsSender
deprecated
func LogsSender(sourceID uuid.UUID, patchLogs func(ctx context.Context, req PatchLogs) error, logger slog.Logger, opts ...func(*logsSenderOptions)) (sendLog func(ctx context.Context, log ...Log) error, flushAndClose func(context.Context) error)
LogsSender will send agent startup logs to the server. Calls to sendLog are non-blocking and will return an error if flushAndClose has been called. Calling sendLog concurrently is not supported. If the context passed to flushAndClose is canceled, any remaining logs will be discarded.
Deprecated: Use NewLogSender instead, based on the v2 Agent API.
func ReadBodyAsError ¶
ReadBodyAsError reads the response as a codersdk.Response, and wraps it in a codersdk.Error type for easy marshaling.
This will always return an error, so only call it if the response failed your expectations. Usually via status code checking. nolint:staticcheck
Types ¶
type AgentSubsystem ¶
type AgentSubsystem string
const (
AgentSubsystemEnvbuilder AgentSubsystem = "envbuilder"
)
type Client ¶
type Client struct { HTTPClient *http.Client URL *url.URL // SessionTokenHeader is an optional custom header to use for setting tokens. By // default 'Coder-Session-Token' is used. SessionTokenHeader string // PlainLogger may be set to log HTTP traffic in a human-readable form. // It uses the LogBodies option. PlainLogger io.Writer // contains filtered or unexported fields }
Client wraps `notcodersdk.Client` with specific functions scoped to a workspace agent.
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...RequestOption) (*http.Response, error)
Request performs a HTTP request with the body provided. The caller is responsible for closing the response body.
func (*Client) SessionToken ¶
SessionToken returns the currently set token for the client.
func (*Client) SetSessionToken ¶
SetSessionToken returns the currently set token for the client.
type Error ¶
Error represents an unaccepted or invalid request to the API. @typescript-ignore Error
func (*Error) StatusCode ¶
type RequestOption ¶
RequestOption is a function that can be used to modify an http.Request.
type Response ¶
type Response struct { // Message is an actionable message that depicts actions the request took. // These messages should be fully formed sentences with proper punctuation. // Examples: // - "A user has been created." // - "Failed to create a user." Message string `json:"message"` // Detail is a debug message that provides further insight into why the // action failed. This information can be technical and a regular golang // err.Error() text. // - "database: too many open connections" // - "stat: too many open files" Detail string `json:"detail,omitempty"` // Validations are form field-specific friendly error messages. They will be // shown on a form field in the UI. These can also be used to add additional // context if there is a set of errors in the primary 'Message'. Validations []ValidationError `json:"validations,omitempty"` }
Response represents a generic HTTP response.
type ValidationError ¶
type ValidationError struct { Field string `json:"field" validate:"required"` Detail string `json:"detail" validate:"required"` }
ValidationError represents a scoped error to a user input.
func (ValidationError) Error ¶
func (e ValidationError) Error() string