Standalone Ruby code for the selective rewriting of MySQL dumps in order to protect user privacy.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 4 commits ahead, 6 commits behind honkster:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
my_obfuscate.gemspec

README.rdoc

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", :unless => lambda {|person| person[:postal_code] == "12345"} },
    :name                      => { :type => :fixed, :string => "Production User", :if => lambda {|person| person[:email] == "hello@example.com"} },
    :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 -ppassword 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

Copyright © 2009 Honk. See LICENSE for details.