Documentation
¶
Overview ¶
Package exampleapp holds the todo-app wiring shared by cmd/testserver and cmd/todoserver: entity registration, the complete_all mutator, and a small permission policy exercised by the test suites.
Index ¶
- func MutatorOptions(perms *Permissions) []server.Option
- func Options(perms *Permissions) []server.Option
- type Permissions
- func (p *Permissions) BumpEpoch(workspaceID string) uint64
- func (*Permissions) CanMutate(_ context.Context, _ server.Principal, _ string, w server.Write) error
- func (p *Permissions) FilterEpoch(_ context.Context, _ server.Principal, workspaceID string) (uint64, error)
- func (*Permissions) ProtectedFields(_ context.Context, p server.Principal, _, entity string) ([]string, error)
- func (*Permissions) ReadFilter(_ context.Context, _ server.Principal, _ string, entity string) (server.RowFilter, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MutatorOptions ¶
func MutatorOptions(perms *Permissions) []server.Option
MutatorOptions returns just complete_all, write_then_reject, fail_internal and bump_epoch, for servers that declare the todo entity themselves.
func Options ¶
func Options(perms *Permissions) []server.Option
Options returns the server options for the whole example app: the todo, note and annotation entities plus every example mutator. perms may be nil when the caller does not install the example permission policy; the bump_epoch mutator is then a no-op.
srv, err := server.New(store, append(exampleapp.Options(perms), server.WithPermissions(perms))...)
Types ¶
type Permissions ¶
Permissions rejects todo writes whose title contains "forbidden" and hides todos whose title contains "secret" from reads. The filter epoch is a process-local counter per workspace that the bump_epoch mutator advances, standing in for out-of-band visibility changes (e.g. a membership edit). It also protects one field per caller (see ProtectedFields), which is the one hook here that does read the principal.
It embeds server.AllowAll purely to show the partial-implementation pattern; every hook below is overridden. CanMutate authorizes on the write's content rather than on the caller, so it ignores the principal — a real policy would not.
Safe for concurrent use.
func NewPermissions ¶
func NewPermissions() *Permissions
NewPermissions returns the example permission policy (every workspace's epoch starts at 0).
func (*Permissions) BumpEpoch ¶
func (p *Permissions) BumpEpoch(workspaceID string) uint64
BumpEpoch invalidates every outstanding cursor for one workspace, leaving the other workspaces' alone. This policy does not implement server.EpochReadFilters, so the next pull of every client in that workspace resets into a re-bootstrap (the delta-resync fallback path).
func (*Permissions) FilterEpoch ¶
func (*Permissions) ProtectedFields ¶
func (*Permissions) ProtectedFields( _ context.Context, p server.Principal, _, entity string, ) ([]string, error)
ProtectedFields puts the "guarded" entity's `label` out of reach of the subject "viewer", on top of the fields that entity's schema already marks.
It is the per-caller half of field protection, and the only half a client cannot predict: the suites assert that such a write enqueues and comes back as a rejection ack, where a schema-marked field is refused at the call site. The subject comes from the bearer token testserver takes at face value, so a spec chooses which side of the rule it is on by who it authenticates as.