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

Allow regexp on params filter #131

Open
sobrinho opened this issue Jan 31, 2023 · 2 comments
Open

Allow regexp on params filter #131

sobrinho opened this issue Jan 31, 2023 · 2 comments

Comments

@sobrinho
Copy link
Contributor

Regexps are more powerful:

HttpLog.configure do |config|
  config.filter_parameters = (
    /date_?of_?birth|dob/
  )
end

module HttpLog
  class << self
    def masked_data(msg)
      case msg
      when Hash
        Hash[msg.map { |key, value| [key, mask?(key) ? PARAM_MASK : masked_data(value)] }]
      when Array
        msg.map { |element| masked_data(element) }
      else
        msg
      end
    end

    # this is slow but not a hotpath, all regexps and strings could be compiled into one regexp.
    def mask?(key)
      config.filter_parameters.any? do |filter_parameter|
        if filter_parameter.is_a?(Regexp)
          key =~ filter_parameter
        else
          key.downcase == filter_parameter
        end
      end
    end
  end
end
@trusche
Copy link
Owner

trusche commented May 11, 2023

Same thing, PRs welcome!

@sobrinho
Copy link
Contributor Author

Will do!

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

No branches or pull requests

2 participants