desk

package
v0.220.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 12 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
	MaxHeartbeatIntervalSeconds = 86400
	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 MaxEnvelopeDepth = 64

MaxEnvelopeDepth bounds how deeply CheckLevel lets an envelope nest. A real fleet document nests under ten levels; without the bound, a small, highly compressible envelope of deep chains would make the check build path strings quadratic in its depth, and with GOEXPERIMENT=nojsonv2 the decoder sets no depth limit of its own.

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. At every level an object with a duplicate key is refused, and at `repositories` so is a key that differs only in case from a name on a withheld path: a case-insensitive decoder such as Go's would otherwise read what this check did not. 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 SnapshotHash

func SnapshotHash(envelope, repositoriesEnvelope []byte, taskKeyID string) string

SnapshotHash is a snapshot request's `hash`, the one definition the daemon and Desk share (desk-connect#req:publish-on-change). A request that sends one envelope hashes it alone: SHA-256 of envelope. A `full` request that also carries repositoriesEnvelope hashes the domain string, then the envelope, the repositories envelope and the task key id, each preceded by its length as an 8-byte big-endian integer, so a changed task key id alone changes the hash. taskKeyID is ignored when repositoriesEnvelope is empty.

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"`
	// IntervalSeconds is the configured heartbeat interval (desk.heartbeat.interval).
	IntervalSeconds int `json:"interval_seconds,omitempty"`
	// LastError is the code of the daemon's current publish failure. It is
	// absent when there is none: after a success, when Desk already holds the
	// current snapshot, and in every heartbeat `wb desk push` sends after its
	// own accepted publish. Absent means no current error, never "unchanged".
	LastError ErrorCode `json:"last_error,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"`
	// RepositoriesEnvelope is the machine's `repositories`-level reduction of
	// the same snapshot, sent alongside a `full` envelope so Desk can serve
	// shares below `full` without reducing snapshots itself.
	RepositoriesEnvelope json.RawMessage `json:"repositories_envelope,omitempty"`
}

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. RepositoriesEnvelope is allowed only when Detail is `full` and must pass CheckLevel at `repositories`. TaskKeyID is required whenever a `repositories`-level envelope is present (either Detail == `repositories`, or Detail == `full` with RepositoriesEnvelope), and forbidden otherwise. 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