failbot 2.0.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f668202c2f67a5b46e2ab742f00f173e58f8f4d
4
- data.tar.gz: 3ca18fe7d1d48e8bea33a91c8e2037e78bba2e1b
3
+ metadata.gz: e8f7925c230c8a2bb881cc98d04f0fbc0af41406
4
+ data.tar.gz: 4f2645f74f1599a3e28be1b336c483ca53d46ff0
5
5
  SHA512:
6
- metadata.gz: 55fa453972efb9dbd6d5703e1f45eeef5d2235f3778cbf56041a3ba6f7dd62650764d9505f63ce190789aafeada5a353da7b48a49e7c3b8255cd79c4b541cdb4
7
- data.tar.gz: 63baf5464539e8fb6639ceb625a3d0cdd2dcc25291c7b273eb0948b190479b9362430086e40ded78e0ac0c9e1390ed953d36322ce239a50eb2a34ba35d066ea8
6
+ metadata.gz: f212fdec123d2cabdf55b2e772e0df63e9fdb454b8aab68de06f47c46c7c1cb7cf6bdf9106dee5235e065e813cbf83b45e0cc2f28c1d583ed8bd02285bb8f968
7
+ data.tar.gz: c0272fd6b9275406eea6d403866e38e3755600985c22fffd772f8ec846311165c43a9fc608122541212049bc078fda7166a91f0fe9a5f52b6654f73026ca71d6
@@ -8,6 +8,7 @@ require "uri"
8
8
 
9
9
  require 'failbot/version'
10
10
  require "failbot/compat"
11
+ require "failbot/sensitive_data_scrubber"
11
12
 
12
13
  # Failbot asynchronously takes exceptions and reports them to the
13
14
  # exception logger du jour. Keeps the main app from failing or lagging if
@@ -16,10 +17,11 @@ module Failbot
16
17
  # Interface for posting exception data to haystack.
17
18
  autoload :Haystack, 'failbot/haystack'
18
19
 
19
- autoload :FileBackend, 'failbot/file_backend'
20
- autoload :HTTPBackend, 'failbot/http_backend'
21
- autoload :MemoryBackend, 'failbot/memory_backend'
22
- autoload :JSONBackend, 'failbot/json_backend'
20
+ autoload :ConsoleBackend, 'failbot/console_backend'
21
+ autoload :FileBackend, 'failbot/file_backend'
22
+ autoload :HTTPBackend, 'failbot/http_backend'
23
+ autoload :MemoryBackend, 'failbot/memory_backend'
24
+ autoload :JSONBackend, 'failbot/json_backend'
23
25
 
24
26
  # Public: Set an instrumenter to be called when exceptions are reported.
25
27
  #
@@ -79,6 +81,8 @@ module Failbot
79
81
  Failbot::HTTPBackend.new(URI(settings["FAILBOT_HAYSTACK_URL"]))
80
82
  when 'json'
81
83
  Failbot::JSONBackend.new(settings["FAILBOT_BACKEND_JSON_HOST"], settings["FAILBOT_BACKEND_JSON_PORT"])
84
+ when 'console'
85
+ Failbot::ConsoleBackend.new
82
86
  else
83
87
  raise ArgumentError, "Unknown backend: #{name.inspect}"
84
88
  end
@@ -93,6 +97,8 @@ module Failbot
93
97
 
94
98
  # Bring in deprecated methods
95
99
  extend Failbot::Compat
100
+ # Bring in sensitive data scrubber specific methods
101
+ extend Failbot::SensitiveDataScrubber
96
102
 
97
103
  # Stack of context information to include in the next failbot report. These
98
104
  # hashes are condensed down into one and included in the next report. Don't
@@ -109,7 +115,7 @@ module Failbot
109
115
  #
110
116
  # Returns the value returned by the block when given; otherwise, returns nil.
111
117
  def push(info={})
112
- context.push(info)
118
+ context.push(scrub(info))
113
119
  yield if block_given?
114
120
  ensure
115
121
  pop if block_given?
@@ -218,11 +224,12 @@ module Failbot
218
224
  #
219
225
  # Returns nothing.
220
226
  def report(e, other = {})
227
+ scrubbed_other = scrub(other)
221
228
  if @raise_errors
222
- squash_contexts(context, exception_info(e), other) # surface problems squashing
229
+ squash_contexts(context, exception_info(e), scrubbed_other) # surface problems squashing
223
230
  raise e
224
231
  else
225
- report!(e, other)
232
+ report!(e, scrubbed_other)
226
233
  end
227
234
  end
228
235
 
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+
3
+ module Failbot
4
+ class ConsoleBackend
5
+ def report(data)
6
+ $stderr.puts data.to_json
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,68 @@
1
+ module Failbot
2
+ module SensitiveDataScrubber
3
+ FILTERED = '****'.freeze
4
+ BASIC_AUTH_REGEX = /:\/\/(.+:.*)(?=@)/
5
+ MAX_DEPTH = 100
6
+
7
+ def scrub(hash)
8
+ transform_values(hash) do |value|
9
+ scrub_urls(value)
10
+ end
11
+ end
12
+
13
+ def scrub_urls(value, max_depth=MAX_DEPTH)
14
+ return value if max_depth <= 0
15
+
16
+ case value
17
+ when String
18
+ scrub_url(value)
19
+ when Array
20
+ value.map do |element|
21
+ scrub_urls(element, max_depth - 1)
22
+ end
23
+ when Hash
24
+ transform_values(value) do |nested_value|
25
+ scrub_urls(nested_value, max_depth - 1)
26
+ end
27
+ else
28
+ value
29
+ end
30
+ end
31
+
32
+ def scrub_url(url)
33
+ uri = URI(url)
34
+
35
+ uri.query = scrub_request_params(uri.query) if uri.query
36
+
37
+ uri.to_s.gsub(BASIC_AUTH_REGEX, "://#{FILTERED}:#{FILTERED}")
38
+ rescue
39
+ url
40
+ end
41
+
42
+ # Took this from ruby 2.4+ because we do not want to rely on
43
+ # specific ruby versions.
44
+ #
45
+ def transform_values(hash)
46
+ return {} if hash.empty?
47
+ result = Hash.new
48
+ hash.each do |key, value|
49
+ result[key] = yield(value)
50
+ end
51
+ result
52
+ end
53
+
54
+ def scrub_request_params(query)
55
+ # We can do this with Rack query builder but we do not want to have a dependency on Rack
56
+ params = Hash[query.split('&').map { |el| el.split('=') }]
57
+
58
+ params.each do |attr, _|
59
+ if attr.include?('token') ||
60
+ !!attr.match(/oauth_\w+/) # this is for Oauth 1.0
61
+ params[attr] = FILTERED
62
+ end
63
+ end
64
+
65
+ params.map { |el| el.join('=') }.join('&')
66
+ end
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Failbot
2
- VERSION = "2.0.1"
2
+ VERSION = "2.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: failbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@rtomayko"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-24 00:00:00.000000000 Z
13
+ date: 2019-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '5.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: minitest-stub-const
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0.6'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0.6'
71
85
  description: "..."
72
86
  email:
73
87
  - github+failbot@lists.github.com
@@ -77,6 +91,7 @@ extra_rdoc_files: []
77
91
  files:
78
92
  - lib/failbot.rb
79
93
  - lib/failbot/compat.rb
94
+ - lib/failbot/console_backend.rb
80
95
  - lib/failbot/exit_hook.rb
81
96
  - lib/failbot/failbot.yml
82
97
  - lib/failbot/file_backend.rb
@@ -86,6 +101,7 @@ files:
86
101
  - lib/failbot/memory_backend.rb
87
102
  - lib/failbot/middleware.rb
88
103
  - lib/failbot/resque_failure_backend.rb
104
+ - lib/failbot/sensitive_data_scrubber.rb
89
105
  - lib/failbot/version.rb
90
106
  homepage: http://github.com/github/failbot#readme
91
107
  licenses:
@@ -107,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
123
  version: 1.3.6
108
124
  requirements: []
109
125
  rubyforge_project:
110
- rubygems_version: 2.5.2
126
+ rubygems_version: 2.5.2.3
111
127
  signing_key:
112
128
  specification_version: 4
113
129
  summary: Deliver exceptions to Haystack