Skip to content

Commit

Permalink
Moved to condition
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartendeKruijf committed May 3, 2024
1 parent db99c7e commit 64bd0b7
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ifcondition
package condition

import (
"errors"
Expand All @@ -7,6 +7,7 @@ import (
"soarca/logger"
"soarca/models/cacao"
"soarca/models/execution"
"soarca/utils/stix"
)

var component = reflect.TypeOf(Executor{}).PkgPath()
Expand All @@ -24,19 +25,37 @@ func New(capabilities map[string]capability.ICapability) *Executor {

type IExecuter interface {
Execute(metadata execution.Metadata,
step cacao.Step) (string, error)
step cacao.Step) (string, bool, error)
}

type Executor struct {
capabilities map[string]capability.ICapability
}

func (executor *Executor) Execute(meta execution.Metadata, step cacao.Step) (string, error) {
func (executor *Executor) Execute(meta execution.Metadata, step cacao.Step) (string, bool, error) {

if step.Type != cacao.StepTypeIfCondition {
err := errors.New("the provided step type is not compatible with this executor")
log.Error(err)
return step.OnFailure, err
return step.OnFailure, false, err
}
return "", nil

result, err := stix.Evaluate(step.Condition, step.StepVariables)
if err != nil {
log.Error(err)
return "", false, err
}

if result {
if step.OnTrue != "" {
log.Trace("")
return step.OnTrue, true, nil
}
} else {
if step.OnFalse != "" {
return step.OnFalse, true, nil
}
}

return step.OnCompletion, false, nil
}

0 comments on commit 64bd0b7

Please sign in to comment.