desk

package
v0.212.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 8 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

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

View Source
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.

View Source
const (
	MaxGrantSeconds            = 600
	MaxMachineNameLength       = 128
	MaxVersionLength           = 64
	MaxPlatformLength          = 32
	MaxSpaceIDLength           = 128
	MaxCredentialLength        = 1024
	MaxDeviceCodeLength        = 512
	MaxURILength               = 2048
	MaxShares                  = 64
	MaxCompressedSnapshotBytes = 1 << 20
	MaxDecodedSnapshotBytes    = 8 << 20
	// MaxResponseBytes caps every non-snapshot response body a client reads.
	MaxResponseBytes = 64 << 10
)

Bounds of the contract.

View Source
const DefaultURL = "https://desk.sneat.dev"

DefaultURL is the hosted Desk origin.

View Source
const SchemaVersion = 1

SchemaVersion is the Desk payload schema this build sends.

Variables

View Source
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

func Decode(reader io.Reader, limit int64, target Validator) error

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"`
	Shares          []Share    `json:"shares,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"
)

func ErrorCodes

func ErrorCodes() []ErrorCode

ErrorCodes lists every ErrorCode in a stable order.

func (ErrorCode) Valid

func (code ErrorCode) Valid() bool

Valid reports whether code is a known ErrorCode.

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 Level

type Level string

Level is a machine's detail level: what the daemon sends.

const (
	LevelRepositories Level = "repositories"
	LevelFull         Level = "full"
)

func (Level) Valid

func (level Level) Valid() bool

Valid reports whether level is a machine detail level.

type MachineRef

type MachineRef struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

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"`
	Shares           []Share    `json:"shares,omitempty"`
	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 Scope

type Scope string

Scope is a Desk machine credential scope.

const (
	ScopeSnapshotPublish Scope = "desk_snapshot:publish"
	ScopeHeartbeatWrite  Scope = "desk_heartbeat:write"
	ScopeMachineReadSelf Scope = "desk_machine:read_self"
)

func Scopes

func Scopes() []Scope

Scopes is the exact scope set a desk-connect credential carries.

type Share

type Share struct {
	SpaceID string     `json:"space_id"`
	Level   ShareLevel `json:"level"`
	State   ShareState `json:"state"`
}

Share is one space a grant shared the machine into.

type ShareLevel

type ShareLevel string

ShareLevel is what a space shows of a shared machine (desk-spaces).

const (
	ShareSummary      ShareLevel = "summary"
	ShareRepositories ShareLevel = "repositories"
	ShareFull         ShareLevel = "full"
)

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 (
	SharePending ShareState = "pending"
	ShareActive  ShareState = "active"
)

func (ShareState) Valid

func (state ShareState) Valid() bool

Valid reports whether state is a share state a grant can return.

type SnapshotReceipt

type SnapshotReceipt struct {
	Hash       string    `json:"hash"`
	AcceptedAt time.Time `json:"accepted_at"`
}

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).

type Validator

type Validator interface{ Validate() error }

Validator is any contract type.

Jump to

Keyboard shortcuts

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