my_obfuscate

Standalone Ruby code for the selective rewriting of MySQL dumps in order to protect user privacy.

Install

sudo gem install my_obfuscate

Example Usage

Make an obfuscator.rb script:

#!/usr/bin/env ruby
require "rubygems"
require "my_obfuscate"

obfuscator = MyObfuscate.new({
  :people => {
    :email                     => { :type => :email, :skip_regexes => [/^[\w\.\_]+@my_company\.com$/i] },
    :ethnicity                 => { :type => :null },
    :crypted_password          => { :type => :fixed, :string => "SOME_FIXED_PASSWORD_FOR_EASE_OF_DEBUGGING" },
    :salt                      => { :type => :fixed, :string => "SOME_THING" },
    :remember_token            => { :type => :null },
    :remember_token_expires_at => { :type => :null },
    :photo_file_name           => { :type => :null },
    :photo_content_type        => { :type => :null },
    :photo_file_size           => { :type => :null },
    :photo_updated_at          => { :type => :null },
    :postal_code               => { :type => :fixed, :string => "94109" },
    :name                      => { :type => :fixed, :string => "Production User" },
    :relationship_status       => { :type => :fixed, :one_of => ["Single", "Divorced", "Married", "Engaged", "In a Relationship"] },
    :has_children              => { :type => :integer, :between => 0..1 },
  },

  :invites                     => :truncate,
  :invite_requests             => :truncate,

  :relationships => {
    :account_id                => { :type => :string, :length => 8, :chars => MyObfuscate::NUMBER_CHARS },
    :code                      => { :type => :string, :length => 8, :chars => MyObfuscate::USERNAME_CHARS }
  }
})
obfuscator.obfuscate(STDIN, STDOUT)

And to get an obfuscated dump:

mysqldump -c --add-drop-table -u user -p database | ruby obfuscator.rb > obfuscated_dump.sql

Note that the -c option on mysqldump is required to use my_obfuscator.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Honk. See LICENSE for details.