Documentation
¶
Overview ¶
Package safety gates the commands that change or destroy something.
The shell toolkit had no preview, no confirmation and no dry run, and one tool scheduled a reboot when it was asked for its help text. Every command that powers off, reinstalls, drains or overwrites goes through here first.
Index ¶
Constants ¶
const EffectAnnotation = "clusterctl.effect"
EffectAnnotation is the key under which a command records its effect.
Variables ¶
var ErrDryRun = errDryRun{}
ErrDryRun is returned by Confirm when the gate is in dry run mode. A command treats it as "stop here, successfully".
Functions ¶
Types ¶
type Action ¶
type Action struct {
// Verb is what is being done, "power off" or "reinstall".
Verb string
// Targets are the hosts it happens to.
Targets *nodeset.NodeSet
// Detail is an extra line shown before the prompt, such as the command
// that will run.
Detail string
}
Action describes what is about to happen, for the prompt and the preview.
type Effect ¶
type Effect string
Effect says what running a command does to the site. The command tree records it on every command, so that anything driving the tree on behalf of someone else, such as the MCP server, can tell a question from a change without keeping its own list.
const ( // EffectRead only looks. It may contact hosts, but changes nothing on // them. EffectRead Effect = "read" // EffectChange changes or destroys something, or may do so depending on // its arguments. EffectChange Effect = "change" // EffectInteractive needs a terminal, opens a program or keeps running // until it is stopped. EffectInteractive Effect = "interactive" )
type Gate ¶
type Gate struct {
// Protected are the hosts no destructive command touches unless Force
// is set.
Protected *nodeset.NodeSet
// ConfirmAbove asks for the host count to be typed back when an action
// targets more than this many hosts.
ConfirmAbove int
// AssumeYes answers every prompt with yes, for -y and for scripts.
AssumeYes bool
// Force allows a protected host to be touched.
Force bool
// DryRun reports what would happen and does nothing.
DryRun bool
// Interactive says whether a prompt can be answered at all. When it is
// false and AssumeYes is not set, an action is refused rather than
// silently carried out.
Interactive bool
// In and Out are the terminal the prompt uses.
In io.Reader
Out io.Writer
}
Gate decides whether a destructive action may go ahead.
func NewGate ¶
func NewGate(spec v1alpha1.SafetySpec) (*Gate, error)
NewGate builds a gate from the safety configuration of a site.
func (*Gate) Check ¶
Check refuses an action that touches a protected host, unless the gate was forced.
type Preview ¶
type Preview struct {
// Verb is what is being done.
Verb string `json:"verb"`
// Targets is the folded node set the action touches.
Targets string `json:"targets"`
// Count is how many hosts that is.
Count int `json:"count"`
// Detail is the extra line shown before the question.
Detail string `json:"detail,omitempty"`
// CountRequired says that a yes is not enough: the host count has to be
// read off the preview and given back.
CountRequired bool `json:"countRequired"`
// ConfirmAbove is the host count above which the count is required.
ConfirmAbove int `json:"confirmAbove,omitempty"`
}
Preview is an action that passed the checks and waits for an answer. It carries everything the question is asked from, so that a caller without a terminal can put the same question some other way and have the answer judged by the same rule.
func (Preview) Accept ¶
Accept judges an answer to the question: the host count when it is required, a yes otherwise. It returns nil when the action may proceed.