rules

package
v0.34.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: BSD-2-Clause Imports: 5 Imported by: ? 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 rules carries the write rules the API enforces: which phase and status transitions are legal, and which guards gate the approve endpoint.

It reproduces vault-cli's approve guards rather than importing them. Those guards are unexported methods of the approve operation and return plain errors with no type to map onto 400/409/422, so this package carries its own typed RefusalError with the same three conditions and the same refusal wording. Injecting a git-rest-backed storage.TaskStorage into ops.NewTaskApproveOperation would give exact guard parity, but its errors are untyped strings and the handler would have to match on message text to pick a status code.

Index

Constants

View Source
const (
	// CodeInvalidTransition is an edge the graph does not carry.
	CodeInvalidTransition = "invalid_transition"
	// CodeApprovalRequired is a write that only an approval may perform.
	CodeApprovalRequired = "approval_required"
	// CodeApprovalIsAVerb is an attempt to write the approval record by edit.
	CodeApprovalIsAVerb = "approval_is_a_verb"
	// CodeNotApprovable is an approval of a task that is not in the inbox.
	CodeNotApprovable = "not_approvable"
	// CodeAlreadyApproved is an approval of a task that already carries one.
	CodeAlreadyApproved = "already_approved"
	// CodeBlankApprover is an approval naming no approver.
	CodeBlankApprover = "blank_approver"
	// CodeInvalidClock is an approval whose instant is the zero value.
	CodeInvalidClock = "invalid_clock"
	// CodeUnknownPhase is a phase value outside the enum.
	CodeUnknownPhase = "unknown_phase"
	// CodeUnknownStatus is a status value outside the enum.
	CodeUnknownStatus = "unknown_status"
)

RefusalError codes. Each names one refusal class; the HTTP layer maps a code to a status, so the code is the contract and the message is for humans.

View Source
const ApproveEndpoint = "POST /api/v1/tasks/{id}/approve"

ApproveEndpoint is the only route that may write an approval record. It appears in the allowed list of every refusal that says approval is a verb.

Variables

This section is empty.

Functions

func RefuseApprovalRecordWrite

func RefuseApprovalRecordWrite() error

RefuseApprovalRecordWrite is the refusal for an edit that tries to write the approval record directly instead of going through the approve endpoint.

func UnknownPhase

func UnknownPhase(raw string) error

UnknownPhase is the refusal for a phase value outside the enum.

func UnknownStatus

func UnknownStatus(raw string) error

UnknownStatus is the refusal for a status value outside the enum.

func ValidateApprove

func ValidateApprove(
	approvedBy string,
	phase domain.TaskPhase,
	hasApprovalRecord bool,
	approvedAt time.Time,
) error

ValidateApprove applies the three guards the approve endpoint enforces, in the order vault-cli applies them: a blank approver, a clock that is not an instant, a task outside the approval inbox, and a task that already carries an approval record. The returned error is always a *RefusalError.

func ValidatePhaseTransition

func ValidatePhaseTransition(from, to domain.TaskPhase) error

ValidatePhaseTransition reports whether moving a task from one phase to another is legal. The returned error is always a *RefusalError.

func ValidateStatusTransition

func ValidateStatusTransition(
	phase domain.TaskPhase,
	from, to domain.TaskStatus,
) error

ValidateStatusTransition reports whether moving a task from one status to another is legal at the task's current phase. A task enters in_progress only once its phase is past todo, so that one edge is refused while the task still sits in the approval inbox. The returned error is always a *RefusalError.

Types

type RefusalError

type RefusalError struct {
	Code    string
	Detail  string
	From    string
	To      string
	Allowed []string
}

RefusalError is the typed error every rule in this package returns. Code names the refusal class; From, To and Allowed carry the detail a caller needs to act on the refusal rather than merely read it.

func (*RefusalError) Error

func (r *RefusalError) Error() string

Error returns the human-readable refusal message.

Jump to

Keyboard shortcuts

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