controller

package
v1.80.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package controller is the Outline controller: for every Outline workspace the policy declares, read what Outline holds and what the directory says of each of its people, decide, act where the workspace is enabled, and report.

It is built on the rails the GitHub and Slack controllers share (internal/rails, docs/decisions/0024): the pass loop, the policy guard on every answer of the console, the tick lease, the breaker fingerprints, the held-once ledger, the last-good-report journal and the dry-run switch.

One tick

  1. The workspace's connection record and API key are read from the console's records. A workspace with none is waiting, not failed.
  2. Outline is read whole: the key's own user and the team settings, every account (the suspended included), the groups and the managed groups' members, the collections and the bound collections' grants and direct members. A read cut short of a group or a collection holds that one; of anything else, it fails the tick. A 429 fails the tick, which the next one tries again.
  3. Each account's address is put to the console's Explain, which resolves it as the issuer does (the directory's standing, then the policy), and every answer is held to this pass's policy digest.
  4. The decision (package reconcile), and, when the workspace is enabled (rails.Switch), the changes, each recorded to the audit trail.
  5. The workspace's report is published. A failed tick keeps its previous report with the failure on it.

Index

Constants

View Source
const DefaultInterval = 2 * time.Minute

DefaultInterval is the time between two passes: short, because a person who signs in for the first time sees nothing but their own documents until the pass after.

View Source
const DefaultShareScan = time.Hour

DefaultShareScan is how often the single-document shares are read: each document is two calls, so not every pass.

View Source
const LeaseKind = "outline-tick"

LeaseKind is the kind of lease on a workspace's tick.

View Source
const MaxScannedDocuments = 5000

MaxScannedDocuments bounds a share scan; a workspace past it is reported and not scanned.

Variables

View Source
var ErrUnknownTarget = errors.New("not a target of this controller")

ErrUnknownTarget is a target that is not a workspace the policy declares.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Interval is the time between passes. Zero is [DefaultInterval].
	Interval    time.Duration
	PolicyRetry time.Duration
	// Enabled are the workspaces the controller acts in. Every other is a
	// dry run.
	Enabled map[string]bool
	// ShareScan is how often the single-document shares are read. Zero is
	// [DefaultShareScan]; negative never reads them.
	ShareScan time.Duration
	// RecordPoll is how often the records are looked at for a change or a
	// request for a pass. Zero is thirty seconds; negative turns it off.
	RecordPoll time.Duration
}

Config is what a deployment decides.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller is the loop and what it remembers between passes.

func New

func New(cfg Config, deps Deps) *Controller

New returns a controller.

func (*Controller) Pass

func (c *Controller) Pass(ctx context.Context) (otherPolicy bool)

Pass is a sweep: every declared workspace once, each under its own lease. It says whether any answer came from a console under another policy.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context) error

Run passes now and then every interval until the context ends. A changed record wakes a pass at once, and an operator's request ticks its workspace.

func (*Controller) RunTarget

func (c *Controller) RunTarget(ctx context.Context, target string) (ran, otherPolicy bool, err error)

RunTarget ticks one workspace under its lease and says whether it ran: false, with no error, when another runner holds the lease.

func (*Controller) Targets

func (c *Controller) Targets() []string

Targets are the declared workspaces, by key.

func (*Controller) Tick

func (c *Controller) Tick(ctx context.Context, target string) (otherPolicy bool)

Tick is one workspace's work, with no lease: its pass, ending in its own report whatever happened, which it publishes.

type Deps

type Deps struct {
	Log       *slog.Logger
	Directory Directory
	// Audit is where the controller records what it did. Nil records
	// nothing.
	Audit   audit.Recorder
	Status  rails.Store
	Records RecordSource
	// Policy is the declared policy the controller decides with, and Digest
	// its digest: an answer of the console under another is not acted on.
	Policy policy.Policy
	Digest string
	// Outline makes the client of a workspace. Nil is Outline's own API.
	Outline func(url, key string) *outlineapi.Client
	// Leases takes a lease on each workspace before its tick. Nil runs every
	// tick without one: a single runner.
	Leases *rails.Leases
	Now    func() time.Time
}

Deps are what the controller talks to.

type Directory

Directory is the console as this controller asks it: the three questions, each answered with the digest of the policy it was computed under. The generated AccessService client is one.

type RecordSource

type RecordSource interface {
	// Get is one workspace's record and API key; found is false when it is
	// not connected.
	Get(ctx context.Context, workspace string) (connection.Record, connection.Credential, bool, error)
	// Confirmations are the operators' confirmations that still stand, of
	// every workspace.
	Confirmations(ctx context.Context) ([]connection.Confirmation, error)
	// PassRequests are the operators' last requests for a pass now, by
	// workspace.
	PassRequests(ctx context.Context) (map[string]connection.PassRequest, error)
	// Digest summarises the records, so a change wakes a pass.
	Digest(ctx context.Context) ([32]byte, error)
}

RecordSource is where the console keeps the workspaces' records (internal/portstore.OutlineWorkspaces).

Jump to

Keyboard shortcuts

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