sql_footprint 0.4.1 → 0.5.0
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 +4 -4
 - data/lib/sql_footprint/sql_anonymizer.rb +15 -0
 - data/lib/sql_footprint/version.rb +1 -1
 - data/lib/sql_footprint.rb +5 -28
 - metadata +2 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1ac46ddae41caa7510ac1f722c17437eaca4ccb3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: dc1c4c55f3b45be3958c2116c9694cc67121fd57
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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
         
     | 
    
        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 
     | 
    
         
            -
                  @ 
     | 
| 
       16 
     | 
    
         
            -
                  @ 
     | 
| 
      
 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 <<  
     | 
| 
       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 
     | 
    
         
            +
              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
         
     |