Skip to content

Commit

Permalink
Fix Bug on Events Configuration Equal function
Browse files Browse the repository at this point in the history
If Config.Events was nil, it would cause an null pointer exception
  • Loading branch information
cesnietor committed Dec 16, 2020
1 parent 3316e6a commit 0224f9a
Show file tree
Hide file tree
Showing 2 changed files with 580 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,28 @@ func EqualFilterRuleList(a, b []FilterRule) bool {

// Equal returns whether this `Config` is equal to another defined by the passed parameters
func (t *Config) Equal(events []EventType, prefix, suffix string) bool {
//Compare events
if t == nil {
return false
}

// Compare events
passEvents := EqualEventTypeList(t.Events, events)

//Compare filters
var newFilter []FilterRule
// Compare filters
var newFilterRules []FilterRule
if prefix != "" {
newFilter = append(newFilter, FilterRule{Name: "prefix", Value: prefix})
newFilterRules = append(newFilterRules, FilterRule{Name: "prefix", Value: prefix})
}
if suffix != "" {
newFilter = append(newFilter, FilterRule{Name: "suffix", Value: suffix})
newFilterRules = append(newFilterRules, FilterRule{Name: "suffix", Value: suffix})
}

var currentFilterRules []FilterRule
if t.Filter != nil {
currentFilterRules = t.Filter.S3Key.FilterRules
}

passFilters := EqualFilterRuleList(t.Filter.S3Key.FilterRules, newFilter)
// if it matches events and filters, mark the index for deletion
passFilters := EqualFilterRuleList(currentFilterRules, newFilterRules)
return passEvents && passFilters
}

Expand Down
Loading

0 comments on commit 0224f9a

Please sign in to comment.