Skip to content
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

Refactor redactor into replacer #2277

Merged
merged 1 commit into from
Aug 9, 2023
Merged

Refactor redactor into replacer #2277

merged 1 commit into from
Aug 9, 2023

Conversation

DrJosh9000
Copy link
Contributor

@DrJosh9000 DrJosh9000 commented Aug 8, 2023

This changes redactor into replacer. A summary:

  1. The minimum redaction length, ValuesToRedact, and VarsToRedact are moved into a new package, redact
  2. The Redactor and necessary friends are renamed and moved into replacer.
  3. pipeline_upload.go is changed to use a Replacer to search through the JSON in a streaming manner.
  4. The implementation of flushUpTo is changed to call a callback when processing matches instead of using a fixed []byte.
  5. flushUpTo also no longer eagerly flushes into the middle of matches.
  6. Basically everything else is mechanical.

if _, err := r.dst.Write(r.subst); err != nil {
// Now handle the match itself.
// Call the replacement callback to get a replacement.
if repl := r.replacement(r.buf[match.from:match.to]); len(repl) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "replace the thing matched with an empty string" (ie delete the matched string) a valid use case? i can see the semantics there being a little confusing if the user tried to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be supported - replacement should return nil. The if on this line is just to skip calling r.dst.Write with nil or empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet as

@DrJosh9000
Copy link
Contributor Author

DrJosh9000 commented Aug 8, 2023

I'm going to add some more tests, since there is 0 coverage in most of clicommand.

Edit: Done.

Copy link
Contributor

@triarius triarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I think I know how to use this now.

@DrJosh9000 DrJosh9000 merged commit 1e12ec2 into main Aug 9, 2023
@DrJosh9000 DrJosh9000 deleted the redactor-refactor branch August 9, 2023 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants