prosopite 1.0.5 → 1.0.6

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: a80a80552bf3cde44c5364bb227937e151b53926b011be7179b48c6cc71696c0
4
- data.tar.gz: 177fdf84e5340fe4d3435e93aeadbf44229678fe3316713ce3771793bbe69935
3
+ metadata.gz: 77276ce50263c0d9e2e4a9e0c525924ac5810367f036d783197222819f8fb312
4
+ data.tar.gz: b43868ebc87b40d97997db1c7a77fb3ee34cb032a76a0b290adb174c8d04c6d3
5
5
  SHA512:
6
- metadata.gz: c23f05d4f8e76c8f99bd59e963a61952b245f72b44148fb8f3ec8a85a49f8fbceec17517328dc3409d1d3987a07f57de5e278365be3fb4ff526a32c8e59c0163
7
- data.tar.gz: 586d95eae04d1a25c61c42760a11a870dfdab79cd81339aff4b2220f347aa6dbab33c4fda2a0cb023a72bf97058a3017a32a56fb0f7e787ddad38c88f9eaf364
6
+ metadata.gz: 5fc318b3becb5095f93244d8e23699c27e604c43ba7a3dc489ee3939d19b23e26a47eb4957d6355f28fdaa18fb6ecaa2caf27721a03fcadadefa73a5cbcfec7e
7
+ data.tar.gz: e5954aa6aec45c26722f807dcb2fde6aae4c1090d097cc7172a306cdde9639b734d226826fa1d6dcab59a9d22857dc7901978eb4297287ac49b81a63b23ae0e1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prosopite (1.0.5)
4
+ prosopite (1.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -182,7 +182,13 @@ WARNING: scan/finish should run before/after **each** test and NOT before/after
182
182
  Ignore notifications for call stacks containing one or more substrings:
183
183
 
184
184
  ```ruby
185
- Prosopite.allow_list = ['substring_in_call_stack']
185
+ Prosopite.allow_stack_paths = ['substring_in_call_stack']
186
+ ```
187
+
188
+ Ignore notifications matching a specific SQL query:
189
+
190
+ ```ruby
191
+ Prosopite.ignore_queries = [/regex_match/, "SELECT * from EXACT_STRING_MATCH"]
186
192
  ```
187
193
 
188
194
  ## Scanning code outside controllers or tests
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prosopite
4
- VERSION = "1.0.5"
4
+ VERSION = "1.0.6"
5
5
  end
data/lib/prosopite.rb CHANGED
@@ -8,7 +8,14 @@ module Prosopite
8
8
  :stderr_logger,
9
9
  :rails_logger,
10
10
  :prosopite_logger,
11
- :allow_list
11
+ :allow_stack_paths,
12
+ :ignore_queries
13
+
14
+ def allow_list=(value)
15
+ puts "Prosopite.allow_list= is deprecated. Use Prosopite.allow_stack_paths= instead."
16
+
17
+ self.allow_stack_paths = value
18
+ end
12
19
 
13
20
  def scan
14
21
  tc[:prosopite_scan] ||= false
@@ -20,7 +27,7 @@ module Prosopite
20
27
  tc[:prosopite_query_holder] = Hash.new { |h, k| h[k] = [] }
21
28
  tc[:prosopite_query_caller] = {}
22
29
 
23
- @allow_list ||= []
30
+ @allow_stack_paths ||= []
24
31
 
25
32
  tc[:prosopite_scan] = true
26
33
 
@@ -75,8 +82,9 @@ module Prosopite
75
82
  next unless fingerprints.uniq.size == 1
76
83
 
77
84
  kaller = tc[:prosopite_query_caller][location_key]
85
+ allow_list = (@allow_stack_paths + DEFAULT_ALLOW_LIST)
86
+ is_allowed = kaller.any? { |f| allow_list.any? { |s| f.include?(s) } }
78
87
 
79
- is_allowed = kaller.any? { |f| (@allow_list + DEFAULT_ALLOW_LIST).any? { |s| f.include?(s) } }
80
88
  unless is_allowed
81
89
  queries = tc[:prosopite_query_holder][location_key]
82
90
  tc[:prosopite_notifications][queries] = kaller
@@ -180,6 +188,11 @@ module Prosopite
180
188
  str.split("\n").map { |line| "\e[91m#{line}\e[0m" }.join("\n")
181
189
  end
182
190
 
191
+ def ignore_query?(sql)
192
+ @ignore_queries ||= []
193
+ @ignore_queries.any? { |q| q === sql }
194
+ end
195
+
183
196
  def subscribe
184
197
  @subscribed ||= false
185
198
  return if @subscribed
@@ -187,7 +200,7 @@ module Prosopite
187
200
  ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, _, _, _, data|
188
201
  sql, name = data[:sql], data[:name]
189
202
 
190
- if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil?
203
+ if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil? && !ignore_query?(sql)
191
204
  location_key = Digest::SHA1.hexdigest(caller.join)
192
205
 
193
206
  tc[:prosopite_query_counter][location_key] += 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prosopite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mpampis Kostas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-11 00:00:00.000000000 Z
11
+ date: 2021-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry