-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add regex replace functionality to transformation filter extractors [Revised] #309
Conversation
…301) * initial extractor implementation of replace functionality * minor changes, testing against mergeExtractorsToBody and extraction callback * add changelog entry * update API to use new mode selector update transformation_filter proto * minor updates to comments in transformation_filter.proto * remove existing references to no-longer-existing replace_all setting * update replacement_text_ to a std::optional<std::string> * remove duplicate mode enum * update comment indicating that subgroup should never exceed regex_result size * add AttemptReplaceFromNoMatchNonNilSubgroup test * prevent string reallocation * remove unnecessary if block + variable in replaceAllValues * clean up new tests * inline replacement_text in inja_transformer_test.cc * more test cleanup
Issues linked to changelog: |
api/envoy/config/filter/http/transformation/v2/transformation_filter.proto
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
Step #0: Step #0 - "do_ci": �[1mtest/extensions/filters/http/transformation/inja_transformer_test.cc:64:29: �[0m�[0;1;31merror: �[0m�[1mincompatible pointer types assigning to 'const std::unordered_map<std::string, std::string> *' (aka 'const unordered_map<basic_string<char, char_traits, allocator>, basic_string<char, char_traits, allocator>> *') from 'const std::unordered_map<std::string, absl::string_view> *' (aka 'const unordered_map<basic_string<char, char_traits, allocator>, basic_string_view> *')�[0m |
82018da
to
741ea24
Compare
resolved with 741ea24 I had added a switch statement to select different modes of extractor operation, and left out |
source/extensions/filters/http/transformation/inja_transformer.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great!
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.h
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
source/extensions/filters/http/transformation/inja_transformer.cc
Outdated
Show resolved
Hide resolved
api/envoy/config/filter/http/transformation/v2/transformation_filter.proto
Show resolved
Hide resolved
api/envoy/config/filter/http/transformation/v2/transformation_filter.proto
Show resolved
Hide resolved
…Revised] (#309) * Add regex replace functionality to transformation filter extractors (#301) * initial extractor implementation of replace functionality * minor changes, testing against mergeExtractorsToBody and extraction callback * add changelog entry * update API to use new mode selector update transformation_filter proto * minor updates to comments in transformation_filter.proto * remove existing references to no-longer-existing replace_all setting * update replacement_text_ to a std::optional<std::string> * remove duplicate mode enum * update comment indicating that subgroup should never exceed regex_result size * add AttemptReplaceFromNoMatchNonNilSubgroup test * prevent string reallocation * remove unnecessary if block + variable in replaceAllValues * clean up new tests * inline replacement_text in inja_transformer_test.cc * more test cleanup * update function signatures, remove replaced_value_ * support dynamic metadata as extractor input * update changelog location * add API changes to go with 3175ca9 * revert support for dynamic metadata as an extractor input 3175ca9 and e2668be * refactor calls to extract/replace * rename replace to extractDestructive, add breaks to switch statement * update data types to match updated function signatures in inja_transformer_test.cc * respond to review comments * update changelog location * update changelog location * separate destructive extractors and non-destructive extractors * fix match_not_null edge case * update inline documentation for new proto field * add test demonstrating use of format specifiers * update REPLACE_ALL mode to return input on no match * return input on no match in single replace case
…Revised] (#309) * Add regex replace functionality to transformation filter extractors (#301) * initial extractor implementation of replace functionality * minor changes, testing against mergeExtractorsToBody and extraction callback * add changelog entry * update API to use new mode selector update transformation_filter proto * minor updates to comments in transformation_filter.proto * remove existing references to no-longer-existing replace_all setting * update replacement_text_ to a std::optional<std::string> * remove duplicate mode enum * update comment indicating that subgroup should never exceed regex_result size * add AttemptReplaceFromNoMatchNonNilSubgroup test * prevent string reallocation * remove unnecessary if block + variable in replaceAllValues * clean up new tests * inline replacement_text in inja_transformer_test.cc * more test cleanup * update function signatures, remove replaced_value_ * support dynamic metadata as extractor input * update changelog location * add API changes to go with 3175ca9 * revert support for dynamic metadata as an extractor input 3175ca9 and e2668be * refactor calls to extract/replace * rename replace to extractDestructive, add breaks to switch statement * update data types to match updated function signatures in inja_transformer_test.cc * respond to review comments * update changelog location * update changelog location * separate destructive extractors and non-destructive extractors * fix match_not_null edge case * update inline documentation for new proto field * add test demonstrating use of format specifiers * update REPLACE_ALL mode to return input on no match * return input on no match in single replace case
* Add regex replace functionality to transformation filter extractors [Revised] (#309) * Add regex replace functionality to transformation filter extractors (#301) * initial extractor implementation of replace functionality * minor changes, testing against mergeExtractorsToBody and extraction callback * add changelog entry * update API to use new mode selector update transformation_filter proto * minor updates to comments in transformation_filter.proto * remove existing references to no-longer-existing replace_all setting * update replacement_text_ to a std::optional<std::string> * remove duplicate mode enum * update comment indicating that subgroup should never exceed regex_result size * add AttemptReplaceFromNoMatchNonNilSubgroup test * prevent string reallocation * remove unnecessary if block + variable in replaceAllValues * clean up new tests * inline replacement_text in inja_transformer_test.cc * more test cleanup * update function signatures, remove replaced_value_ * support dynamic metadata as extractor input * update changelog location * add API changes to go with 3175ca9 * revert support for dynamic metadata as an extractor input 3175ca9 and e2668be * refactor calls to extract/replace * rename replace to extractDestructive, add breaks to switch statement * update data types to match updated function signatures in inja_transformer_test.cc * respond to review comments * update changelog location * update changelog location * separate destructive extractors and non-destructive extractors * fix match_not_null edge case * update inline documentation for new proto field * add test demonstrating use of format specifiers * update REPLACE_ALL mode to return input on no match * return input on no match in single replace case * update changelog location
* Add regex replace functionality to transformation filter extractors [Revised] (#309) * Add regex replace functionality to transformation filter extractors (#301) * initial extractor implementation of replace functionality * minor changes, testing against mergeExtractorsToBody and extraction callback * add changelog entry * update API to use new mode selector update transformation_filter proto * minor updates to comments in transformation_filter.proto * remove existing references to no-longer-existing replace_all setting * update replacement_text_ to a std::optional<std::string> * remove duplicate mode enum * update comment indicating that subgroup should never exceed regex_result size * add AttemptReplaceFromNoMatchNonNilSubgroup test * prevent string reallocation * remove unnecessary if block + variable in replaceAllValues * clean up new tests * inline replacement_text in inja_transformer_test.cc * more test cleanup * update function signatures, remove replaced_value_ * support dynamic metadata as extractor input * update changelog location * add API changes to go with 3175ca9 * revert support for dynamic metadata as an extractor input 3175ca9 and e2668be * refactor calls to extract/replace * rename replace to extractDestructive, add breaks to switch statement * update data types to match updated function signatures in inja_transformer_test.cc * respond to review comments * update changelog location * update changelog location * separate destructive extractors and non-destructive extractors * fix match_not_null edge case * update inline documentation for new proto field * add test demonstrating use of format specifiers * update REPLACE_ALL mode to return input on no match * return input on no match in single replace case * update changelog * empty commit to kick changelog bot after switching target branch
Description
RE2
as a supported regex engine in addition to C++std::regex
This has been added with this PRstd::string
values, instead ofabsl::string_view
API Changes
Extraction
(see Gloo Edge docs here) message has been updated to include 3 new fields:mode
SINGLE_REPLACE
andREPLACE_ALL
modesenvoy-gloo/api/envoy/config/filter/http/transformation/v2/transformation_filter.proto
Lines 157 to 168 in e2668be
replacement_text
SINGLE_REPLACE
orREPLACE_ALL
modes are selected, the content matching the extractor's regex will be replaced with the value inreplacement_text
source.dynamic_metadata
adynamic_metadata
field has been added to thesource
oneof, which specifies the source of the extraction. This value contains a key, the value of which in dynamic metadata will be provided to the extractor as inputFeature Overview
SINGLE_REPLACE
andREPLACE_ALL
modesSINGLE_REPLACE
mode, regex semantics are the same as withEXTRACT
mode, i.e., the previous and now default extractor behavior. Users specify a regex that must match the entire input, and the content in the specified capture group is replaced with a configured string value (replacement_text
)REPLACE_ALL
mode, the regex is allowed to match the input multiple times. All matches are replaced by a configured string value (replacement_text
)