Documentation
¶
Overview ¶
Package bridgeapi serves :8443, over TLS only (GP-18): run bridges push their harness events here (C4: runs push, the broker never dials into a sandbox), and system principals read and annotate logs (SP3's API).
Every refusal is a wire.Error whose reason is a wire.Reason* constant. The log's sentinel errors map to status codes in one place, logFailure.
Index ¶
Constants ¶
const ( // StubInvalidValue is a value the store rejected (SQLSTATE class 22, such as a NUL in jsonb). StubInvalidValue = "invalid_value" // StubKeyCollision is keys that are one once redacted: case-folded or NUL-equal (Ruling AI). StubKeyCollision = "key_collision" )
Why the broker stored an item as a stub rather than as sent. Each is the stub's reason field, and a label of rooms_bridge_items_stubbed_total (S1 review I-4).
Variables ¶
This section is empty.
Functions ¶
func Deliverable ¶
Deliverable derives what the running run must receive from the log itself: deliveries are durable, replica-agnostic, and resume from the bridge's last ack.
func TLSConfig ¶
TLSConfig serves the pair at certFile and keyFile (GP-18: cert-manager's Certificate room-broker-tls). Each handshake compares both files' size and modification time with the last seen, and re-reads the pair once either changes, so a renewal needs no restart. A pair that fails to load, such as one caught mid-rotation, is logged and the last good one stays in service. It refuses to start without a loadable pair.
Types ¶
type Approvals ¶
type Approvals interface {
RequestApproval(ctx context.Context, a store.Approval, d envelope.Draft) (store.Approval, envelope.Event, error)
Prompters(ctx context.Context, roomID, runID string) ([]string, error)
}
Approvals is the part of the store the approval route writes; *store.Store implements it.
type Authenticator ¶
Authenticator maps a request's credential to a principal. *authn.Runs and *authn.Systems implement it; authn.ErrForbidden means a valid credential for a principal outside the allowlist.
type Hub ¶
type Hub interface {
Subscribe(ctx context.Context, roomID string) (*fanout.Sub, error)
Unsubscribe(*fanout.Sub)
}
Hub is the fan-out hub's subscription side; *fanout.Hub implements it.
type Limits ¶
type Limits struct {
Rate float64 // requests a second, refilled continuously
Burst int // requests at once after a quiet spell
InFlight int // requests being served at once
}
Limits bound each principal on the events endpoint and the system API. A zero field takes its default.
type Log ¶
type Log interface {
Append(ctx context.Context, d envelope.Draft) (envelope.Event, bool, error)
AppendAsBridge(ctx context.Context, bridgeRun string, d envelope.Draft) (envelope.Event, bool, error)
Range(ctx context.Context, roomID string, afterSeq int64, limit int) ([]envelope.Event, error)
// Deliveries is the run's deliverable events in (after, through], paged (phase 4).
Deliveries(ctx context.Context, roomID, runID string, after, through int64, limit int) ([]envelope.Event, error)
Cursor(ctx context.Context, roomID, originClient string) (int64, error)
Room(ctx context.Context, id string) (store.RoomState, error)
ClaimBridge(ctx context.Context, roomID, runID string, live func(ctx context.Context, runID string) bool) (string, bool, error)
TouchBridge(ctx context.Context, roomID, runID string) (held bool, err error)
}
Log is the part of the store the API reads and writes. A bridge's events go only through AppendAsBridge, fenced on the room's bridge lease (Ruling Y).
type QueueStore ¶
type QueueStore interface {
Enqueue(ctx context.Context, d envelope.Draft, author, text string) (envelope.Event, error)
Queue(ctx context.Context, roomID string) ([]store.Queued, error)
SetQueued(ctx context.Context, roomID string, ref int64, to, runID string) error
Cursor(ctx context.Context, roomID, originClient string) (int64, error)
}
QueueStore is the room queue (SP2 phase 4) as system callers reach it: SP3's factory queues a maintainer's GitHub review in the task's room, and consumes what its next run's brief quoted (SP3 R9). *store.Store implements it.
type Redactor ¶
type Redactor interface {
Payload(ctx context.Context, raw json.RawMessage) (json.RawMessage, []string, error)
}
Redactor removes secrets from a JSON payload, keys included, and fails once ctx ends rather than return it partly scanned; *redact.Redactor implements it.
type Server ¶
type Server struct {
Log Log
Redactor Redactor
Runs Authenticator
Systems Authenticator
Watch Liveness
// RoomPolicy, when set, is the room's approval policy handed out at hello and
// read for each approval's deadline (phase 5); unset means attended.
RoomPolicy func(ctx context.Context, roomID string) wire.ApprovalPolicy
// Approvals records approval requests (phase 5); unset answers 503.
Approvals Approvals
// PingEvery is the stream's keep-alive period; 0 means 30 s.
PingEvery time.Duration
// Ticker starts the stream's keep-alive; nil means a time.Ticker.
Ticker func(d time.Duration) (c <-chan time.Time, stop func())
// ReplayPage is how many deliveries a stream's replay reads at once; 0 means 500.
ReplayPage int
// StreamWriteWait bounds each write to a stream; 0 means 10 s.
StreamWriteWait time.Duration
// Hub feeds each stream its room's live events, and LastAck is where a run's
// deliveries resume (phase 4). The stream refuses to start without them.
Hub Hub
LastAck func(ctx context.Context, room, run string) (int64, error)
// Limits bound each principal on the events endpoint and the system API.
Limits Limits
// Queue serves the system queue routes (SP3 R9); nil answers them 501.
Queue QueueStore
// SlackLinks serves GET /v1/links/slack to SlackLinkReader alone (the factory, system:factory);
// either unset refuses it.
SlackLinks SlackLinks
SlackLinkReader string
// Now is the limits' clock; nil means time.Now. Deadlines handed to the
// runtime (a context's, a connection's) stay on its own clock: a fake one
// there would expire a request before it starts, or never.
Now func() time.Time
Logger *slog.Logger
// contains filtered or unexported fields
}
Server is the :8443 API. Log, Redactor, Runs, Systems and Watch are required; the rest is optional.
func (*Server) Drop ¶
Drop ends a run's stream on this replica; register it with Watcher.OnGone (S4).
func (*Server) ListenAndServeTLS ¶
func (s *Server) ListenAndServeTLS(ctx context.Context, addr string, cfg *tls.Config, drain time.Duration) error
ListenAndServeTLS serves the API on addr with cfg (TLSConfig's) until ctx ends, then drains for at most drain. Streams end at once on shutdown: their bridges re-dial another replica.