Documentation
¶
Overview ¶
capabilities.go
control.go
http.go
stream.go
Index ¶
- Constants
- func NewCSRFTokenHandler(mgr *security.CSRFManager, ttl time.Duration) http.Handler
- func NewCapabilitiesHandler(reg contract.Registry, shellEnvelopes []string, status ContributorStatusFunc) http.Handler
- func NewHandler(reg contract.Registry, wreg contract.WardenRegistry, disp Dispatcher, ...) http.Handler
- func NewHandlerWithCSRF(reg contract.Registry, wreg contract.WardenRegistry, disp Dispatcher, ...) http.Handler
- type CSRFTokenResponse
- type CapabilitiesResponse
- type ContributorCapability
- type ContributorStatus
- type ContributorStatusFunc
- type ControlMessage
- type Dispatcher
- type HandlerOption
- type IntentCapability
- type IntentVersionStatus
- type NilDispatcher
- type StreamBroker
- type SubscriptionSource
Constants ¶
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 ¶
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 ¶
func NewHandler(reg contract.Registry, wreg contract.WardenRegistry, disp Dispatcher, audit contract.AuditEmitter, opts ...HandlerOption) http.Handler
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
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 ¶
func (NilDispatcher) Dispatch(_ context.Context, _ contract.Request, _ contract.Principal) (json.RawMessage, contract.ResponseMeta, error)
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.