Documentation
¶
Overview ¶
Package feed is authama's event feed: one ordered stream of what happened, for the API, webhooks and MCP, each event a CloudEvents 1.0 event in structured JSON (https://github.com/cloudevents/spec). An operation that finished (any change, made from the CLI or the web) is a com.simtabi.authama.operation.finished event; a change to a watched file is com.simtabi.authama.file.added, .changed, .removed or .mode-changed.
The envelope is sange's (its design, webhooks-and-events.md section 3.1), so one receiver reads both: the type is reverse-DNS from authama's own prefix, as its desktop notifier's app id is; the source is a URL naming this install by a random id, never the host or the user; a path in a home is written from ~, so neither a subject nor the data names the account.
It is read from the history database and the file events log, so it holds changes made by every authama process, not only the one serving the feed. Events are ordered by time, then id; a cursor names a place in that order.
Index ¶
Constants ¶
const ( TypeOperation = TypePrefix + "operation.finished" TypeFileAdded = TypePrefix + "file.added" TypeFileChanged = TypePrefix + "file.changed" TypeFileRemoved = TypePrefix + "file.removed" TypeFileMode = TypePrefix + "file.mode-changed" TypeWatchStarted = TypePrefix + "file.watch.started" TypeWebhookTested = TypePrefix + "webhook.tested" )
The event types.
const MaxLimit = 500
MaxLimit is the most events one List returns.
const TypePrefix = "com.simtabi.authama."
TypePrefix starts every event type: reverse-DNS, as authama's desktop notifier's app id is (com.simtabi.authama).
Variables ¶
var ErrBadCursor = errors.New("not a cursor this feed gave: pass the cursor of the last event you read, or none")
ErrBadCursor is a cursor this feed did not give.
Functions ¶
func Matches ¶
Matches reports whether e's type starts with one of prefixes, each given whole (com.simtabi.authama.file.) or without the common prefix (file.); no prefixes match every event.
Types ¶
type Event ¶
type Event struct {
SpecVersion string `json:"specversion"`
ID string `json:"id"`
Source string `json:"source"`
Type string `json:"type"`
Subject string `json:"subject,omitempty"`
Time time.Time `json:"time"`
DataContentType string `json:"datacontenttype"`
Data any `json:"data"`
// Sub is the authamasub extension: set per webhook delivery to the
// endpoint's name, inside the signed body, so a delivery captured from
// one endpoint cannot be replayed to another that checks it.
Sub string `json:"authamasub,omitempty"`
}
Event is one thing that happened: a CloudEvents 1.0 event.
func List ¶
List returns up to limit events after cursor, oldest first, and the cursor to pass next (the last event's, or cursor itself when there are none). An empty cursor lists the newest limit events.
type File ¶
type File struct {
Kind string `json:"kind"`
ChangedAt time.Time `json:"changed_at"`
Area string `json:"area"`
Path string `json:"path"`
Size int64 `json:"size,omitempty"`
Mode string `json:"mode,omitempty"`
Detail string `json:"detail,omitempty"`
}
File is a file event's data. The event's time is when authama noticed the change; ChangedAt is when the file says it changed, which can be much earlier (a change made while nothing was watching).
type Operation ¶
type Operation struct {
OpID string `json:"op_id"`
Command string `json:"command"`
Args []string `json:"args"`
// MadeFrom is where the change was made: cli or web (the history's
// source; named apart from the event's own source).
MadeFrom string `json:"made_from"`
Result string `json:"result"`
Error string `json:"error,omitempty"`
Subjects []string `json:"subjects,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
}
Operation is an operation.finished event's data.