sql_footprint 0.4.1 → 0.5.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: be386779c80212ebc572dc5ab1f8facbc7f01a2d
4
- data.tar.gz: 24a778a2eef8fb80a8e026155d1df4af82c8fd3f
3
+ metadata.gz: 1ac46ddae41caa7510ac1f722c17437eaca4ccb3
4
+ data.tar.gz: dc1c4c55f3b45be3958c2116c9694cc67121fd57
5
5
  SHA512:
6
- metadata.gz: fc004cfb2453e5dd2c43d4098a5768a5df1b6fb35b1e58e35c2a8cb851b3cf48f462a54085a2a953b27be310041bbc4bacef14561571599cab37dcec47756cf6
7
- data.tar.gz: fedb11a433daa76e87afd984a0f848f2bcbd8fe8dcda92387a467264eeccb18b56afe15b30d02d0b163439def24339305e3e578274e4f68be14c382d8c239d86
6
+ metadata.gz: a6cca4053a8fe4414c8d54c265f67f393b16435fe9b7dfa111f40a65b088a88b11d69e3246dc1d5c28f97e55b303faa3e84c2f327625cb632cc955a205a5488e
7
+ data.tar.gz: 4707ade659f35ff6b18280aa062bbe9c49217f1f57c233d13379a057222c92752e2f1fdc99c2273daef359c1c8b2551c4ddfe014e8e07adcacb811156f26a56c
@@ -0,0 +1,15 @@
1
+ module SqlFootprint
2
+ class SqlAnonymizer
3
+ GSUBS = {
4
+ /\sIN\s\((.*)\)/ => ' IN (values-redacted)'.freeze, # IN clauses
5
+ /\s\=\s([0-9]+)/ => ' = number-redacted'.freeze, # numbers
6
+ /\s'(.*)\'/ => " 'value-redacted'".freeze, # literal strings
7
+ }.freeze
8
+
9
+ def anonymize sql
10
+ GSUBS.reduce(sql) do |s, (regex, replacement)|
11
+ s.gsub regex, replacement
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module SqlFootprint
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
data/lib/sql_footprint.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'sql_footprint/version'
2
+ require 'sql_footprint/sql_anonymizer'
2
3
  require 'set'
3
4
  require 'active_support/notifications'
4
5
 
@@ -12,8 +13,9 @@ module SqlFootprint
12
13
 
13
14
  class << self
14
15
  def start
15
- @capture = true
16
- @lines = Set.new
16
+ @anonymizer = SqlAnonymizer.new
17
+ @capture = true
18
+ @lines = Set.new
17
19
  end
18
20
 
19
21
  def stop
@@ -34,32 +36,7 @@ module SqlFootprint
34
36
 
35
37
  def capture sql
36
38
  return unless @capture
37
- @lines << strip_values(sql)
38
- end
39
-
40
- def strip_values sql
41
- sql = sql.gsub(/\[\[.*\]\]/, '')
42
- sql = strip_string_values(sql)
43
- sql = strip_integer_values(sql)
44
- strip_in_clause_values(sql)
45
- end
46
-
47
- def strip_in_clause_values sql
48
- sql.gsub(/\sIN\s\((.*)\)/) do |_match|
49
- ' IN (values-redacted)'
50
- end
51
- end
52
-
53
- def strip_integer_values sql
54
- sql.gsub(/\s\=\s([0-9]+)/) do |_match|
55
- ' = number-redacted'
56
- end
57
- end
58
-
59
- def strip_string_values sql
60
- sql.gsub(/\s'(.*)\'/) do |_match|
61
- " 'value-redacted'"
62
- end
39
+ @lines << @anonymizer.anonymize(sql)
63
40
  end
64
41
  end
65
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_footprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Joyce
@@ -153,6 +153,7 @@ files:
153
153
  - bin/console
154
154
  - bin/setup
155
155
  - lib/sql_footprint.rb
156
+ - lib/sql_footprint/sql_anonymizer.rb
156
157
  - lib/sql_footprint/version.rb
157
158
  - sql_footprint.gemspec
158
159
  homepage: https://github.com/covermymeds/sql_footprint