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
- func RefuseApprovalRecordWrite() error
- func UnknownPhase(raw string) error
- func UnknownStatus(raw string) error
- func ValidateApprove(approvedBy string, phase domain.TaskPhase, hasApprovalRecord bool, ...) error
- func ValidatePhaseTransition(from, to domain.TaskPhase) error
- func ValidateStatusTransition(phase domain.TaskPhase, from, to domain.TaskStatus) error
- type RefusalError
Constants ¶
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.
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 ¶
UnknownPhase is the refusal for a phase value outside the enum.
func UnknownStatus ¶
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 ¶
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 ¶
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.