my_obfuscate 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -3
- data/VERSION +1 -1
- data/lib/my_obfuscate.rb +12 -2
- data/my_obfuscate.gemspec +2 -2
- data/spec/my_obfuscate_spec.rb +50 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -26,8 +26,8 @@ Make an obfuscator.rb script:
|
|
26
26
|
:photo_content_type => { :type => :null },
|
27
27
|
:photo_file_size => { :type => :null },
|
28
28
|
:photo_updated_at => { :type => :null },
|
29
|
-
:postal_code => { :type => :fixed, :string => "94109" },
|
30
|
-
:name => { :type => :fixed, :string => "Production User" },
|
29
|
+
:postal_code => { :type => :fixed, :string => "94109", :unless => lambda {|person| person[:postal_code] == "12345"} },
|
30
|
+
:name => { :type => :fixed, :string => "Production User", :if => lambda {|person| person[:email] == "hello@example.com"} },
|
31
31
|
:relationship_status => { :type => :fixed, :one_of => ["Single", "Divorced", "Married", "Engaged", "In a Relationship"] },
|
32
32
|
:has_children => { :type => :integer, :between => 0..1 },
|
33
33
|
},
|
@@ -47,7 +47,7 @@ And to get an obfuscated dump:
|
|
47
47
|
Note that the -c option on mysqldump is required to use my_obfuscator.
|
48
48
|
|
49
49
|
== Note on Patches/Pull Requests
|
50
|
-
|
50
|
+
|
51
51
|
* Fork the project.
|
52
52
|
* Make your feature addition or bug fix.
|
53
53
|
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/my_obfuscate.rb
CHANGED
@@ -25,7 +25,7 @@ class MyObfuscate
|
|
25
25
|
table_name = regex_result[1].to_sym
|
26
26
|
columns = regex_result[2].split(/`\s*,\s*`/).map { |col| col.gsub('`',"").to_sym }
|
27
27
|
if config[table_name]
|
28
|
-
output_io.puts
|
28
|
+
output_io.puts obfuscate_bulk_insert_line(line, table_name, columns)
|
29
29
|
else
|
30
30
|
output_io.write line
|
31
31
|
end
|
@@ -108,12 +108,22 @@ class MyObfuscate
|
|
108
108
|
output
|
109
109
|
end
|
110
110
|
|
111
|
+
def self.row_as_hash(row, columns)
|
112
|
+
columns.zip(row).inject({}) {|m, (name, value)| m[name] = value; m}
|
113
|
+
end
|
114
|
+
|
111
115
|
def self.apply_table_config(row, table_config, columns)
|
112
116
|
return row unless table_config.is_a?(Hash)
|
117
|
+
row_hash = row_as_hash(row, columns)
|
113
118
|
|
114
119
|
table_config.each do |column, definition|
|
115
120
|
index = columns.index(column)
|
116
121
|
|
122
|
+
next if definition[:unless] && definition[:unless].call(row_hash)
|
123
|
+
if definition[:if]
|
124
|
+
next unless definition[:if].call(row_hash)
|
125
|
+
end
|
126
|
+
|
117
127
|
if definition[:skip_regexes]
|
118
128
|
next if definition[:skip_regexes].any? {|regex| row[index] =~ regex}
|
119
129
|
end
|
@@ -162,7 +172,7 @@ class MyObfuscate
|
|
162
172
|
end
|
163
173
|
end
|
164
174
|
|
165
|
-
def
|
175
|
+
def obfuscate_bulk_insert_line (line, table_name, columns)
|
166
176
|
table_config = config[table_name]
|
167
177
|
if table_config == :truncate
|
168
178
|
""
|
data/my_obfuscate.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{my_obfuscate}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Cantino", "Dave Willett", "Mike Grafton", "Mason Glaves"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-09}
|
13
13
|
s.description = %q{Standalone Ruby code for the selective rewriting of MySQL dumps in order to protect user privacy.}
|
14
14
|
s.email = %q{andrew@pivotallabs.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/my_obfuscate_spec.rb
CHANGED
@@ -69,6 +69,50 @@ describe MyObfuscate do
|
|
69
69
|
new_row[1].should_not == "something_else"
|
70
70
|
end
|
71
71
|
|
72
|
+
describe "conditional directives" do
|
73
|
+
it "should honor :unless conditionals" do
|
74
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :unless => lambda {|row| row[:a] == "blah"} }}, [:a, :b, :c])
|
75
|
+
new_row[0].should_not == "123"
|
76
|
+
new_row[0].should == "blah"
|
77
|
+
|
78
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :unless => lambda {|row| row[:a] == "not blah"} }}, [:a, :b, :c])
|
79
|
+
new_row[0].should == "123"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should honor :if conditionals" do
|
83
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :if => lambda {|row| row[:a] == "blah"} }}, [:a, :b, :c])
|
84
|
+
new_row[0].should == "123"
|
85
|
+
|
86
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :if=> lambda {|row| row[:a] == "not blah"} }}, [:a, :b, :c])
|
87
|
+
new_row[0].should_not == "123"
|
88
|
+
new_row[0].should == "blah"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should supply the original row values to the conditional" do
|
92
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else"], { :a => { :type => :fixed, :string => "123" }, :b => { :type => :fixed, :string => "yup", :if => lambda {|row| row[:a] == "blah"}}}, [:a, :b])
|
93
|
+
new_row[0].should == "123"
|
94
|
+
new_row[1].should == "yup"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should honor combined :unless and :if conditionals" do
|
98
|
+
#both true
|
99
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :if => lambda {|row| row[:a] == "blah"}, :unless => lambda {|row| row[:b] == "something_else"} }}, [:a, :b, :c])
|
100
|
+
new_row[0].should == "blah"
|
101
|
+
|
102
|
+
#both false
|
103
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :if => lambda {|row| row[:a] == "not blah"}, :unless => lambda {|row| row[:b] == "not something_else"} }}, [:a, :b, :c])
|
104
|
+
new_row[0].should == "blah"
|
105
|
+
|
106
|
+
#if true, #unless false
|
107
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :if => lambda {|row| row[:a] == "blah"}, :unless => lambda {|row| row[:b] == "not something_else"} }}, [:a, :b, :c])
|
108
|
+
new_row[0].should == "123"
|
109
|
+
|
110
|
+
#if false, #unless true
|
111
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :a=> { :type => :fixed, :string => "123", :if => lambda {|row| row[:a] == "not blah"}, :unless => lambda {|row| row[:b] == "something_else"} }}, [:a, :b, :c])
|
112
|
+
new_row[0].should == "blah"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
72
116
|
it "should be able to generate random integers in ranges" do
|
73
117
|
new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], { :c => { :type => :integer, :between => 10..100 }}, [:a, :b, :c])
|
74
118
|
new_row.length.should == 3
|
@@ -104,6 +148,12 @@ describe MyObfuscate do
|
|
104
148
|
|
105
149
|
end
|
106
150
|
|
151
|
+
describe "MyObfuscate.row_as_hash" do
|
152
|
+
it "will map row values into a hash with column names as keys" do
|
153
|
+
MyObfuscate.row_as_hash([1, 2, 3, 4], [:a, :b, :c, :d]).should == {:a => 1, :b => 2, :c => 3, :d => 4}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
107
157
|
describe "#obfuscate" do
|
108
158
|
context "when there is nothing to obfuscate" do
|
109
159
|
it "should accept an IO object for input and output, and copy the input to the output" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_obfuscate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Cantino
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-10-
|
15
|
+
date: 2009-10-09 00:00:00 -07:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|