Giter Site home page Giter Site logo

ejvalmores / brillo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bessey/brillo

0.0 1.0 0.0 150 KB

Rails database scrubber and loader, for lightweight snapshots of your production DB in development

License: MIT License

Ruby 99.45% Shell 0.15% HTML 0.40%

brillo's Introduction

Build Status Gem Version

Brillo

Brillo is a Rails database scrubber and loader, useful for making lightweight copies of your production database for development machines, with sensitive information obfuscated. Most configuration is done through YAML: Specify the models that you want to back up, what associations you want with them, and what fields should be obfuscated (and how).

Once that is done, dropping your local DB and replacing it with the latest scrubbed copy is as easy as rake db:load.

Under the hood we use Polo to explore the classes and associations you specify in brillo.yml, obfuscated fields as configured.

Installation

Add this line to your application's Gemfile:

gem 'brillo'

Generate a starter brillo.yml file and config/initializers/brillo.rb with

$ rails g brillo_config

If you're using Capistrano, add Brillo's tasks to your Capfile:

# Capfile
require 'capistrano/brillo'

Lastly, since the scrubber is pretty resource intensive you may wish to ensure it runs on separate hardware from your app servers:

# config/deploy.rb
set :brillo_role, :my_batch_role

Usage

Here's an example brillo.yml for IMDB:

name: imdb            # Namespace the scrubbed file will occupy in S3
explore:
  user:               # Name of ActiveRecord class in snake_case
    tactic: all       # Scrubbing tactic to use (see Brillo:TACTICS for choices)
    associations:     # Associations to include in the scrub (ALL associated records included)
      - comments
  movie:
    tactic: latest    # The latest tactic explores the most recent 1,000 records
    associations:
      - actors
      - ratings
  admin/note:         # Corresponds to the Admin::Note class
    tactic: all
obfuscations:         #
  user.name: name     # Scrub user.name with the "name" scrubber (see Brillo::SCRUBBERS for choices)
  user.phone: phone
  user.email: email

Brillo uses the official aws-sdk to communicate with S3. There are a number of ways to pass your S3 credentials, but the simplest is to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in your environment.

If you'd like to see the gem in use, check out the /example_app directory.

Creating a scrubbed copy of the database in production

$ rake db:scrub

Loading a database in development

$ rake db:load

Loading a database on a stage

$ cap staging db:load

Advanced Configuration

If the built in record selection tactics aren't enough for you, or you need a custom obfuscation strategy, you can add them via the initializer. They are available in the YAML config like any other strategy.

# config/initializers/brillo.rb

Brillo.configure do |config|
  config.add_tactic :oldest, -> (klass) { klass.order(created_at: :desc).limit(1000) }

  config.add_obfuscation :remove_ls, -> (field) {
    field.gsub(/l/, "X")
  }

  # If you need the context of the entire record being obfuscated, it is available in the second argument
  config.add_obfuscation :phone_with_id, -> (field, instance) {
    (555_000_0000 + instance.id).to_s
  }

  # In addition to setting your S3 credentials via env you can set them something like this
  config.transfer_config.secret_access_key  = Rails.application.secrets.secret_access_key
  config.transfer_config.access_key_id      = Rails.application.secrets.access_key_id
end

To Do

  • Support alternative transfer mechanisms

brillo's People

Contributors

cionescu avatar joemcb avatar bessey avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.