tidus 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 982c186ae247f2768f5836f664786d27e0746267
|
4
|
+
data.tar.gz: 47adfce0419345aa46db2da66954a22a13eeb706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e64fd16e2f06d5238ef075e215a1eb97976c0153677f3ab96aa4cf3c7cefd5af86855d893bc4fbe08e398db5d3c5b13af3a30d8c53209c72f9df8bcb45c2c275
|
7
|
+
data.tar.gz: 7f77bbd00064728512bf6b999cf29b08817e7f74900582cd139592fc06800bae3f83b29df725cd3c6ae15866ea604773250b5682014319f8934017b3f37ea288
|
@@ -4,8 +4,14 @@ module Tidus
|
|
4
4
|
def self.anonymize(table_name, column_name, options = {})
|
5
5
|
name = "#{table_name}.#{column_name}"
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
# If options is edited on a deeper level .dup has to be replaced by marshal dump/load
|
8
|
+
options = options.dup
|
9
|
+
options[:result_type] ||= "text"
|
10
|
+
type = options[:result_type]
|
11
|
+
|
12
|
+
if options[:default] && options[:default_strategy]
|
13
|
+
raise "CondAnonymizer: Only one of default and default_strategy can be used"
|
14
|
+
end
|
9
15
|
|
10
16
|
if options[:conditions].blank?
|
11
17
|
raise "Missing option :conditions for CondAnonymizer on #{name}"
|
@@ -31,10 +37,31 @@ module Tidus
|
|
31
37
|
"'#{cond_value}'::#{cond_type}) THEN '#{cond_result}'::#{type} "
|
32
38
|
end
|
33
39
|
|
34
|
-
command += "ELSE #{default} END"
|
40
|
+
command += "ELSE #{self.default(table_name, column_name, options)} END"
|
35
41
|
|
36
42
|
return command
|
37
43
|
end
|
44
|
+
|
45
|
+
def self.default(table_name, column_name, options)
|
46
|
+
type = options[:result_type]
|
47
|
+
|
48
|
+
value = if options[:default_strategy]
|
49
|
+
klass = self.anonymizer(options[:default_strategy])
|
50
|
+
klass.anonymize(table_name, column_name, {})
|
51
|
+
elsif options[:default]
|
52
|
+
"'#{options[:default]}'::#{type}"
|
53
|
+
else
|
54
|
+
"#{table_name}.#{column_name}::#{type}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.anonymizer(name)
|
59
|
+
begin
|
60
|
+
klass = Kernel.const_get("Tidus::Postgresql::#{name.to_s.camelize}Anonymizer")
|
61
|
+
rescue NameError
|
62
|
+
raise "default_strategy '#{name}' not implemented for Postgresql"
|
63
|
+
end
|
64
|
+
end
|
38
65
|
end
|
39
66
|
end
|
40
|
-
end
|
67
|
+
end
|
@@ -2,18 +2,18 @@ module Tidus
|
|
2
2
|
module Postgresql
|
3
3
|
class TextAnonymizer
|
4
4
|
def self.anonymize(table_name, column_name, options = {})
|
5
|
-
base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZCßüäöÜÄÖ"
|
5
|
+
base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZCßüäöÜÄÖ0123456789"
|
6
6
|
return "translate((#{table_name}.#{column_name})::text, " +
|
7
7
|
"'#{base}'::text, '#{generate_mapping(base)}'::text)"
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
11
11
|
def self.generate_mapping(base)
|
12
|
-
|
12
|
+
upper_and_nums = ("A".."Z").to_a + ('0'..'9').to_a
|
13
13
|
lower = ("a".."z").to_a
|
14
14
|
result = base.split("").map do |letter|
|
15
15
|
if letter == letter.upcase
|
16
|
-
|
16
|
+
upper_and_nums.sample
|
17
17
|
else
|
18
18
|
lower.sample
|
19
19
|
end
|
@@ -22,4 +22,4 @@ module Tidus
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
data/lib/tidus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Schoknecht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.2.2
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: Gem for creating anonymization views.
|