workflow

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEventActor         = errors.New("invalid event actor")
	ErrInsufficientApproverCount = errors.New("insufficient approvers to transition to next state")
	ErrApproverNoLongerEligible  = errors.New("approver is no longer in the admin group and has not voted yet")
	ErrTransitionExecution       = errors.New("failed to execute transition")
	ErrWorkflowExecution         = errors.New("failed to execute workflow action")
	ErrUpdateWorkflowState       = errors.New("failed to update workflow state")
	ErrCheckApprovers            = errors.New("failed to check approvers")
	ErrAutomatedTransition       = errors.New(
		"automated transition cannot be triggered by user input",
	)
	ErrInvalidWorkflowState              = errors.New("invalid workflow state")
	ErrInvalidWorkflowType               = errors.New("invalid workflow type")
	ErrCheckApproverDecision             = errors.New("failed to check approver decision")
	ErrListApprovers                     = errors.New("failed to list approvers")
	ErrInvalidVotingTransition           = errors.New("invalid voting transition")
	ErrWorkflowGroupNotSufficientMembers = errors.New("insufficient eligible approvers in admin group")
	ErrUserRemovedFromApproverGroup      = errors.New("user is no longer a member of the workflow approver groups")
)

Functions

func GetApproverUserNames

func GetApproverUserNames(
	ctx context.Context,
	approvers []model.WorkflowApprover,
	idm identitymanagement.IdentityManagement,
) ([]string, error)

func GetNotificationRecipients

func GetNotificationRecipients(
	ctx context.Context,
	workflow model.Workflow,
	transition Transition,
	idm identitymanagement.IdentityManagement,
) ([]string, error)

GetNotificationRecipients returns the usernames to notify for a workflow transition.

func NewApproverNoLongerEligibleError added in v0.9.0

func NewApproverNoLongerEligibleError(userID string) error

NewApproverNoLongerEligibleError creates an error when an approver is no longer in the admin group and has not voted yet.

func NewInsufficientApproverCountError

func NewInsufficientApproverCountError(currentCount, requiredCount int) error

NewInsufficientApproverCountError creates an error when there are not enough approvers to transition to the next state.

func NewInsufficientApproversError added in v0.9.0

func NewInsufficientApproversError(required, actual int) error

NewInsufficientApproversError creates a structured error with approver counts

func NewInvalidEventActorError

func NewInvalidEventActorError(userID string, expectedRole string) error

NewInvalidEventActorError creates an error when the user is not the expected actor of the event.

func NewTransitionError

func NewTransitionError(transition Transition) error

NewTransitionError creates an error when a transition fails.

Types

type ApprovalMechanism

type ApprovalMechanism string
const (
	ApprovalMechanismTargetScore ApprovalMechanism = "TARGET_SCORE"
)

type ApprovalSummary

type ApprovalSummary struct {
	Mechanism   ApprovalMechanism
	Approvals   int
	Rejections  int
	Pending     int
	TargetScore int
}

type InsufficientApproversError added in v0.9.0

type InsufficientApproversError struct {
	Required int
	Actual   int
}

InsufficientApproversError is a structured error that carries approver count context

func (*InsufficientApproversError) Error added in v0.9.0

func (*InsufficientApproversError) Unwrap added in v0.9.0

func (e *InsufficientApproversError) Unwrap() error

type KeyActions

type KeyActions interface {
	UpdateKey(
		ctx context.Context,
		keyID uuid.UUID,
		keyPatch cmkapi.KeyPatch,
	) (*model.Key, error)
	Delete(ctx context.Context, keyID uuid.UUID) error
	Get(ctx context.Context, keyID uuid.UUID) (*model.Key, error)
}

type KeyConfigurationActions

type KeyConfigurationActions interface {
	DeleteKeyConfigurationByID(ctx context.Context, keyConfigID uuid.UUID) error
	UpdateKeyConfigurationByID(
		ctx context.Context,
		keyConfigID uuid.UUID,
		patchKeyConfig cmkapi.KeyConfigurationPatch,
	) (*model.KeyConfiguration, error)
}

type Lifecycle

type Lifecycle struct {
	Workflow                *model.Workflow
	StateMachine            *fsm.FSM
	ActorID                 string
	Repository              repo.Repo
	KeyActions              KeyActions
	KeyConfigurationActions KeyConfigurationActions
	SystemActions           SystemActions
	MinimumApproverCount    int
	EligibleApproverIDs     map[string]bool // Optional: if set, only these approvers count for voting
	ActorApproverGroupIDs   []uuid.UUID     // Optional: if set, validates actor is still in approver groups
}

func NewLifecycle

func NewLifecycle(workflow *model.Workflow,
	keyActions KeyActions,
	keyConfigurationActions KeyConfigurationActions,
	systemActions SystemActions,
	repo repo.Repo,
	actorID string,
	minimumApproverCount int,
) *Lifecycle

NewLifecycle creates a new Lifecycle object for the given workflow with a state machine that defines the possible transitions.

func (*Lifecycle) ApplyTransition

func (l *Lifecycle) ApplyTransition(ctx context.Context, transition Transition) error

ApplyTransition applies a transition without actor validation. Use only when the caller has already established authority through other means and actor validation must be skipped (e.g. auto-reject after vote).

func (*Lifecycle) AvailableBusinessUserTransitions

func (l *Lifecycle) AvailableBusinessUserTransitions(ctx context.Context) []Transition

AvailableBusinessUserTransitions returns the list of transitions that can be performed by business users (i.e., non-automated transitions) after the creation of the workflow.

func (*Lifecycle) CanExpire added in v0.9.0

func (l *Lifecycle) CanExpire() bool

func (*Lifecycle) CanTransition

func (l *Lifecycle) CanTransition(transition Transition) bool

CanTransition checks if the workflow can transition to the given state

func (*Lifecycle) CheckInsufficientApprovers added in v0.9.0

func (l *Lifecycle) CheckInsufficientApprovers(
	eligibleApprovers []*model.WorkflowApprover,
) bool

CheckInsufficientApprovers determines if eligible approvers can meet threshold. Takes pre-fetched eligible list (no external calls) - pure business logic.

func (*Lifecycle) Expire

func (l *Lifecycle) Expire(ctx context.Context) error

Expire triggers to EXPIRED state

func (*Lifecycle) GetAllApprovers added in v0.9.0

func (l *Lifecycle) GetAllApprovers(ctx context.Context) ([]*model.WorkflowApprover, error)

func (*Lifecycle) GetApprovalSummary

func (l *Lifecycle) GetApprovalSummary(ctx context.Context) (*ApprovalSummary, error)

func (*Lifecycle) ValidateActor

func (l *Lifecycle) ValidateActor(ctx context.Context, transition Transition) error

ValidateActor validates the actor of the event

func (*Lifecycle) ValidateAndApplyTransition added in v0.9.0

func (l *Lifecycle) ValidateAndApplyTransition(ctx context.Context, transition Transition) error

ValidateAndApplyTransition wraps the execution of a transition in the state machine triggered by user input

type ParametersResourceType

type ParametersResourceType string

ParametersResourceType is stored as an opaque varchar.

const (
	ParametersResourceTypeKey              ParametersResourceType = "KEY"
	ParametersResourceTypeKeyConfiguration ParametersResourceType = "KEY_CONFIGURATION"
)

func (ParametersResourceType) String

func (t ParametersResourceType) String() string

type SystemActions

type SystemActions interface {
	LinkSystemAction(ctx context.Context, systemID uuid.UUID, patchSystem cmkapi.SystemPatch) (*model.System, error)
	UnlinkSystemAction(ctx context.Context, systemID uuid.UUID, trigger string) error
}

type Transition

type Transition string

Transition is a state-machine event name.

const (
	TransitionCreate  Transition = "CREATE"
	TransitionRevoke  Transition = "REVOKE"
	TransitionReject  Transition = "REJECT"
	TransitionExpire  Transition = "EXPIRE"
	TransitionApprove Transition = "APPROVE"
	TransitionConfirm Transition = "CONFIRM"
	TransitionExecute Transition = "EXECUTE"
	TransitionFail    Transition = "FAIL"
)

func (Transition) String

func (t Transition) String() string

Jump to

Keyboard shortcuts

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