diff options
author | Prem Sichanugrist <s@sikachu.com> | 2010-01-21 04:37:10 +0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-21 10:08:26 +0100 |
commit | bd4f21fbac495fb28b6be993be808509e567239e (patch) | |
tree | facad12a926cd08f40ebf97da6d336cb8e03e6d9 /actionpack/lib/action_controller/metal/filter_parameter_logging.rb | |
parent | fa9f000246c2f6010f18bf40237d105b782873e2 (diff) | |
download | rails-bd4f21fbac495fb28b6be993be808509e567239e.tar.gz rails-bd4f21fbac495fb28b6be993be808509e567239e.tar.bz2 rails-bd4f21fbac495fb28b6be993be808509e567239e.zip |
Move filter_parameter_logging logic out of the controller and create ActionDispatch::ParametersFilter to handle parameter filteration instead. This will make filteration not depending on controller anymore.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_controller/metal/filter_parameter_logging.rb')
-rw-r--r-- | actionpack/lib/action_controller/metal/filter_parameter_logging.rb | 36 |
1 files changed, 4 insertions, 32 deletions
diff --git a/actionpack/lib/action_controller/metal/filter_parameter_logging.rb b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb index 9e03f50759..befb4a58cc 100644 --- a/actionpack/lib/action_controller/metal/filter_parameter_logging.rb +++ b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb @@ -2,8 +2,6 @@ module ActionController module FilterParameterLogging extend ActiveSupport::Concern - INTERNAL_PARAMS = %w(controller action format _method only_path) - module ClassMethods # Replace sensitive parameter data from the request log. # Filters parameters that have any of the arguments as a substring. @@ -27,40 +25,14 @@ module ActionController # => reverses the value to all keys matching /secret/i, and # replaces the value to all keys matching /foo|bar/i with "[FILTERED]" def filter_parameter_logging(*filter_words, &block) - raise "You must filter at least one word from logging" if filter_words.empty? - - parameter_filter = Regexp.new(filter_words.join('|'), true) - - define_method(:filter_parameters) do |original_params| - filtered_params = {} - - original_params.each do |key, value| - if key =~ parameter_filter - value = '[FILTERED]' - elsif value.is_a?(Hash) - value = filter_parameters(value) - elsif value.is_a?(Array) - value = value.map { |item| filter_parameters(item) } - elsif block_given? - key = key.dup - value = value.dup if value.duplicable? - yield key, value - end - - filtered_params[key] = value - end - - filtered_params.except!(*INTERNAL_PARAMS) - end - protected :filter_parameters + ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words, &block) end end - + protected - + def filter_parameters(params) - params.dup.except!(*INTERNAL_PARAMS) + request.send(:process_parameter_filter, params) end - end end |