forked from expertiza/expertiza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Independent study. Add db anonymization (expertiza#2744)
* Add db anonyimization * Updated logic in scrub_database.rb * Added Faker gem * Remove Faker gem, fix .sh script * Add name.yml * Add comments * Delete db_anonymization.sh * Update scrub_database.rake * Update scrub_database.rake * Update scrub_database.rake * Update scrub_database.rb * Update name.yml * Fix name generation * Add anonymization environment --------- Co-authored-by: Ali Qureshi <[email protected]>
- Loading branch information
1 parent
ef449f6
commit af5f58e
Showing
4 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Expertiza::Application.configure do | ||
# Settings specified here will take precedence over those in config/environment.rb | ||
|
||
# In the development environment your application's code is reloaded on | ||
# every request. This slows down response time but is perfect for development | ||
# since you don't have to restart the webserver when you make code changes. | ||
config.cache_classes = false | ||
# config.serve_static_assets = false | ||
# config.action_mailer.default_url_options = { :host => 'localhost:3000' } | ||
host = '152.7.98.82:8080' | ||
config.action_mailer.default_url_options = { host: '152.7.98.82:8080', protocol: 'http' } | ||
# Do not eager load code on boot. | ||
config.eager_load = false | ||
|
||
# Show full error reports and disable caching. | ||
config.consider_all_requests_local = true | ||
config.action_controller.perform_caching = false | ||
# config.active_record.whitelist_attributes = false # need protected_attributes gem | ||
|
||
# Print deprecation notices to the Rails logger. | ||
config.active_support.deprecation = :log | ||
# Print development logs | ||
config.log_level = :error | ||
|
||
config.log_tags = %i[remote_ip uuid] | ||
|
||
config.log_formatter = proc do |s, ts, pg, msg| | ||
if msg.is_a?(LoggerMessage) | ||
"TST=[#{ts}] SVT=[#{s}] PNM=[#{pg}] OIP=[#{msg.oip}] RID=[#{msg.req_id}] CTR=[#{msg.generator}] UID=[#{msg.unity_id}] MSG=[#{filter(msg.message)}]\n" | ||
else | ||
"TST=[#{ts}] SVT=[#{s}] PNM=[#{pg}] OIP=[] RID=[] CTR=[] UID=[] MSG=[#{filter(msg)}]\n" | ||
end | ||
end | ||
|
||
def filter(msg) | ||
msg.tr("\n", ' ') | ||
end | ||
|
||
config.action_view.logger = nil | ||
|
||
# Raise an error on page load if there are pending migrations | ||
config.active_record.migration_error = :page_load | ||
|
||
# Debug mode disables concatenation and preprocessing of assets. | ||
# This option may cause significant delays in view rendering with a large | ||
# number of complex assets. | ||
config.assets.debug = true | ||
config.react.variant = :development | ||
config.active_record.logger = nil | ||
# Line 63-69 are for 'bullet' gem initialization. | ||
config.after_initialize do | ||
Bullet.enable = true | ||
Bullet.alert = false | ||
Bullet.bullet_logger = false | ||
Bullet.console = false | ||
Bullet.rails_logger = false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
require 'yaml' | ||
|
||
class ScrubDatabase | ||
def self.run! | ||
# Loop through each user | ||
User.find_each do |user| | ||
user.name = "#{user.role.name.downcase.gsub(/[- ]/, '_')}#{user.id}" | ||
user.fullname = "#{user.id}, #{user.role.name.downcase.gsub(/[- ]/, '_')}" | ||
user.email = '[email protected]' | ||
user.handle = 'handle' | ||
user.password = 'password' | ||
# user.password_confirmation = "password" | ||
user.save(validate: false) | ||
# Generate a new fake user record | ||
loop do | ||
fake_name = FakeNameGenerator.first_name | ||
fake_lastname = FakeNameGenerator.last_name | ||
num = rand(1..9) | ||
role = user.role.name.downcase.gsub(/[- ]/, '_') | ||
user.name = role == 'student' ? "#{fake_name}_#{fake_lastname[0..3]}#{num}" : "#{role}_#{fake_name}__#{fake_lastname[0..3]}" | ||
user.fullname = role == 'student' ? "#{fake_lastname}, #{fake_name}" : "#{fake_name}, #{role}" | ||
user.email = '[email protected]' | ||
user.handle = 'handle' | ||
user.password = 'password' | ||
username = role == 'student' ? "#{fake_name}_#{fake_lastname[0..3]}#{num}" : "#{role}_#{fake_name}__#{fake_lastname[0..3]}" | ||
# Checking if username already exists | ||
if User.find_by(:name => username) == nil #no record exists of that username | ||
# print "new user" | ||
user.save(validate: false) | ||
break | ||
end | ||
# if record exists, generate new fake record by going through the loop again | ||
end | ||
end | ||
|
||
Participant.find_each do |participant| | ||
participant.handle = 'handle' | ||
participant.save(validate: false) | ||
end | ||
end | ||
end | ||
|
||
|
||
class FakeNameGenerator | ||
NAMES = YAML.load_file("#{Rails.root}/config/name.yml")['name'] | ||
|
||
def self.first_name | ||
gender = [:male_first_name, :female_first_name, :neutral_first_name].sample | ||
NAMES["#{gender}"].sample | ||
end | ||
|
||
def self.last_name | ||
NAMES["#{:last_name}"].sample | ||
end | ||
end |