Documentation
¶
Overview ¶
Package desk is the public wire contract between a WB daemon and Sneat Dev Desk (spec/features/desk-connect). It holds only request and response types, their validation, and strict decoding; it imports nothing from internal/ so the private Desk server can depend on it.
Index ¶
- Constants
- Variables
- func CheckLevel(envelope json.RawMessage, level Level) error
- func Decode(reader io.Reader, limit int64, target Validator) error
- func WithheldAtRepositories() []string
- type ConnectStartRequest
- type ConnectStartResponse
- type ConnectTokenRequest
- type ConnectTokenResponse
- type ErrorCode
- type GrantError
- type HeartbeatRequest
- type Level
- type MachineRef
- type MachineSelf
- type SchemaUnsupported
- type Scope
- type Share
- type ShareLevel
- type ShareState
- type SnapshotReceipt
- type SnapshotRequest
- type Validator
Constants ¶
const ( PathConnectStart = "/v0/desk/connect/start" PathConnectToken = "/v0/desk/connect/token" PathMachineSelf = "/v0/desk/machines/self" PathSnapshot = PathMachineSelf + "/snapshot" PathHeartbeat = PathMachineSelf + "/heartbeat" )
Routes, relative to the Desk origin.
const ( MaxGrantSeconds = 600 MaxMachineNameLength = 128 MaxVersionLength = 64 MaxPlatformLength = 32 MaxSpaceIDLength = 128 MaxCredentialLength = 1024 MaxDeviceCodeLength = 512 MaxURILength = 2048 MaxCompressedSnapshotBytes = 1 << 20 MaxDecodedSnapshotBytes = 8 << 20 // MaxResponseBytes caps every non-snapshot response body a client reads. MaxResponseBytes = 64 << 10 )
Bounds of the contract.
const DefaultURL = "https://desk.sneat.dev"
DefaultURL is the hosted Desk origin.
const SchemaVersion = 1
SchemaVersion is the Desk payload schema this build sends.
Variables ¶
var ErrInvalid = errors.New("invalid desk payload")
ErrInvalid is wrapped by every validation failure.
Functions ¶
func CheckLevel ¶
func CheckLevel(envelope json.RawMessage, level Level) error
CheckLevel reports whether envelope carries anything above level. At `full` every envelope passes; at `repositories` one that carries a withheld path with a value, or a value of the wrong JSON type where a withheld path leads, is refused. The error names the path, never the value.
func Decode ¶
Decode reads at most limit bytes of one JSON value into target, refusing unknown fields and trailing data, then validates it.
func WithheldAtRepositories ¶
func WithheldAtRepositories() []string
WithheldAtRepositories returns the envelope paths the `repositories` level withholds, in a stable order.
Types ¶
type ConnectStartRequest ¶
type ConnectStartRequest struct {
SchemaVersion int `json:"schema_version"`
Machine MachineRef `json:"machine"`
WBVersion string `json:"wb_version"`
OS string `json:"os"`
Arch string `json:"arch"`
Detail Level `json:"detail"`
SpaceHint string `json:"space_hint,omitempty"`
}
ConnectStartRequest opens a device grant.
func (ConnectStartRequest) Validate ¶
func (request ConnectStartRequest) Validate() error
Validate checks the request.
type ConnectStartResponse ¶
type ConnectStartResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationURIComplete string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
ConnectStartResponse is the grant Desk opened.
func (ConnectStartResponse) Validate ¶
func (response ConnectStartResponse) Validate() error
Validate checks the response.
type ConnectTokenRequest ¶
type ConnectTokenRequest struct {
DeviceCode string `json:"device_code"`
}
ConnectTokenRequest polls a device grant.
func (ConnectTokenRequest) Validate ¶
func (request ConnectTokenRequest) Validate() error
Validate checks the request.
type ConnectTokenResponse ¶
type ConnectTokenResponse struct {
Error GrantError `json:"error,omitempty"`
Credential string `json:"credential,omitempty"`
Machine MachineRef `json:"machine,omitzero"`
PersonalSpaceID string `json:"personal_space_id,omitempty"`
Scopes []Scope `json:"scopes,omitempty"`
}
ConnectTokenResponse is either a grant error or an issued credential.
func (ConnectTokenResponse) Validate ¶
func (response ConnectTokenResponse) Validate() error
Validate checks the response: a pending or failed grant carries only its error; an issued one carries the credential, the machine, the personal space, and exactly the desk-connect scopes.
type ErrorCode ¶
type ErrorCode string
ErrorCode is a typed publish or heartbeat failure recorded by the daemon. Desk's response text is never recorded.
const ( ErrorUnreachable ErrorCode = "unreachable" ErrorTimeout ErrorCode = "timeout" ErrorRevoked ErrorCode = "revoked" ErrorRejectedPayload ErrorCode = "rejected_payload" ErrorSchemaUnsupported ErrorCode = "schema_unsupported" ErrorTooLarge ErrorCode = "too_large" ErrorRateLimited ErrorCode = "rate_limited" )
type GrantError ¶
type GrantError string
GrantError is a device-authorization polling outcome (RFC 8628 §3.5).
const ( GrantPending GrantError = "authorization_pending" GrantSlowDown GrantError = "slow_down" GrantAccessDenied GrantError = "access_denied" GrantExpired GrantError = "expired_token" )
func (GrantError) Valid ¶
func (code GrantError) Valid() bool
Valid reports whether code is a known grant error.
type HeartbeatRequest ¶
type HeartbeatRequest struct {
SchemaVersion int `json:"schema_version"`
ObservedAt time.Time `json:"observed_at"`
WBVersion string `json:"wb_version"`
LastSnapshotHash string `json:"last_snapshot_hash,omitempty"`
}
HeartbeatRequest is the small periodic liveness signal.
func (HeartbeatRequest) Validate ¶
func (request HeartbeatRequest) Validate() error
Validate checks the request.
type MachineRef ¶
MachineRef names a machine.
func (MachineRef) Validate ¶
func (ref MachineRef) Validate() error
Validate checks the machine reference.
type MachineSelf ¶
type MachineSelf struct {
Machine MachineRef `json:"machine"`
PersonalSpaceID string `json:"personal_space_id"`
Detail Level `json:"detail"`
LastSnapshotHash string `json:"last_snapshot_hash,omitempty"`
LastSnapshotAt time.Time `json:"last_snapshot_at,omitzero"`
LastHeartbeatAt time.Time `json:"last_heartbeat_at,omitzero"`
}
MachineSelf is Desk's record of the calling machine.
func (MachineSelf) Validate ¶
func (record MachineSelf) Validate() error
Validate checks the record.
type SchemaUnsupported ¶
type SchemaUnsupported struct {
MinimumSchemaVersion int `json:"minimum_schema_version"`
}
SchemaUnsupported is the body of a 426 answer.
func (SchemaUnsupported) Validate ¶
func (body SchemaUnsupported) Validate() error
Validate checks the body.
type ShareLevel ¶
type ShareLevel string
ShareLevel is what a space shows of a shared machine (desk-spaces).
const ( )
func (ShareLevel) Valid ¶
func (level ShareLevel) Valid() bool
Valid reports whether level is a share level.
type ShareState ¶
type ShareState string
ShareState is the lifecycle state of a share.
const ( )
func (ShareState) Valid ¶
func (state ShareState) Valid() bool
Valid reports whether state is a share state a grant can return.
type SnapshotReceipt ¶
SnapshotReceipt acknowledges an accepted snapshot.
func (SnapshotReceipt) Validate ¶
func (receipt SnapshotReceipt) Validate() error
Validate checks the receipt.
type SnapshotRequest ¶
type SnapshotRequest struct {
SchemaVersion int `json:"schema_version"`
Detail Level `json:"detail"`
TaskKeyID string `json:"task_key_id,omitempty"`
ObservedAt time.Time `json:"observed_at"`
Hash string `json:"hash"`
Envelope json.RawMessage `json:"envelope"`
}
SnapshotRequest publishes the machine's reduced export envelope. The envelope is the Cockpit export envelope after the machine's detail-level reduction; it is opaque JSON at this boundary.
func (SnapshotRequest) Validate ¶
func (request SnapshotRequest) Validate() error
Validate checks the request. A `repositories` snapshot must name its task key; a `full` one must not. The envelope must carry nothing above the declared detail (CheckLevel).