Skip to content

Commit

Permalink
Make closer to suffix filter
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 committed Sep 28, 2023
1 parent d5395a6 commit 8331495
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pkg/eventfilter/subscriptionsapi/prefix_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ func (filter *prefixFilter) Filter(ctx context.Context, event cloudevents.Event)
if filter == nil {
return eventfilter.NoFilter
}
result := eventfilter.NoFilter
logger := logging.FromContext(ctx)
logger.Debugw("Performing a prefix match ", zap.Any("filters", filter.filters), zap.Any("event", event))
for k, v := range filter.filters {
if k == "" || v == "" {
continue
}
value, ok := attributes.LookupAttribute(event, k)
if !ok {
logger.Debugw("Couldn't find attribute in event. Prefix match failed.", zap.String("attribute", k), zap.String("prefix", v),
Expand All @@ -67,13 +63,11 @@ func (filter *prefixFilter) Filter(ctx context.Context, event cloudevents.Event)
if s, ok = value.(string); !ok {
s = fmt.Sprintf("%v", value)
}
if strings.HasPrefix(s, v) {
result = eventfilter.PassFilter
} else {
if !strings.HasPrefix(s, v) {
return eventfilter.FailFilter
}
}
return result
return eventfilter.PassFilter
}

func (filter *prefixFilter) Cleanup() {}

0 comments on commit 8331495

Please sign in to comment.