exampleapp

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 10 Imported by: 0

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

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, set_owner and bump_epoch, for servers that declare the todo entity themselves. Every caller admitted to the workspace may invoke each of them, in a schema that uses the access model too.

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

type Permissions struct {
	server.AllowAll
	// contains filtered or unexported fields
}

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) CanMutate

func (*Permissions) FilterEpoch

func (p *Permissions) FilterEpoch(_ context.Context, _ server.Principal, workspaceID string) (uint64, error)

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 guard already keeps from every client.

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 field no guard rule admits writing 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.

func (*Permissions) ReadFilter

func (*Permissions) ReadFilter(_ context.Context, _ server.Principal, _ string, entity string) (server.RowFilter, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL