obfuscator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,7 +29,6 @@ As a Ruby program:
29
29
  # Without a format, Obfuscator will fill all of the given columns
30
30
  # with dummy data based on the column's SQL type
31
31
  Obfuscator.scrub! "Message" do
32
- # Would generate dummy sentences, paragraphs, and timestamps accordingly
33
32
  overwrite :title, :body, :created_at
34
33
  end
35
34
 
@@ -40,18 +39,16 @@ Obfuscator.scrub! "User" do
40
39
  overwrite :login do
41
40
  format :user_name
42
41
  end
43
- end
44
42
 
45
- Obfuscator.scrub! "Subscriber" do
46
43
  overwrite :email_address do
47
44
  format :email
48
45
  end
49
46
  end
50
47
  ```
51
48
 
52
- Or as a Rake task (TODO: Not finished yet):
49
+ Or as a Rake task:
53
50
 
54
- rake obfuscator:scrub["User", ["login","email"]]
51
+ rake obfuscator:scrub[User] COLUMNS=login,email
55
52
 
56
53
  ## Contributing
57
54
 
@@ -63,9 +60,8 @@ Or as a Rake task (TODO: Not finished yet):
63
60
 
64
61
  ## TODO
65
62
 
66
- * Get Rake task fully working
67
- * Move away from iterating through all records and calling
68
- update_attributes. Better: finding in batches. Best: Generating a
69
- giant update_all.
70
- * Definite jankiness with the Dsl (especially that you can't pass
71
- multiple overwrite/format blocks in one parent block currently)
63
+ * Reflect on model validations to ensure generated data is valid
64
+ * Make DSL more flexible about taking both arrays and hashes of columns
65
+ with options
66
+ * Move away from iterating through batches of records and calling
67
+ update_attributes by constructing an update_all
@@ -32,7 +32,12 @@ module Obfuscator
32
32
  end
33
33
 
34
34
  def format(format)
35
- @columns = { columns.first => format }
35
+ if @columns_hash.present?
36
+ @columns = @columns_hash.merge(columns.first => format)
37
+ else
38
+ @columns = { columns.first => format }
39
+ @columns_hash = @columns
40
+ end
36
41
  end
37
42
  end
38
43
 
@@ -74,11 +74,13 @@ module Obfuscator
74
74
  end
75
75
 
76
76
  def scrub_all_records!
77
- @model.all.each do |m|
78
- attributes = model_columns_contain_given? ?
79
- columns_with_obfuscated_values_hash : {}
77
+ @model.find_in_batches do |group|
78
+ group.each do |record|
79
+ attributes = model_columns_contain_given? ?
80
+ columns_with_obfuscated_values_hash : {}
80
81
 
81
- m.update_attributes(attributes)
82
+ record.update_attributes(attributes)
83
+ end
82
84
  end
83
85
  end
84
86
  end
@@ -1,3 +1,3 @@
1
1
  module Obfuscator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,12 +1,11 @@
1
1
  namespace :obfuscator do
2
- desc "Scrub sensitive data in provided model's columns"
3
-
4
- task :scrub, [:model, :columns] => :environment do |task, arguments|
2
+ desc "Scrub sensitive data for a given model's column"
3
+ task :scrub, [:model] => :environment do |task, arguments|
5
4
  model = arguments[:model]
6
- columns = arguments[:columns]
7
-
8
- obfuscator = Obfuscator::Generic.new
5
+ columns = ENV["COLUMNS"].split(",")
9
6
 
10
- obfuscator.scrub!(model, columns)
7
+ Obfuscator.scrub! model do
8
+ overwrite columns
9
+ end
11
10
  end
12
11
  end
@@ -53,12 +53,16 @@ describe Obfuscator::Dsl do
53
53
  describe ".format" do
54
54
  it "sets the type of the column to the given format" do
55
55
  Obfuscator::Generic.any_instance.should_receive(:scrub!).
56
- with("User", { login: :user_name })
56
+ with("User", { login: :user_name, email: :email })
57
57
 
58
58
  Obfuscator.scrub!("User") do
59
59
  overwrite :login do
60
60
  format :user_name
61
61
  end
62
+
63
+ overwrite :email do
64
+ format :email
65
+ end
62
66
  end
63
67
  end
64
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obfuscator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-03 00:00:00.000000000Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70183958259900 !ruby/object:Gem::Requirement
16
+ requirement: &70194697721360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70183958259900
24
+ version_requirements: *70194697721360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faker
27
- requirement: &70183958259480 !ruby/object:Gem::Requirement
27
+ requirement: &70194697718000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70183958259480
35
+ version_requirements: *70194697718000
36
36
  description: A clean, friendly API for obfuscating slightly sensitive data from a
37
37
  Rails application
38
38
  email:
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 1.8.16
83
+ rubygems_version: 1.8.15
84
84
  signing_key:
85
85
  specification_version: 3
86
86
  summary: Obfuscate provides an easy way to quickly overwrite slightly sensitive data