workflow

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateInitial          State = "INITIAL"
	StateRevoked          State = "REVOKED"
	StateRejected         State = "REJECTED"
	StateExpired          State = "EXPIRED"
	StateWaitApproval     State = "WAIT_APPROVAL"
	StateWaitConfirmation State = "WAIT_CONFIRMATION"
	StateExecuting        State = "EXECUTING"
	StateSuccessful       State = "SUCCESSFUL"
	StateFailed           State = "FAILED"

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

	ArtifactTypeKey              ArtifactType = "KEY"
	ArtifactTypeKeyConfiguration ArtifactType = "KEY_CONFIGURATION"
	ArtifactTypeSystem           ArtifactType = "SYSTEM"

	ParametersResourceTypeKey              ParametersResourceType = "KEY"
	ParametersResourceTypeKeyConfiguration ParametersResourceType = "KEY_CONFIGURATION"

	ActionTypeUpdateState   ActionType = "UPDATE_STATE"
	ActionTypeUpdatePrimary ActionType = "UPDATE_PRIMARY"
	ActionTypeLink          ActionType = "LINK"
	ActionTypeUnlink        ActionType = "UNLINK"
	ActionTypeSwitch        ActionType = "SWITCH"
	ActionTypeDelete        ActionType = "DELETE"
)

Variables

View Source
var (
	ErrInvalidEventActor         = errors.New("invalid event actor")
	ErrInsufficientApproverCount = errors.New("insufficient approvers to transition to next state")
	ErrTransitionExecution       = errors.New("failed to execute transition")
	ErrWorkflowExecution         = errors.New("failed to execute workflow action")
	ErrUpdateWorkflowState       = errors.New("fialed 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")
)
View Source
var NonTerminalStates = []string{
	StateInitial.String(),
	StateWaitApproval.String(),
	StateWaitConfirmation.String(),
	StateExecuting.String(),
}
View Source
var SystemUserID = SystemUserUUID.String()
View Source
var SystemUserUUID = uuid.Max
View Source
var TerminalStates = []string{
	StateRevoked.String(),
	StateRejected.String(),
	StateExpired.String(),
	StateSuccessful.String(),
	StateFailed.String(),
}

Functions

func GetApproverUserNames

func GetApproverUserNames(approvers []model.WorkflowApprover) []string

func GetNotificationRecipients

func GetNotificationRecipients(workflow model.Workflow, transition Transition) []string

GetNotificationRecipients returns the usernames to notify for a workflow transition.

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 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 ActionType

type ActionType string

ActionType represents the type of the action that the workflow is performing.

func (ActionType) String

func (t ActionType) String() string

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 ArtifactType

type ArtifactType string

ArtifactType represents the type of the artifact that the workflow is acting on.

func (ArtifactType) String

func (t ArtifactType) String() string

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
}

type Lifecycle

type Lifecycle struct {
	Workflow                *model.Workflow
	StateMachine            *fsm.FSM
	ActorID                 string
	Repository              repo.Repo
	KeyActions              KeyActions
	KeyConfigurationActions KeyConfigurationActions
	SystemActions           SystemActions
	MinimumApproverCount    int
}

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 wraps the execution of a transition in the state machine triggered by user input

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) CanTransition

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

CanTransition checks if the workflow can transition to the given state

func (*Lifecycle) Expire

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

Expire triggers to EXPIRED state

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

type ParametersResourceType

type ParametersResourceType string

ParametersResourceType represents the type of the resource that is referenced in the workflow parameters.

func (ParametersResourceType) String

func (t ParametersResourceType) String() string

type State

type State string

State represents the state of a workflow in the state-machine.

func (State) String

func (s State) 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) error
}

type Transition

type Transition string

Transition represents the transition of a workflow in the state-machine.

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