Documentation
¶
Overview ¶
Package revocation carries credential revocation events, the bus that fans them out, and the watcher that cancels a context when one matches.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bus ¶
type Bus interface {
// Publish delivers ev to every subscriber, local and remote.
Publish(ctx context.Context, ev Event) error
// Subscribe registers fn and returns a func that removes it. fn must not
// block: it runs on the publisher's or listener's goroutine.
Subscribe(fn func(Event)) (unsubscribe func(), err error)
}
Bus fans revocation events out to subscribers. The default is in-process; implement it over Postgres NOTIFY or Redis pub/sub so a revocation on one node reaches streams held by another.
type Event ¶
type Event struct {
Kind Kind `json:"kind"`
ID string `json:"id,omitempty"`
UserID string `json:"userId,omitempty"`
Reason string `json:"reason,omitempty"`
At time.Time `json:"at"`
}
Event reports one revocation. An empty ID means "every credential of this kind belonging to UserID".
type MemoryBus ¶
type MemoryBus struct {
// contains filtered or unexported fields
}
MemoryBus is the in-process Bus.
type Target ¶
type Target struct {
UserID string
SessionID string
TokenID string
AgentID string
CredentialID string
DelegationID string
}
Target names the credential a stream was opened with. Set every ID that applies; an event matches when it names any of them.
type WatchOptions ¶
type WatchOptions struct {
// PollInterval, when positive, also re-validates SessionToken or
// BearerToken on a timer, a backstop for a bus that missed an event
// (a remote node, a dropped NOTIFY). Sessions reuse WatchSession.
PollInterval time.Duration
// SessionToken is the raw session token to poll.
SessionToken string
// BearerToken is the raw API token to poll.
BearerToken string
}
WatchOptions tunes a revocation watch.
type Watcher ¶
type Watcher struct {
Bus Bus
// WatchSession returns a context cancelled when the session dies; nil when sessions are unavailable.
WatchSession func(ctx context.Context, token string, every time.Duration) (context.Context, context.CancelCauseFunc)
// CheckBearer re-validates a raw API token; nil when API tokens are off.
CheckBearer func(ctx context.Context, raw string) error
}
Watcher supplies the credential re-validation a watch polls with.
func (Watcher) Watch ¶
func (w Watcher) Watch(ctx context.Context, target Target, opts WatchOptions) (context.Context, context.CancelCauseFunc)
Watch returns a context cancelled, with an error wrapping models.ErrCredentialRevoked as its cause, as soon as an event matches target or a poll finds the credential invalid. Call the cancel func when the stream ends.