Sha256: e95f21b6075e9f3e44e7f301a25df60bee5256108d581c922f8a570df44ed64a

Contents?: true

Size: 775 Bytes

Versions: 10

Compression:

Stored size: 775 Bytes

Contents

module Rollbar
  module Util
    module IPAnonymizer
      require 'ipaddr'

      def self.anonymize_ip(ip_string)
        return ip_string unless Rollbar.configuration.anonymize_user_ip
        ip = IPAddr.new(ip_string)
        return anonymize_ipv6 ip if ip.ipv6?
        return anonymize_ipv4 ip if ip.ipv4?
      rescue
        nil
      end
      
      def self.anonymize_ipv4(ip)
        ip_parts = ip.to_s.split '.'
        
        ip_parts[ip_parts.count - 1] = '0'
        
        IPAddr.new(ip_parts.join('.')).to_s
      end
      
      def self.anonymize_ipv6(ip)
        ip_parts = ip.to_s.split ':'
        
        ip_string = ip_parts[0..2].join(':') + ':0000:0000:0000:0000:0000'
        
        IPAddr.new(ip_string).to_s
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rollbar-2.19.2 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.19.1 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.19.0 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.18.2 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.18.0 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.17.0 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.16.4 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.16.3 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.16.2 lib/rollbar/util/ip_anonymizer.rb
rollbar-2.16.0 lib/rollbar/util/ip_anonymizer.rb