-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
plugins/logs: Fixes unintended mutation of result #2808
plugins/logs: Fixes unintended mutation of result #2808
Conversation
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.
@gshively11 thanks for submitting this! Left a few comments on the implementation.
Let me know if that |
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.
Just one comment about adding some test coverage for the deep copy utility. Other than that, LGTM.
// DeepCopy performs a recursive deep copy for nested slices/maps and | ||
// returns the copied object. Supports []interface{} | ||
// and map[string]interface{} only | ||
func DeepCopy(val interface{}) interface{} { |
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.
nit: I'd add some test coverage here now that this is exposed for re-use within the rest of OPA.
@@ -254,20 +261,20 @@ func (r maskRule) mkdirp(node map[string]interface{}, path []string, value inter | |||
return nil | |||
} | |||
|
|||
func resultValueToMaskRules(rv interface{}) ([]*maskRule, error) { | |||
|
|||
func newMaskRuleSet(rv interface{}, onRuleError func(*maskRule, error)) (*maskRuleSet, error) { |
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.
onRuleError
looks fine to me; definitely better than creating a cyclic dependency or adding logging into the mask.go file.
I spent a while trying to make something that could recursively compare the reference of the deep copy target/result, but I just don't have enough golang experience to pull that off, so I just went with this more simplistic mutation test, hope that's ok. |
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. @gshively11 can you squash your commits? Once that's done we can merge this.
When mask rules targeted /result, it was modifying both the result in the decision logs (intended) and the result in the API response (unintended). Added a step to deep copy the result only once, if there is at least one mask rule targeting the result. Fixes #2752 Signed-off-by: Grant Shively <[email protected]>
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
When mask rules targeted /result, it was modifying both the result
in the decision logs (intended) and the result in the API
response (unintended). Added a step to deep copy the result only once, if
there is at least one mask rule targeting the result.
Fixes #2752
Signed-off-by: Grant Shively [email protected]