-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forwarder): add
SourceObjectKeys
(#308)
This commit adds the ability to specify a set of patterns which identify object keys we are willing to forward. A new parameter, `SourceObjectKeys`, allows specifying a set of key patterns against which incoming objects are filtered. We also use this parameter to further constrict our eventbridge pattern for triggering the lambda function.
- Loading branch information
Showing
9 changed files
with
178 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package forwarder | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
var globOperators = regexp.MustCompile(`(\*|\?)`) | ||
|
||
// ObjectFilter verifies if object is intended for processing | ||
type ObjectFilter struct { | ||
filters []*regexp.Regexp | ||
} | ||
|
||
// Allow verifies if object source should be accessed | ||
func (o *ObjectFilter) Allow(source string) bool { | ||
for _, re := range o.filters { | ||
if re.MatchString(source) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// NewObjectFilter initializes an ObjectFilter. | ||
// This function will error if any bucket or object pattern are not valid glob expressions. | ||
func NewObjectFilter(names, keys []string) (*ObjectFilter, error) { | ||
var obj ObjectFilter | ||
// TODO: for simplicity we compute the cross product of regular expressions. It | ||
// would be more efficient to verify buckets and object key separately, but | ||
// we don't expect either list to be very long. | ||
|
||
for _, name := range names { | ||
for _, key := range keys { | ||
source := name + "/" + key | ||
re, err := regexp.Compile(globOperators.ReplaceAllString(source, ".$1")) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to compile %s: %w", source, err) | ||
} | ||
obj.filters = append(obj.filters, re) | ||
} | ||
} | ||
return &obj, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.