utils

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionIdKey = "actionId"
)

Variables

This section is empty.

Functions

func GenerateId added in v0.0.5

func GenerateId() string

func GetDecendants

func GetDecendants(step *models.Step) (steps []*models.Step)

GetDecendants recursively retrieves the IDs of all child steps for a given step. It handles different types of steps including If, Parallel, ForLoop, and Switch steps.

Parameters:

  • step: A pointer to a models.Step object representing the current step.

Returns:

  • ids: A slice of strings containing the IDs of all child steps.

func GetDecendantsById

func GetDecendantsById(id string, workflow *models.Workflow) (steps []*models.Step)

GetDecendantsById retrieves the IDs of all child steps for a given step ID within a workflow. It first fetches the step by its ID and then retrieves its child steps.

Parameters:

  • id: The ID of the step for which child steps are to be retrieved.
  • workflow: The workflow containing the steps.

Returns:

  • ids: A slice of strings containing the IDs of the child steps.

func GetStepById

func GetStepById(id string, workflow *models.Workflow) *models.Step

GetStepById retrieves a step from the workflow by its ID. It takes an ID as a string and a workflow of type models.Workflow. It returns a pointer to the models.Step that matches the given ID.

func SearchSteps

func SearchSteps(id string, steps []*models.Step) *models.Step

SearchSteps searches for a step with the given id within a slice of steps. It recursively searches through nested steps in Parallel, If, For, and Switch blocks.

Parameters:

  • id: The identifier of the step to search for.
  • steps: A slice of pointers to Step objects to search within.

Returns:

  • A pointer to the Step object with the matching id, or nil if no match is found.

func ValidateInputs

func ValidateInputs(actionSpec *models.ActionSpec, pipeline *data.Pipeline) (valid bool, err error)

ValidateInputs checks if all required inputs specified in the actionSpec are present in the pipeline. It returns a boolean indicating whether the inputs are valid and an error if any required inputs are missing.

Parameters:

  • actionSpec: A pointer to an ActionSpec struct containing the parameters to validate.
  • pipeline: A pointer to a Pipeline struct where the inputs are checked.

Returns:

  • valid: A boolean indicating whether all required inputs are present.
  • err: An error containing details of any missing required inputs, or nil if all inputs are valid.

func ValidateStep

func ValidateStep(step *models.Step) (err error)

ValidateStep validates the configuration of a given step based on its type. It returns an error if any required configuration is missing or invalid.

Parameters:

  • step: A pointer to the Step object to be validated.

Returns:

  • err: An error if the step configuration is invalid, otherwise nil.

Validation rules:

  • For StepTypeAction: The Action field must not be nil.
  • For StepTypeIf: The If field must not be nil, Condition must not be empty, Steps must not be empty, and all sub-steps must be valid. ElseIf and Else blocks, if present, must also be valid.
  • For StepTypeParallel: The Parallel field must not be nil, Steps must not be empty, and all sub-steps must be valid.
  • For StepTypeForLoop: The For field must not be nil, ItemsVar or ItemsArr must be provided, Loopvar or IndexVar must be provided, Steps must not be empty, and all sub-steps must be valid.
  • For StepTypeSwitch: The Switch field must not be nil, Variable must not be empty, Cases must not be empty, and all case blocks must be valid.
  • For any other step type: An error indicating an invalid step type is returned.

func ValidateWorkflow

func ValidateWorkflow(workflow models.Workflow) (err error)

ValidateWorkflow validates the given workflow by checking if it has a name and steps. It returns an error if the workflow is invalid.

Parameters:

  • workflow: The workflow to be validated.

Returns:

  • err: An error if the workflow is invalid, otherwise nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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