transport

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

capabilities.go

control.go

http.go

stream.go

Index

Constants

View Source
const DefaultMaxBodyBytes int64 = 1 << 20

DefaultMaxBodyBytes caps the request envelope when no WithMaxBodyBytes option is given. The whole envelope is decoded before the intent's Requires predicate can run, so this cap is what bounds the work an unauthorized caller can make the server do.

Variables

This section is empty.

Functions

func NewCSRFTokenHandler

func NewCSRFTokenHandler(mgr *security.CSRFManager, ttl time.Duration) http.Handler

NewCSRFTokenHandler returns the GET /csrf handler. ttl is the token validity window the response surfaces to the client; the underlying manager is the authority on validation.

func NewCapabilitiesHandler

func NewCapabilitiesHandler(reg contract.Registry, shellEnvelopes []string, status ContributorStatusFunc) http.Handler

NewCapabilitiesHandler returns the GET /capabilities handler. status may be nil, which reports every contributor with the permissive default.

func NewHandler

NewHandler returns the POST /api/dashboard/{envelope} handler.

func NewHandlerWithCSRF

func NewHandlerWithCSRF(reg contract.Registry, wreg contract.WardenRegistry, disp Dispatcher, audit contract.AuditEmitter, mgr *security.CSRFManager, opts ...HandlerOption) http.Handler

NewHandlerWithCSRF is NewHandler plus a CSRFManager for command validation. When mgr is non-nil, command envelopes whose CSRF token does not validate return CodeUnauthenticated. Pass nil to skip CSRF (preserves the slice-(a) behaviour for tests and rollout opt-out).

Types

type CSRFTokenResponse

type CSRFTokenResponse struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expiresAt"`
}

CSRFTokenResponse is the wire shape for GET /api/dashboard/v1/csrf.

type CapabilitiesResponse

type CapabilitiesResponse struct {
	ShellEnvelopes []string                `json:"shellEnvelopes"`
	Contributors   []ContributorCapability `json:"contributors"`
}

CapabilitiesResponse is the wire shape for GET /capabilities.

type ContributorCapability

type ContributorCapability struct {
	Name      string             `json:"name"`
	Envelopes []string           `json:"envelopes"`
	Intents   []IntentCapability `json:"intents"`

	Version    string `json:"version,omitempty"`
	Configured bool   `json:"configured"`
	Message    string `json:"message,omitempty"`
}

ContributorCapability is one contributor's negotiable surface.

type ContributorStatus added in v1.11.1

type ContributorStatus struct {
	Version    string
	Configured bool
	Message    string
}

ContributorStatus is what the host reports about one contributor: the version a plugin's `requires` range is matched against, and whether the contributor has everything it needs to serve.

This mirrors dashboard.DashboardStatus, which is the interface extension authors implement. It is redeclared here because package dashboard already imports this package, so importing it back would be a cycle. The dashboard extension converts between the two at the wiring site.

type ContributorStatusFunc added in v1.11.1

type ContributorStatusFunc func(contributor string) (ContributorStatus, bool)

ContributorStatusFunc looks up a contributor's status by name. ok is false when nothing registered a status for that contributor, in which case the handler applies the permissive default (empty version, configured).

type ControlMessage

type ControlMessage struct {
	StreamID       string                          `json:"streamID"`
	Op             string                          `json:"op"` // "subscribe" | "unsubscribe"
	SubscriptionID string                          `json:"subscriptionID"`
	Contributor    string                          `json:"contributor,omitempty"`
	Intent         string                          `json:"intent,omitempty"`
	Params         map[string]contract.ParamSource `json:"params,omitempty"`
}

ControlMessage is one client request on POST /stream/control.

type Dispatcher

type Dispatcher interface {
	Dispatch(ctx context.Context, in contract.Request, p contract.Principal) (json.RawMessage, contract.ResponseMeta, error)
}

Dispatcher routes a fully-validated request to an intent implementation. Slice (c) provides the binding from intent name to actual handlers.

type HandlerOption added in v1.12.0

type HandlerOption func(*handler)

HandlerOption configures the handler returned by NewHandler.

func WithMaxBodyBytes added in v1.12.0

func WithMaxBodyBytes(n int64) HandlerOption

WithMaxBodyBytes sets the largest request envelope the handler will read. A larger body is refused with 413 and CodeBadRequest. n <= 0 keeps DefaultMaxBodyBytes; there is no way to switch the cap off.

type IntentCapability

type IntentCapability struct {
	Name     string                `json:"name"`
	Versions []IntentVersionStatus `json:"versions"`
}

IntentCapability summarises one intent's available versions.

type IntentVersionStatus

type IntentVersionStatus struct {
	N           int    `json:"n"`
	Status      string `json:"status"` // active | deprecated
	RemoveAfter string `json:"removeAfter,omitempty"`
}

IntentVersionStatus reports a single version + lifecycle status.

type NilDispatcher

type NilDispatcher struct{}

NilDispatcher is the safe default when no real Dispatcher has been wired. Every dispatch returns a CodeUnavailable contract error so that callers see a clear, kind-agnostic failure instead of a nil panic.

func (NilDispatcher) Dispatch

Dispatch implements Dispatcher.

type StreamBroker

type StreamBroker struct {
	// contains filtered or unexported fields
}

StreamBroker manages active SSE connections + their subscriptions.

func NewStreamBroker

func NewStreamBroker(reg contract.Registry, wreg contract.WardenRegistry, source SubscriptionSource) *StreamBroker

NewStreamBroker returns a broker bound to a registry, warden registry, and source.

func (*StreamBroker) ConnectionCount added in v1.12.0

func (b *StreamBroker) ConnectionCount() int

ConnectionCount reports how many stream connections are open right now. The dashboard reads it to tell whether somebody is watching: a client that only streams issues no further requests after it connects.

func (*StreamBroker) ServeControl

func (b *StreamBroker) ServeControl(w http.ResponseWriter, r *http.Request)

ServeControl handles POST /api/dashboard/v1/stream/control.

func (*StreamBroker) ServeStream

func (b *StreamBroker) ServeStream(w http.ResponseWriter, r *http.Request)

ServeStream implements GET /api/dashboard/v1/stream.

func (*StreamBroker) SnapshotIDs

func (b *StreamBroker) SnapshotIDs() []string

SnapshotIDs returns currently-active stream IDs (test helper / introspection).

type SubscriptionSource

type SubscriptionSource interface {
	Subscribe(ctx context.Context, p contract.Principal, contributor string, intent contract.Intent, params map[string]contract.ParamSource) (<-chan contract.StreamEvent, func(), error)
}

SubscriptionSource is the upstream events feeder. Slice (c) implements one for each contributor's subscription intents.

Jump to

Keyboard shortcuts

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