Documentation
¶
Overview ¶
Package gates holds every decision waiting on the user: it opens a gate, resolves it only through the user API or a trusted policy rule, and applies the one consequence its kind names.
Index ¶
- Constants
- Variables
- type Begun
- type Decider
- type Decision
- type Def
- type Deliverer
- type Deps
- type Events
- type Intent
- type Once
- type OwnTasks
- type Policy
- type Profile
- type Publisher
- type Query
- type Reader
- type Releaser
- type Resolution
- type Sent
- type Service
- func (s *Service) Cut() []gate.Gate
- func (s *Service) NextDeadline(ctx context.Context) (time.Time, error)
- func (s *Service) Open(ctx context.Context, g gate.Gate, p Policy) (gate.Gate, error)
- func (s *Service) RecordSent(ctx context.Context, g gate.Gate) (gate.Gate, error)
- func (s *Service) Resolve(ctx context.Context, id int64, r Resolution) error
- func (s *Service) Supersede(ctx context.Context, id int64, by task.Actor) error
- func (s *Service) Tick(ctx context.Context, now time.Time) error
- type Store
- type Tasks
- type Unblocker
Constants ¶
const RuleWindow = "window"
RuleWindow is the Rule of a gate its passed Deadline resolved to its Default.
Variables ¶
var ( // ErrRefused is a resolution the gate does not accept: by an agent or a // plugin, by a rule the trusted policy does not hold, or by a window that // has not passed. ErrRefused = errors.New("the gate refuses the resolution") // ErrIntent is an intent the gate does not offer, or one gates.toml does // not declare for it. ErrIntent = errors.New("the gate offers no such intent") // ErrNoDef is a gate gates.toml does not declare, by name or by kind. ErrNoDef = errors.New("gates.toml declares no such gate") )
var ( ErrNoGate = errors.New("no such gate") ErrResolved = errors.New("the gate is resolved already") )
Functions ¶
This section is empty.
Types ¶
type Begun ¶
type Begun interface {
// Begin marks resolved gate id's consequence run, and begun until End.
Begin(ctx context.Context, id int64) error
End(ctx context.Context, id int64) error
// Begun are the resolved gates whose consequence began and never ended.
Begun(ctx context.Context) ([]gate.Gate, error)
}
Begun is optional on a Store: it keeps an at-most-once consequence begun until it ends, so one a stopped daemon cut can be reported.
type Decision ¶
Decision is how an approval decides a gate: its Mode, a delay's Window, and Rule, the rule that decided, which a gate it releases records.
type Def ¶
Def is a gate the profile's gates.toml declares: its kind, its words and its intents in the order clients offer them.
type Deps ¶
type Deps struct {
Store Store
Reader Reader
Profile Profile
// Tasks gives a gate the task of its unit; nil leaves it with none.
Tasks Tasks
// Policy decides a gate Open is given no policy for, and is the one a
// resolution naming a rule is checked against; nil holds every gate.
Policy Policy
Clock port.Clock
Publisher Publisher
Releaser Releaser
Deliverer Deliverer
Decider Decider
Unblocker Unblocker
// Events records a resolved step gate; nil records none.
Events Events
Log func(format string, args ...any)
}
Deps are what the service reads, writes and applies. Every consequence port is optional: a kind whose port is nil resolves with no consequence.
type Intent ¶
Intent is what a gate is resolved with: the status gates.toml gives it, and whether it takes text.
type Once ¶
Once is optional on a consequence port: a gate it answers true for is marked run before its consequence runs, so a daemon that stops during the consequence never runs it again, and may leave it not run. For a consequence that acts in the user's name and keeps no record a second run could read, such as a round or a verb.
type OwnTasks ¶
OwnTasks is optional on Tasks: the unit's own task, such as a pull request's, which a gate on the unit goes to whatever its state, reopened when it is done, so the unit keeps one task.
type Policy ¶
Policy is a trusted approval: the profile's and the configuration's [gates.approval], never an agent's or a thread's text.
type Query ¶
Query narrows Where: a zero field matches every gate, but Statuses, which matches the open gates when empty.
type Reader ¶
type Reader interface {
// Get is gate id; ErrNoGate when there is none.
Get(ctx context.Context, id int64) (gate.Gate, error)
// OfTask are task id's gates, open and closed.
OfTask(ctx context.Context, id task.ID) ([]gate.Gate, error)
// Where are the gates matching q.
Where(ctx context.Context, q Query) ([]gate.Gate, error)
}
Reader reads the gates, open and closed. Its lists are ordered by ID, oldest first; a list nothing matches is empty.
type Resolution ¶
Resolution is how a gate closed: Intent is the intent a person or a rule chose and Status the one gates.toml gives it, Answer a question's text, By who resolved it, Rule the policy rule that released it ("window" for a deadline's default), "" for a person.
type Sent ¶
Sent records a post an agent made at once with a tool as a gate already approved. It is no resolution: no agent resolves an open gate.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service opens the gates and is the only code that resolves one.
func (*Service) Cut ¶
Cut are the resolved gates whose at-most-once consequence began and was cut by a daemon that stopped, so it may not have run, by ID.
func (*Service) NextDeadline ¶
NextDeadline is the earliest Deadline of an open gate, zero when none has one.
func (*Service) Open ¶
Open opens g under p, nil meaning the service's Policy. The gate takes its kind and intents from gates.toml: the gate g names, else the first of its kind. It takes the task of its unit, or a new capture task when no task holds it. A policy that releases it resolves it at once with its rule; a delay gives it a Deadline and the Default its approving intent; a dry_run rejects a draft gate and holds any other.
func (*Service) RecordSent ¶
RecordSent records g, a post a tool made at once, as a gate already approved by g.By with g.Rule, worded by gates.toml and on the task of its unit when one holds it. It resolves no gate and applies no consequence.
func (*Service) Resolve ¶
Resolve closes open gate id with r. It accepts a person's intent, the Default of a gate whose Deadline passed with the rule window, and a rule the service's trusted Policy holds for the gate now; it refuses anything else, an agent's or a plugin's resolution above all. Status comes from the intent's declaration in gates.toml. It then applies the one consequence the gate's kind names.
func (*Service) Supersede ¶
Supersede closes open gate id as superseded by by, its subject gone or replaced, with no consequence: the subject's owner settles the subject. It refuses an agent: no agent closes an open gate.
type Store ¶
type Store interface {
// Open stores g as open with a new ID and OpenedAt, and returns it.
Open(ctx context.Context, g gate.Gate) (gate.Gate, error)
// Resolve closes the open gate id with r and returns it: ErrNoGate when
// there is none, ErrResolved when it is closed already. A Resolution whose
// Status is open is refused.
Resolve(ctx context.Context, id int64, r Resolution) (gate.Gate, error)
// Due are the open gates whose Deadline is set and not after now.
Due(ctx context.Context, now time.Time) ([]gate.Gate, error)
// Applied marks resolved gate id's consequence as run; an open gate is
// refused.
Applied(ctx context.Context, id int64) error
// Unapplied are the resolved gates whose consequence has not run: a
// superseded gate and a recorded send have none.
Unapplied(ctx context.Context) ([]gate.Gate, error)
}
Store writes the gates. Its lists are ordered by ID, oldest first; a list nothing matches is empty.