data-anonymization 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/Gemfile +0 -1
- data/README.md +16 -12
- data/examples/mongodb_blacklist_dsl.rb +7 -5
- data/examples/mongodb_whitelist_dsl.rb +8 -6
- data/examples/whitelist_dsl.rb +1 -1
- data/lib/strategy/base.rb +19 -3
- data/lib/strategy/mongodb/blacklist.rb +2 -1
- data/lib/strategy/mongodb/whitelist.rb +2 -2
- data/lib/version.rb +1 -1
- data/spec/acceptance/mongodb_blacklist_spec.rb +6 -6
- data/spec/acceptance/mongodb_whitelist_spec.rb +10 -10
- data/spec/acceptance/rdbms_blacklist_spec.rb +5 -5
- data/spec/acceptance/rdbms_whitelist_spec.rb +23 -2
- data/spec/acceptance/rdbms_whitelist_with_primary_key_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/support/customer_sample.rb +30 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3354956cfd68076ea4bc342f611a9934f2b7385
|
4
|
+
data.tar.gz: ac064ad09012df2877aa29bd726c9e074749c7ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11b75a2a68c5ec5f80049378a6a23c3b25a7f9368e7063febc5d88107e80dcc165498038e55f8d4b651fcbfd0e30489918be751f7a647f37a535cd8dd40cc2d6
|
7
|
+
data.tar.gz: 65edc1aeaf200ed7ef0774801a690806f2256a60c43aa838ac8717e3f9e8466292cf22a339dac975ee88ae32efea541991c761dec6adc5be88bbbee5ae352a83
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.2.2
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -70,13 +70,18 @@ Postgresql database having **composite primary key**
|
|
70
70
|
|
71
71
|
## Changelog
|
72
72
|
|
73
|
+
#### 0.7.2 (Sep 26, 2015)
|
74
|
+
1. Upgraded MongoDB to latest gem version 2.1.0 and tested with MongoDB 3.x version.
|
75
|
+
2. Upgraded gems to latest version
|
76
|
+
3. Adding limit functionality - Merge pull request #27 from yanismydj/master
|
77
|
+
|
73
78
|
#### 0.7.1 (Jun 13, 2015)
|
74
79
|
1. Fixed issues with empty array data for MongoDB
|
75
80
|
2. Added feature to skip and continue records during anaonymisation, this is useful to apply different strategies for different types of records.
|
76
81
|
|
77
82
|
|
78
83
|
#### 0.7.0 (Mar 9, 2015)
|
79
|
-
1. Removed downcase from field name since it was causing issues with upper case field names. So now for databsae where case matters field name case should be maintained.
|
84
|
+
1. Removed downcase from field name since it was causing issues with upper case field names. So now for databsae where case matters field name case should be maintained.
|
80
85
|
2. Upgraded gems to latest version
|
81
86
|
|
82
87
|
|
@@ -204,8 +209,9 @@ Read more about [blacklist and whitelist here](http://sunitspace.blogspot.in/201
|
|
204
209
|
2. Change [default field strategies](#default-field-strategies) to avoid using same strategy again and again in your DSL.
|
205
210
|
3. To run anonymization in parallel at Table level, provided no FK constraint on tables use DataAnon::Parallel::Table strategy
|
206
211
|
4. For large table to load them in batches from table set 'batch_size' and it will use RoR's batch mode processing. Checkout [example](https://github.com/sunitparekh/data-anonymization/blob/master/examples/whitelist_dsl.rb) on how to use batch processing.
|
207
|
-
5. Make sure to give proper case for fields and table names.
|
208
|
-
6. Use skip and continue to apply different strategies for records.
|
212
|
+
5. Make sure to give proper case for fields and table names.
|
213
|
+
6. Use skip and continue to apply different strategies for records.
|
214
|
+
7. Use 'limit' to limit the number of rows that will be imported in whitelist
|
209
215
|
|
210
216
|
## DSL Generation
|
211
217
|
|
@@ -268,7 +274,7 @@ The options available are :
|
|
268
274
|
2. database(-d) : The name of the database to generate the whitelist script for
|
269
275
|
3. username(-u) : Username for DB authentication
|
270
276
|
4. password(-w) : Password for DB authentication
|
271
|
-
5. port(-p) : The port the database service is running on.
|
277
|
+
5. port(-p) : The port the database service is running on.
|
272
278
|
6. whitelist patterns(-r): A regex expression which can be used to match records in the database to list as whitelisted fields in the generated script.
|
273
279
|
|
274
280
|
The host and database options are mandatory. The others are optional.
|
@@ -282,7 +288,7 @@ datanon generate_mongo_dsl -h 123.456.7.8 -d production_db
|
|
282
288
|
|
283
289
|
```
|
284
290
|
|
285
|
-
The **mongo** gem is required in order to install the mongo db drivers. The script generates a file named **mongodb_whitelist_generated.rb** in the same location as the project.
|
291
|
+
The **mongo** gem is required in order to install the mongo db drivers. The script generates a file named **mongodb_whitelist_generated.rb** in the same location as the project.
|
286
292
|
|
287
293
|
|
288
294
|
|
@@ -575,7 +581,7 @@ DataAnon::Utils::Logging.logger.level = Logger::INFO
|
|
575
581
|
|
576
582
|
## Skip and Continue records
|
577
583
|
|
578
|
-
*Skip* is used to skip records during anonymization when condition returns true. This records are ignored,
|
584
|
+
*Skip* is used to skip records during anonymization when condition returns true. This records are ignored,
|
579
585
|
in blacklist it remains as it is in database and in case of whitelist this records will not be copied to destination database.
|
580
586
|
|
581
587
|
```ruby
|
@@ -587,11 +593,11 @@ table 'customers' do
|
|
587
593
|
anonymize 'terms_n_condition', 'age'
|
588
594
|
end
|
589
595
|
```
|
590
|
-
|
591
|
-
|
592
|
-
*Continue* is exactly opposite of Skip and it continue with anonymization only if given condition returns true.
|
596
|
+
|
597
|
+
|
598
|
+
*Continue* is exactly opposite of Skip and it continue with anonymization only if given condition returns true.
|
593
599
|
In case of blacklist records are anonymized for matching conditions and for whitelist records are anonymized and copied
|
594
|
-
to new database for matching conditions.
|
600
|
+
to new database for matching conditions.
|
595
601
|
|
596
602
|
```ruby
|
597
603
|
table 'customers' do
|
@@ -623,5 +629,3 @@ end
|
|
623
629
|
- [Dan Abel](http://www.linkedin.com/pub/dan-abel/0/61b/9b0) for introducing me to Blacklist and Whitelist approach for data anonymization.
|
624
630
|
- [Chirga Doshi](https://twitter.com/chiragsdoshi) for encouraging me to get this done.
|
625
631
|
- [Aditya Karle](https://twitter.com/adityakarle) for the Logo. (Coming Soon...)
|
626
|
-
|
627
|
-
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'data-anonymization'
|
2
|
-
|
3
2
|
require 'mongo'
|
4
|
-
Mongo::Connection.from_uri("mongodb://localhost/test").drop_database('test')
|
5
|
-
system "mongoimport -d test --drop -c users --jsonArray ./sample-data/mongo/users.json"
|
6
|
-
system "mongoimport -d test --drop -c plans --jsonArray ./sample-data/mongo/plans.json"
|
7
3
|
|
8
4
|
DataAnon::Utils::Logging.logger.level = Logger::INFO
|
5
|
+
Mongo::Logger.logger.level = Logger::WARN
|
6
|
+
|
7
|
+
Mongo::Client.new("mongodb://localhost/test").database.drop
|
8
|
+
system "mongoimport --host=127.0.0.1 -d test --drop -c users --jsonArray ./sample-data/mongo/users.json"
|
9
|
+
system "mongoimport --host=127.0.0.1 -d test --drop -c plans --jsonArray ./sample-data/mongo/plans.json"
|
10
|
+
|
9
11
|
|
10
12
|
database 'test' do
|
11
13
|
strategy DataAnon::Strategy::MongoDB::Blacklist
|
@@ -21,7 +23,7 @@ database 'test' do
|
|
21
23
|
end
|
22
24
|
|
23
25
|
collection 'plans' do
|
24
|
-
anonymize('plan_aliases').using FieldStrategy::AnonymizeArray.new(FieldStrategy::SelectFromList.new(
|
26
|
+
anonymize('plan_aliases').using FieldStrategy::AnonymizeArray.new(FieldStrategy::SelectFromList.new(%w(Free Team Business Paid)))
|
25
27
|
anonymize 'public_sharing','photo_sharing'
|
26
28
|
|
27
29
|
document 'features' do
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'data-anonymization'
|
2
|
-
|
3
2
|
require 'mongo'
|
4
|
-
Mongo::Connection.from_uri("mongodb://localhost/test").drop_database('test')
|
5
|
-
Mongo::Connection.from_uri("mongodb://localhost/dest").drop_database('dest')
|
6
|
-
system "mongoimport -d test --drop -c users --jsonArray ./sample-data/mongo/users.json"
|
7
|
-
system "mongoimport -d test --drop -c plans --jsonArray ./sample-data/mongo/plans.json"
|
8
3
|
|
9
4
|
DataAnon::Utils::Logging.logger.level = Logger::INFO
|
5
|
+
Mongo::Logger.logger.level = Logger::WARN
|
6
|
+
|
7
|
+
|
8
|
+
Mongo::Client.new("mongodb://localhost/test").database.drop
|
9
|
+
Mongo::Client.new("mongodb://localhost/dest").database.drop
|
10
|
+
system "mongoimport --host=127.0.0.1 -d test --drop -c users --jsonArray ./sample-data/mongo/users.json"
|
11
|
+
system "mongoimport --host=127.0.0.1 -d test --drop -c plans --jsonArray ./sample-data/mongo/plans.json"
|
10
12
|
|
11
13
|
database 'test' do
|
12
14
|
strategy DataAnon::Strategy::MongoDB::Whitelist
|
@@ -26,7 +28,7 @@ database 'test' do
|
|
26
28
|
|
27
29
|
collection 'plans' do
|
28
30
|
whitelist '_id', 'name','term', 'created_at'
|
29
|
-
anonymize('plan_aliases').using FieldStrategy::AnonymizeArray.new(FieldStrategy::SelectFromList.new(
|
31
|
+
anonymize('plan_aliases').using FieldStrategy::AnonymizeArray.new(FieldStrategy::SelectFromList.new(%w(Free Team Business Paid)))
|
30
32
|
anonymize 'public_sharing','photo_sharing'
|
31
33
|
|
32
34
|
collection 'features' do
|
data/examples/whitelist_dsl.rb
CHANGED
@@ -29,6 +29,7 @@ database 'Chinook' do
|
|
29
29
|
table 'Customer' do
|
30
30
|
primary_key 'CustomerId'
|
31
31
|
batch_size 5 # batch_size works only if the primary_key is defined for the table
|
32
|
+
limit 10 # will only take last 10 records
|
32
33
|
|
33
34
|
whitelist 'CustomerId', 'SupportRepId', 'Company'
|
34
35
|
anonymize('Phone').using FieldStrategy::RandomPhoneNumber.new
|
@@ -64,4 +65,3 @@ database 'Chinook' do
|
|
64
65
|
|
65
66
|
|
66
67
|
end
|
67
|
-
|
data/lib/strategy/base.rb
CHANGED
@@ -33,6 +33,10 @@ module DataAnon
|
|
33
33
|
@batch_size = size
|
34
34
|
end
|
35
35
|
|
36
|
+
def limit limit
|
37
|
+
@limit = limit
|
38
|
+
end
|
39
|
+
|
36
40
|
def whitelist *fields
|
37
41
|
fields.each { |f| @fields[f] = DataAnon::Strategy::Field::Whitelist.new }
|
38
42
|
end
|
@@ -98,7 +102,8 @@ module DataAnon
|
|
98
102
|
|
99
103
|
def process_table progress
|
100
104
|
index = 0
|
101
|
-
|
105
|
+
|
106
|
+
source_table_limited.each do |record|
|
102
107
|
index += 1
|
103
108
|
begin
|
104
109
|
process_record_if index, record
|
@@ -112,7 +117,8 @@ module DataAnon
|
|
112
117
|
def process_table_in_batches progress
|
113
118
|
logger.info "Processing table #{@name} records in batch size of #{@batch_size}"
|
114
119
|
index = 0
|
115
|
-
|
120
|
+
|
121
|
+
source_table_limited.find_each(:batch_size => @batch_size) do |record|
|
116
122
|
index += 1
|
117
123
|
begin
|
118
124
|
process_record_if index, record
|
@@ -123,6 +129,16 @@ module DataAnon
|
|
123
129
|
end
|
124
130
|
end
|
125
131
|
|
132
|
+
def source_table_limited
|
133
|
+
@source_table_limited ||= begin
|
134
|
+
if @limit.present?
|
135
|
+
source_table.all.limit(@limit).order(created_at: :desc)
|
136
|
+
else
|
137
|
+
source_table.all
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
126
142
|
def process_record_if index, record
|
127
143
|
return if @skip_block && @skip_block.call(index, record)
|
128
144
|
return if @continue_block && !@continue_block.call(index, record)
|
@@ -141,4 +157,4 @@ module DataAnon
|
|
141
157
|
|
142
158
|
end
|
143
159
|
end
|
144
|
-
end
|
160
|
+
end
|
@@ -8,7 +8,8 @@ module DataAnon
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def process_record index, document
|
11
|
-
|
11
|
+
anonymized_document = anonymize_document(document, index, @fields)
|
12
|
+
source_collection.find({'_id' => anonymized_document['_id']}).update_one(anonymized_document)
|
12
13
|
end
|
13
14
|
|
14
15
|
def anonymize_document document, index, field_strategies = {}
|
@@ -23,7 +23,7 @@ module DataAnon
|
|
23
23
|
|
24
24
|
def mongo_collection(database)
|
25
25
|
options = database[:options] || {}
|
26
|
-
Mongo::
|
26
|
+
Mongo::Client.new(database[:mongodb_uri], options).database.collection(@name)
|
27
27
|
end
|
28
28
|
|
29
29
|
def dest_collection
|
@@ -39,7 +39,7 @@ module DataAnon
|
|
39
39
|
alias :dest_table :dest_collection
|
40
40
|
|
41
41
|
def process_record index, document
|
42
|
-
dest_collection.
|
42
|
+
dest_collection.insert_one anonymize_document(document, index, @fields)
|
43
43
|
end
|
44
44
|
|
45
45
|
def anonymize_document document, index, field_strategies = {}
|
data/lib/version.rb
CHANGED
@@ -4,7 +4,7 @@ require 'mongo'
|
|
4
4
|
describe "End 2 End MongoDB Blacklist Acceptance Test" do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
Mongo::
|
7
|
+
Mongo::Client.new("mongodb://localhost/test").database().drop()
|
8
8
|
users = [
|
9
9
|
{
|
10
10
|
"_id" => 1,
|
@@ -36,8 +36,8 @@ describe "End 2 End MongoDB Blacklist Acceptance Test" do
|
|
36
36
|
"alternate_emails" => ["abc@test.com","abc2@test.com"]
|
37
37
|
}
|
38
38
|
]
|
39
|
-
users_coll = Mongo::
|
40
|
-
users.each { |p| users_coll.
|
39
|
+
users_coll = Mongo::Client.new("mongodb://localhost/test").database().collection('users')
|
40
|
+
users.each { |p| users_coll.insert_one p }
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should anonymize plans collection" do
|
@@ -58,9 +58,9 @@ describe "End 2 End MongoDB Blacklist Acceptance Test" do
|
|
58
58
|
|
59
59
|
end
|
60
60
|
|
61
|
-
users_coll = Mongo::
|
62
|
-
users_coll.count.should be 2
|
63
|
-
user = users_coll.
|
61
|
+
users_coll = Mongo::Client.new("mongodb://localhost/test").database().collection('users')
|
62
|
+
users_coll.find.count.to_int.should be 2
|
63
|
+
user = users_coll.find({'_id' => 1}).to_a[0]
|
64
64
|
|
65
65
|
user['_id'].should == 1
|
66
66
|
user['USER_ID'].should == "user-1"
|
@@ -4,8 +4,8 @@ require 'mongo'
|
|
4
4
|
describe "End 2 End MongoDB Whitelist Acceptance Test" do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
Mongo::
|
8
|
-
Mongo::
|
7
|
+
Mongo::Client.new("mongodb://localhost/test").database.drop
|
8
|
+
Mongo::Client.new("mongodb://localhost/dest").database.drop
|
9
9
|
plans = [
|
10
10
|
{
|
11
11
|
"_id" => 1,
|
@@ -50,20 +50,20 @@ describe "End 2 End MongoDB Whitelist Acceptance Test" do
|
|
50
50
|
"created_at" => Time.new(2012, 8, 11, 13, 1, 0)
|
51
51
|
}
|
52
52
|
]
|
53
|
-
plans_coll =
|
54
|
-
plans.each { |p| plans_coll.
|
53
|
+
plans_coll = Mongo::Client.new("mongodb://localhost/test").database.collection('plans')
|
54
|
+
plans.each { |p| plans_coll.insert_one p }
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should anonymize plans collection" do
|
58
58
|
|
59
|
-
database '
|
59
|
+
database 'dest' do
|
60
60
|
strategy DataAnon::Strategy::MongoDB::Whitelist
|
61
61
|
source_db :mongodb_uri => "mongodb://localhost/test", :database => 'test'
|
62
62
|
destination_db :mongodb_uri => "mongodb://localhost/dest", :database => 'dest'
|
63
63
|
|
64
64
|
collection 'plans' do
|
65
65
|
whitelist '_id', 'name', 'term', 'created_at'
|
66
|
-
anonymize('plan_aliases').using FieldStrategy::SelectFromList.new(
|
66
|
+
anonymize('plan_aliases').using FieldStrategy::SelectFromList.new(%w(Free Team Business Paid))
|
67
67
|
anonymize 'public_sharing', 'photo_sharing'
|
68
68
|
|
69
69
|
collection 'features' do
|
@@ -78,9 +78,9 @@ describe "End 2 End MongoDB Whitelist Acceptance Test" do
|
|
78
78
|
|
79
79
|
end
|
80
80
|
|
81
|
-
plans_coll = Mongo::
|
82
|
-
plans_coll.count.should be 2
|
83
|
-
plan = plans_coll.
|
81
|
+
plans_coll = Mongo::Client.new("mongodb://localhost/dest").database.collection('plans')
|
82
|
+
plans_coll.find.count.to_int.should be 2
|
83
|
+
plan = plans_coll.find({ '_id' => 1}).to_a[0]
|
84
84
|
|
85
85
|
plan['_id'].should == 1
|
86
86
|
plan['name'].should == "Free"
|
@@ -99,7 +99,7 @@ describe "End 2 End MongoDB Whitelist Acceptance Test" do
|
|
99
99
|
[true,false].should include(feature1['users']['additional'])
|
100
100
|
|
101
101
|
|
102
|
-
plan = plans_coll.
|
102
|
+
plan = plans_coll.find({ '_id' => 2}).to_a[0]
|
103
103
|
plan['plan_aliases'].length.should == 2
|
104
104
|
["Free", "Team", "Business", "Paid"].should include(plan['plan_aliases'][0])
|
105
105
|
["Free", "Team", "Business", "Paid"].should include(plan['plan_aliases'][1])
|
@@ -6,7 +6,7 @@ describe 'End 2 End RDBMS Blacklist Acceptance Test using SQLite database' do
|
|
6
6
|
before(:each) do
|
7
7
|
CustomerSample.clean
|
8
8
|
CustomerSample.create_schema connection_spec
|
9
|
-
CustomerSample.insert_record connection_spec, CustomerSample::SAMPLE_DATA
|
9
|
+
CustomerSample.insert_record connection_spec, CustomerSample::SAMPLE_DATA[0]
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should anonymize customer table record ' do
|
@@ -24,7 +24,7 @@ describe 'End 2 End RDBMS Blacklist Acceptance Test using SQLite database' do
|
|
24
24
|
|
25
25
|
DataAnon::Utils::SourceDatabase.establish_connection connection_spec
|
26
26
|
source = DataAnon::Utils::SourceTable.create 'customers', ['cust_id']
|
27
|
-
new_rec = source.find(CustomerSample::SAMPLE_DATA[:cust_id])
|
27
|
+
new_rec = source.find(CustomerSample::SAMPLE_DATA[0][:cust_id])
|
28
28
|
new_rec['email'].should == 'test+1@gmail.com'
|
29
29
|
|
30
30
|
end
|
@@ -45,7 +45,7 @@ describe 'End 2 End RDBMS Blacklist Acceptance Test using SQLite database' do
|
|
45
45
|
|
46
46
|
DataAnon::Utils::SourceDatabase.establish_connection connection_spec
|
47
47
|
source = DataAnon::Utils::SourceTable.create 'customers', ['cust_id']
|
48
|
-
new_rec = source.find(CustomerSample::SAMPLE_DATA[:cust_id])
|
48
|
+
new_rec = source.find(CustomerSample::SAMPLE_DATA[0][:cust_id])
|
49
49
|
new_rec['email'].should_not == 'test+1@gmail.com'
|
50
50
|
|
51
51
|
end
|
@@ -66,10 +66,10 @@ describe 'End 2 End RDBMS Blacklist Acceptance Test using SQLite database' do
|
|
66
66
|
|
67
67
|
DataAnon::Utils::SourceDatabase.establish_connection connection_spec
|
68
68
|
source = DataAnon::Utils::SourceTable.create 'customers', ['cust_id']
|
69
|
-
new_rec = source.find(CustomerSample::SAMPLE_DATA[:cust_id])
|
69
|
+
new_rec = source.find(CustomerSample::SAMPLE_DATA[0][:cust_id])
|
70
70
|
new_rec['email'].should == 'test+1@gmail.com'
|
71
71
|
|
72
72
|
|
73
73
|
|
74
74
|
end
|
75
|
-
end
|
75
|
+
end
|
@@ -8,7 +8,7 @@ describe 'End 2 End RDBMS Whitelist Acceptance Test using SQLite database' do
|
|
8
8
|
before(:each) do
|
9
9
|
CustomerSample.clean
|
10
10
|
CustomerSample.create_schema source_connection_spec
|
11
|
-
CustomerSample.
|
11
|
+
CustomerSample.insert_records source_connection_spec, CustomerSample::SAMPLE_DATA
|
12
12
|
|
13
13
|
CustomerSample.create_schema dest_connection_spec
|
14
14
|
end
|
@@ -35,7 +35,8 @@ describe 'End 2 End RDBMS Whitelist Acceptance Test using SQLite database' do
|
|
35
35
|
|
36
36
|
DataAnon::Utils::DestinationDatabase.establish_connection dest_connection_spec
|
37
37
|
dest_table = DataAnon::Utils::DestinationTable.create 'customers'
|
38
|
-
|
38
|
+
dest_table.count.should == 2
|
39
|
+
new_rec = dest_table.where('cust_id' => CustomerSample::SAMPLE_DATA[0][:cust_id]).first
|
39
40
|
new_rec.first_name.should_not be('Sunit')
|
40
41
|
new_rec.last_name.should_not be('Parekh')
|
41
42
|
new_rec.birth_date.should_not be(Date.new(1977,7,8))
|
@@ -52,4 +53,24 @@ describe 'End 2 End RDBMS Whitelist Acceptance Test using SQLite database' do
|
|
52
53
|
new_rec.updated_at.should == Time.new(2010,5,5)
|
53
54
|
end
|
54
55
|
|
56
|
+
describe 'limiting' do
|
57
|
+
it 'returns only last record' do
|
58
|
+
database 'Customer' do
|
59
|
+
strategy DataAnon::Strategy::Whitelist
|
60
|
+
source_db source_connection_spec
|
61
|
+
destination_db dest_connection_spec
|
62
|
+
|
63
|
+
table 'customers' do
|
64
|
+
limit 1
|
65
|
+
whitelist 'cust_id', 'first_name', 'created_at','updated_at'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
DataAnon::Utils::DestinationDatabase.establish_connection dest_connection_spec
|
70
|
+
dest_table = DataAnon::Utils::DestinationTable.create 'customers'
|
71
|
+
dest_table.count.should == 1
|
72
|
+
new_rec = dest_table.first
|
73
|
+
new_rec.first_name.should eq('Rohit')
|
74
|
+
end
|
75
|
+
end
|
55
76
|
end
|
@@ -8,7 +8,7 @@ describe "End 2 End RDBMS Whitelist Acceptance Test using SQLite database" do
|
|
8
8
|
before(:each) do
|
9
9
|
CustomerSample.clean
|
10
10
|
CustomerSample.create_schema source_connection_spec
|
11
|
-
CustomerSample.insert_record source_connection_spec, CustomerSample::SAMPLE_DATA
|
11
|
+
CustomerSample.insert_record source_connection_spec, CustomerSample::SAMPLE_DATA[0]
|
12
12
|
|
13
13
|
CustomerSample.create_schema dest_connection_spec
|
14
14
|
end
|
@@ -37,7 +37,7 @@ describe "End 2 End RDBMS Whitelist Acceptance Test using SQLite database" do
|
|
37
37
|
|
38
38
|
DataAnon::Utils::DestinationDatabase.establish_connection dest_connection_spec
|
39
39
|
dest_table = DataAnon::Utils::DestinationTable.create 'customers'
|
40
|
-
new_rec = dest_table.where("cust_id" => CustomerSample::SAMPLE_DATA[:cust_id]).first
|
40
|
+
new_rec = dest_table.where("cust_id" => CustomerSample::SAMPLE_DATA[0][:cust_id]).first
|
41
41
|
new_rec.first_name.should_not be("Sunit")
|
42
42
|
new_rec.last_name.should_not be("Parekh")
|
43
43
|
new_rec.birth_date.should_not be(Date.new(1977,7,8))
|
@@ -52,4 +52,4 @@ describe "End 2 End RDBMS Whitelist Acceptance Test using SQLite database" do
|
|
52
52
|
new_rec.longitude.should be_between( -84.044636, -64.044636)
|
53
53
|
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,7 @@ ENV['show_progress'] = 'false'
|
|
11
11
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
12
|
|
13
13
|
DataAnon::Utils::Logging.logger.level = Logger::WARN
|
14
|
+
Mongo::Logger.logger.level = Logger::WARN
|
14
15
|
|
15
16
|
RSpec.configure do |config|
|
16
17
|
config.expect_with :rspec do |c|
|
@@ -20,7 +20,7 @@ class CustomerSample
|
|
20
20
|
t.float :latitude
|
21
21
|
t.float :longitude
|
22
22
|
|
23
|
-
t.timestamps null:
|
23
|
+
t.timestamps null: false
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -36,14 +36,26 @@ class CustomerSample
|
|
36
36
|
CreateCustomer.migrate :up
|
37
37
|
end
|
38
38
|
|
39
|
-
SAMPLE_DATA =
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
SAMPLE_DATA = [
|
40
|
+
{
|
41
|
+
:cust_id => 100, :first_name => "Sunit", :last_name => "Parekh",
|
42
|
+
:birth_date => Date.new(1977,7,8), :address => "F 501 Shanti Nagar",
|
43
|
+
:state => "Maharastra", :zipcode => "411048", :phone => "9923700662",
|
44
|
+
:email => "parekh.sunit@gmail.com", :terms_n_condition => true,
|
45
|
+
:age => 34, :longitude => -74.044636, :latitude => +40.689060,
|
46
|
+
:created_at => Time.new(2010,10,10), :updated_at => Time.new(2010,5,5)
|
47
|
+
},
|
48
|
+
{
|
49
|
+
:cust_id => 101, :first_name => "Rohit", :last_name => "Parekh",
|
50
|
+
:birth_date => Date.new(1977,7,8), :address => "F 501 Shanti Nagar",
|
51
|
+
:state => "Maharastra", :zipcode => "411048", :phone => "9923700662",
|
52
|
+
:email => "parekh.sunit@gmail.com", :terms_n_condition => true,
|
53
|
+
:age => 34, :longitude => -74.044636, :latitude => +40.689060,
|
54
|
+
:created_at => Time.now, :updated_at => Time.now
|
55
|
+
}
|
56
|
+
]
|
45
57
|
|
46
|
-
def self.insert_record connection_spec, data_hash = SAMPLE_DATA
|
58
|
+
def self.insert_record connection_spec, data_hash = SAMPLE_DATA[0]
|
47
59
|
DataAnon::Utils::TempDatabase.establish_connection connection_spec
|
48
60
|
source = DataAnon::Utils::BaseTable.create_table DataAnon::Utils::TempDatabase, 'customers', 'cust_id'
|
49
61
|
cust = source.new data_hash
|
@@ -51,4 +63,13 @@ class CustomerSample
|
|
51
63
|
cust.save!
|
52
64
|
end
|
53
65
|
|
54
|
-
|
66
|
+
def self.insert_records connection_spec, data_hash = SAMPLE_DATA
|
67
|
+
DataAnon::Utils::TempDatabase.establish_connection connection_spec
|
68
|
+
source = DataAnon::Utils::BaseTable.create_table DataAnon::Utils::TempDatabase, 'customers', 'cust_id'
|
69
|
+
data_hash.each do |data_row|
|
70
|
+
cust = source.new data_row
|
71
|
+
cust.cust_id = data_row[:cust_id]
|
72
|
+
cust.save!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data-anonymization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sunit Parekh
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-10-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -311,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
311
311
|
version: '0'
|
312
312
|
requirements: []
|
313
313
|
rubyforge_project:
|
314
|
-
rubygems_version: 2.4.
|
314
|
+
rubygems_version: 2.4.8
|
315
315
|
signing_key:
|
316
316
|
specification_version: 4
|
317
317
|
summary: Tool to create anonymized production data dump to use for PREF and other
|