nadir 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ab62bfe9744ad0af0ae7224025fefe213c7a6691ec91b01f4284c7b6b093970
4
- data.tar.gz: fb21b0592ea8c01e9bad62afbb69cf3e7a686c0883a02de893938cc903f9869b
3
+ metadata.gz: 2a0977a1a853e63b9ad20a765aa18acc90b08a3f60827044d02205f808329d11
4
+ data.tar.gz: 006b93b16c0df54a94a97a2d1e02733848e8aec500c7491edb42ba88142fccde
5
5
  SHA512:
6
- metadata.gz: 475e064f690a0c2e7b7857ccdca1c26393d0d2c2febc7fb390a9709600c8564ceb0027e75c237ead868be4dd996322a517979db16efc05d1ee3c3caea0dcc91f
7
- data.tar.gz: 37da2b4ff18bd392461ea03b4f39c6e262e0cfeaaec5d4f2fab7e153111d45ff50eb1873c9f297a7b16a483545c6404518940fcbf475098283cf4a132e7e46e1
6
+ metadata.gz: c8627141fa0628b10eb2a747c3256c85746f0e3d60b950dcfee997a8a5ed044427dcae471b3720ae9dc5a10f9e1fcfe56e46d4c45c80c1531ce595957dca26b2
7
+ data.tar.gz: d31b15b9cd5ee955db8188aee2c1020c88d07c879ff663ea3534f8a415ad76acbf306bac941131668ac748381396cc4081efcdd41d9dfea7233c15bc418e35b0
@@ -7,15 +7,16 @@ module Nadir
7
7
  :env,
8
8
  :logger,
9
9
  :root,
10
- :enabled_for
10
+ :enabled_for,
11
+ :filtered_params
11
12
 
12
13
  def initialize
13
- @env = ENV['NADIR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
14
- @api_key = ENV['NADIR_API_KEY']
15
- @api_url = 'https://nadir.dev/api'.freeze
16
- @enabled_for = %w(production staging)
17
-
18
- @logger = Logger.new(STDOUT)
14
+ @env = ENV['NADIR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
15
+ @api_key = ENV['NADIR_API_KEY']
16
+ @api_url = 'https://nadir.dev/api'.freeze
17
+ @enabled_for = %w(production staging)
18
+ @logger = Logger.new(STDOUT)
19
+ @filtered_params = %i(password credit_card secret http_cookie)
19
20
  end
20
21
 
21
22
  def validate
@@ -45,6 +46,8 @@ module Nadir
45
46
  @api_key = file_config['api_key'] if file_config['api_key']
46
47
  @api_url = file_config['api_url'] if file_config['api_url']
47
48
  @enabled_for = file_config['enabled_for'] if file_config['enabled_for']
49
+ rescue => e
50
+ @logger.warn "Unable to load Nadir configuration. Please ensure that the file 'config/nadir.yml' exists and contains your API key."
48
51
  end
49
52
  end
50
53
  end
@@ -16,9 +16,9 @@ module Nadir
16
16
  fingerprint: fingerprint,
17
17
  host: Socket.gethostname,
18
18
  pid: Process.pid,
19
- request_params: @params.dig(:request, :params),
19
+ request_params: filter(@params.dig(:request, :params)),
20
+ request_headers: filter(@params.dig(:request, :headers)),
20
21
  request_remote_ip: @params.dig(:request, :remote_ip),
21
- request_headers: @params.dig(:request, :headers),
22
22
  }
23
23
  end
24
24
 
@@ -50,6 +50,15 @@ module Nadir
50
50
  def gem_paths
51
51
  @gem_paths ||= Gem.path | [Gem.default_dir]
52
52
  end
53
+
54
+ def filter(params)
55
+ params_filter.filter params
56
+ rescue
57
+ params
58
+ end
59
+
60
+ def params_filter
61
+ @params_filter ||= ActionDispatch::Http::ParameterFilter.new(Nadir.config.filtered_params || [])
62
+ end
53
63
  end
54
64
  end
55
-
@@ -25,14 +25,15 @@ module Nadir
25
25
  def deliver(params)
26
26
  self.class.thread_pool.post do
27
27
  uri = URI("#{@api_url}/faults")
28
- post = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
29
- post.body = {fault: params, api_key: @api_key}.to_json
30
-
31
- request = Net::HTTP.new(uri.hostname, uri.port)
32
- request.use_ssl = true
33
- response = request.start do |http|
34
- http.request post
35
- end
28
+
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+
31
+ http.use_ssl = true if uri.class == URI::HTTPS
32
+
33
+ request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
34
+ request.body = {fault: params, api_key: @api_key}.to_json
35
+
36
+ http.request request
36
37
  end
37
38
  end
38
39
  end
@@ -1,3 +1,3 @@
1
1
  module Nadir
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nadir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georgi Mitrev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby