sunitparekh/data-anonymization

View on GitHub
bin/datanon

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# encoding: UTF-8

require 'thor'
require 'data-anonymization'

class AnonymizationCLI < Thor

  include Thor::Actions

  desc "generate_rdbms_dsl", "Generates a base anonymization script(whitelist strategy) for a RDBMS database using the database schema"

  def generate_rdbms_dsl

    configuration_hash = {:adapter => options["adapter"],
                           :host => options["host"],
                           :port => options["port"],
                           :database => options["database"],
                           :username => options["username"],
                           :password => options["password"]
                          }
    create_file "rdbms_whitelist_generated.rb"
    DataAnon::ThorHelpers::RDBMSDSLGenerator.new.generate_whitelist_script(configuration_hash)
  end

  method_option :adapter, :required => true, :aliases => "-a", :desc => "Activerecord database adapter to be used [required]", :for => :generate_rdbms_dsl
  method_option :host, :required => true, :aliases => "-h", :desc => "Source Database host [required]", :for => :generate_rdbms_dsl
  method_option :database, :required => true, :aliases => "-d", :desc => "Database name [required]", :for => :generate_rdbms_dsl
  method_option :port, :aliases => "-p", :desc => "Port to connect to. If not provided default port provided by AR will be used", :for => :generate_rdbms_dsl
  method_option :username, :aliases => "-u", :desc => "Username", :for => :generate_rdbms_dsl
  method_option :password, :aliases => "-w", :desc => "Password", :for => :generate_rdbms_dsl

  desc "generate_mongo_dsl", "Generates a base anonymization script(whitelist strategy) for a Mongo DB using the database schema"

  def generate_mongo_dsl

    configuration_hash = {:host => options["host"],
                          :port => options["port"],
                          :database => options["database"],
                          :username => options["username"],
                          :password => options["password"]
    }

    create_file "mongodb_whitelist_generated.rb"
    DataAnon::ThorHelpers::MongoDBDSLGenerator.new(configuration_hash, options["whitelist_patterns"]).generate
  end

  method_option :host, :required => true, :aliases => "-h", :desc => "Source Database host [required]", :for => :generate_mongo_dsl
  method_option :database, :required => true, :aliases => "-d", :desc => "Database name [required]", :for => :generate_mongo_dsl
  method_option :port, :aliases => "-p", :desc => "Port to connect to. If not provided default port will be used", :for => :generate_mongo_dsl
  method_option :username, :aliases => "-u", :desc => "Username", :for => :generate_mongo_dsl
  method_option :password, :aliases => "-w", :desc => "Password", :for => :generate_mongo_dsl
  method_option :whitelist_patterns, :aliases => "-r", :desc => "Whitelist Patterns", :for => :generate_mongo_dsl

end

AnonymizationCLI.start