imprint 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,17 @@
1
1
  module Imprint
2
2
  module LogHelpers
3
3
 
4
- # Not relying on default rails logging, more often using lograge
5
- # Still want to log incoming params safely, which lograge doesn't include
4
+ # Not relying on default rails logging, we more often use lograge.
5
+ # We still want to log incoming params safely, which lograge doesn't include
6
6
  # this does the same sensative param filtering as rails defaults
7
+ # It also allows for logging headers and cookies
7
8
  def log_entrypoint
8
9
  raise "you must call Imprint.configuration and configure the gem before using LogHelpers" if Imprint.configuration.nil?
9
10
  log_filter = ActionDispatch::Http::ParameterFilter.new(Imprint.configuration[:log_filters] || Rails.application.config.filter_parameters)
11
+ # I should probably switch this to be a whitelist as well, or support both white and black lists for both cookies and headers
10
12
  header_blacklist = Imprint.configuration[:header_blacklist] || []
11
13
  cookies_whitelist = Imprint.configuration[:cookies_whitelist] || []
14
+ param_level = Imprint.configuration[:param_level] || Imprint::QUERY_PARAMS
12
15
 
13
16
  http_request_headers = request.headers.select{|header_name, header_value| header_name.match("^HTTP.*") && !header_blacklist.include?(header_name) }
14
17
  data_append = "headers: "
@@ -19,8 +22,18 @@ module Imprint
19
22
  end
20
23
 
21
24
  data_append << " params: "
22
- log_filter.filter(request.query_parameters).each_pair{|k,v| data_append << " #{k}=\"#{v}\"" }
23
-
25
+ if param_level==Imprint::FULL_PARAMS
26
+ set_full_params(log_filter, data_append)
27
+ elsif param_level==Imprint::FULL_GET_PARAMS
28
+ if request.get?
29
+ set_full_params(log_filter, data_append)
30
+ else
31
+ set_query_params(log_filter, data_append)
32
+ end
33
+ else
34
+ set_query_params(log_filter, data_append)
35
+ end
36
+
24
37
  cookies_whitelist.each do |cookie_key|
25
38
  cookie_val = cookies[cookie_key] ? cookies[cookie_key] : 'nil'
26
39
  data_append << " #{cookie_key}=\"#{cookie_val}\""
@@ -31,5 +44,13 @@ module Imprint
31
44
  logger.error "error logging log_entrypoint for request"
32
45
  end
33
46
 
47
+ def set_full_params(log_filter, data_append)
48
+ log_filter.filter(request.parameters).except('action', 'controller').each_pair{|k,v| data_append << " #{k}=\"#{v}\"" }
49
+ end
50
+
51
+ def set_query_params(log_filter, data_append)
52
+ log_filter.filter(request.query_parameters).each_pair{|k,v| data_append << " #{k}=\"#{v}\"" }
53
+ end
54
+
34
55
  end
35
56
  end
@@ -1,3 +1,3 @@
1
1
  module Imprint
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/imprint.rb CHANGED
@@ -4,6 +4,10 @@ require 'imprint/tracer'
4
4
 
5
5
  module Imprint
6
6
 
7
+ FULL_PARAMS = :full
8
+ QUERY_PARAMS = :query
9
+ FULL_GET_PARAMS = :full_get
10
+
7
11
  class << self
8
12
  attr_accessor :configuration
9
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: 402883591187876401
150
+ hash: -1390655757384157980
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  segments:
158
158
  - 0
159
- hash: 402883591187876401
159
+ hash: -1390655757384157980
160
160
  requirements: []
161
161
  rubyforge_project:
162
162
  rubygems_version: 1.8.23