-
Notifications
You must be signed in to change notification settings - Fork 264
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 feature in JsonBodyFilters to replace value by custom function. #855
Add feature in JsonBodyFilters to replace value by custom function. #855
Conversation
I'd prefer an easier change:
|
In other words, make the current default implementation (string replacement) a special case of the new default implementation (function-based replacement). |
I actually had implemented it that way initially. The issue with that is it will break the BodyFilter merge functionality. Because it will become a bit complicated to compare replacement function instead of replacement string: public boolean compatibleWith(final PrimitiveJsonPropertyBodyFilter that) { |
That works if you have a non-anonymous function. So instead of my suggestion from above ( @AllArgsConstructor
private static final class StaticReplacement implements BinaryOperator<String> {
private final String replacement;
// TODO apply
// TODO equals/hashCode
} |
d80836c
to
e582f8b
Compare
Thanks for the feedback. I hadn't thought of that. I have updated the PR with the changes. |
logbook-json/src/main/java/org/zalando/logbook/json/PrimitiveJsonPropertyBodyFilter.java
Outdated
Show resolved
Hide resolved
logbook-json/src/main/java/org/zalando/logbook/json/StaticParameterReplacementOperator.java
Outdated
Show resolved
Hide resolved
logbook-json/src/main/java/org/zalando/logbook/json/StaticParameterReplacementOperator.java
Outdated
Show resolved
Hide resolved
logbook-json/src/main/java/org/zalando/logbook/json/StringFunctionReplacementOperator.java
Outdated
Show resolved
Hide resolved
logbook-json/src/main/java/org/zalando/logbook/json/JsonBodyFilters.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
static BodyFilter replacePrimitive( | ||
final Predicate<String> predicate, final String replacement) { | ||
return create(PRIMITIVE, predicate, quote(replacement)); |
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.
Interesting. I didn't realize that we always quoted here. Means there is no way to replace booleans and numbers because they will become strings.
Looks good. Let me fix the issue in the master first. Might take a couple of days. |
|
||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
final class QuotedStringReplacementOperator<T> implements BinaryOperator<String> { |
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.
There is no need for this class to be generic, is there?
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.
Yeah. Not in current use cases, I guess. It can be removed if you want.
|
||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
final class StaticParameterReplacementOperator<T> implements BinaryOperator<String> { |
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.
Same here. T
is always String
, no need to be generic.
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.
Not in this case. It could be number or boolean. Or I guess, it can be passed as string through constructor.
If you rebase onto main, then I can fix the final review comments myself before releasing. |
f4c4ced
to
e72cfba
Compare
I rebased it with main. |
👍 |
Summary:
Currently Json Body filters obfusicate the property values with a replacement string. eg. "XXX". However, users may want to do a custom obfusication of these values for eg. Hash of the given value. In order to make it extensible, add a function in JSonBodyFilter to convert a primitive JSON using a custom function provided by the user.
Description:
The following changes are made:
Motivation and Context
Adds extension to help users create a custom filter function.
Fixes #851
#755
Types of changes
Checklist: