Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ pkg/protocols/headless/engine/.cache
/bindgen
/jsdocgen
/scrapefuncs
/extracted
24 changes: 23 additions & 1 deletion pkg/operators/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,14 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc
outputUnique: make(map[string]struct{}),
}

// state variable to check if all extractors are internal
var allInternalExtractors bool = true

// Start with the extractors first and evaluate them.
for _, extractor := range operators.Extractors {
if !extractor.Internal && allInternalExtractors {
allInternalExtractors = false
}
var extractorResults []string
for match := range extract(data, extractor) {
extractorResults = append(extractorResults, match)
Expand All @@ -241,6 +247,10 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc
if len(extractorResults) > 0 && !extractor.Internal && extractor.Name != "" {
result.Extracts[extractor.Name] = extractorResults
}
// update data with whatever was extracted doesn't matter if it is internal or not (skip unless it empty)
if len(extractorResults) > 0 {
data[extractor.Name] = getExtractedValue(extractorResults)
}
}

// expose dynamic values to same request matchers
Expand Down Expand Up @@ -288,7 +298,9 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc

result.Matched = matches
result.Extracted = len(result.OutputExtracts) > 0
if len(result.DynamicValues) > 0 {
if len(result.DynamicValues) > 0 && allInternalExtractors {
// only return early if all extractors are internal
// if some are internal and some are not then followthrough
return result, true
}

Expand Down Expand Up @@ -339,3 +351,13 @@ func (operators *Operators) IsEmpty() bool {
func (operators *Operators) Len() int {
return len(operators.Matchers) + len(operators.Extractors)
}

// getExtractedValue takes array of extracted values if it only has one value
// then it is flattened and returned as a string else original type is returned
func getExtractedValue(values []string) any {
if len(values) == 1 {
return values[0]
} else {
return values
}
}
8 changes: 8 additions & 0 deletions pkg/protocols/common/helpers/eventcreator/eventcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ func CreateEventWithAdditionalOptions(request protocols.Request, outputEvent out
if compiledOperator != nil {
result, ok := compiledOperator.Execute(outputEvent, request.Match, request.Extract, isResponseDebug)
if ok && result != nil {
// if result has both extracted values and dynamic values, put dynamic values in data
// and remove dynamic values to avoid skipping legitimate event
if (len(result.Extracts) > 0 || len(result.OutputExtracts) > 0) && len(result.DynamicValues) > 0 {
for k, v := range result.DynamicValues {
event.InternalEvent[k] = v
}
result.DynamicValues = nil
}
event.OperatorsResult = result
if addAdditionalOptions != nil {
addAdditionalOptions(event)
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions pkg/protocols/http/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

// Match matches a generic data response again a given matcher
// TODO: Try to consolidate this in protocols.MakeDefaultMatchFunc to avoid any inconsistencies
func (request *Request) Match(data map[string]interface{}, matcher *matchers.Matcher) (bool, []string) {
item, ok := request.getMatchPart(matcher.Part, data)
if !ok && matcher.Type.MatcherType != matchers.DSLMatcher {
Expand Down