mongoid-kms 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid/kms.rb +28 -38
- data/lib/mongoid/kms/version.rb +1 -1
- data/spec/lib/mongoid/kms_spec.rb +0 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5889640818fefd09ba8da7d2913101709824eb70
|
4
|
+
data.tar.gz: 84db0216fc606c8f566c9e7fb144fff8e9eb4761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd89f03c35e0689906b6e7db35bf41012f784b701b8f5ba6182d3b4cc79e9f33e0567a3c994425a1b56912f1d0c25d50fd6497cf20b37cbfc2f488033a1d790
|
7
|
+
data.tar.gz: 432fd44f6222d35eed8b2491701b5426981869424b5dad7ac978cf3763f30851333e64e6bb40faca6e1a795b0e2503add1153bd6f3fbc5f06218d2c03a4c1bc4
|
data/lib/mongoid/kms.rb
CHANGED
@@ -82,45 +82,9 @@ module Mongoid
|
|
82
82
|
module ClassMethods
|
83
83
|
def inherited(child)
|
84
84
|
child.kms_field_map = self.kms_field_map.clone
|
85
|
-
|
86
|
-
child.kms_field_map.each do |field_name, args|
|
87
|
-
child.add_secure_field(field_name, args)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def add_secure_field(field_name, args)
|
92
|
-
encrypted_field_name = get_encrypted_field_name(field_name)
|
93
|
-
|
94
|
-
define_attribute_methods field_name.to_sym
|
95
|
-
before_save :set_kms_values
|
96
|
-
|
97
|
-
kms_field_map[field_name.to_s] = {context: args.delete(:context), type: args[:type]}
|
98
|
-
|
99
|
-
field encrypted_field_name, type: Mongoid::Kms.bson_class::Binary
|
100
|
-
|
101
|
-
self.class_eval do
|
102
|
-
define_method(field_name) do
|
103
|
-
instance_variable_get("@#{field_name}") || begin
|
104
|
-
raw = send("kms_secure_#{field_name}")
|
105
|
-
|
106
|
-
if raw.nil?
|
107
|
-
raw
|
108
|
-
else
|
109
|
-
v = self.class.decrypt_field(self, field_name, raw)
|
110
|
-
instance_variable_set("@#{field_name}", v)
|
111
|
-
v
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
define_method("#{field_name}=") do |value|
|
117
|
-
self.send("#{field_name}_will_change!")
|
118
|
-
instance_variable_set("@#{field_name}", value)
|
119
|
-
end
|
120
|
-
end
|
85
|
+
super(child)
|
121
86
|
end
|
122
87
|
|
123
|
-
|
124
88
|
def encrypt_field(object, field_name, value)
|
125
89
|
Mongoid::Kms.kms.encrypt({
|
126
90
|
key_id: Mongoid::Kms.key,
|
@@ -178,7 +142,33 @@ module Mongoid
|
|
178
142
|
end
|
179
143
|
|
180
144
|
def secure_field(field_name, args)
|
181
|
-
|
145
|
+
encrypted_field_name = get_encrypted_field_name(field_name)
|
146
|
+
|
147
|
+
define_attribute_methods field_name.to_sym
|
148
|
+
before_save :set_kms_values
|
149
|
+
|
150
|
+
kms_field_map[field_name.to_s] = {context: args.delete(:context), type: args[:type]}
|
151
|
+
|
152
|
+
field encrypted_field_name, type: Mongoid::Kms.bson_class::Binary
|
153
|
+
|
154
|
+
define_method(field_name) do
|
155
|
+
instance_variable_get("@#{field_name}") || begin
|
156
|
+
raw = send("kms_secure_#{field_name}")
|
157
|
+
|
158
|
+
if raw.nil?
|
159
|
+
raw
|
160
|
+
else
|
161
|
+
v = self.class.decrypt_field(self, field_name, raw)
|
162
|
+
instance_variable_set("@#{field_name}", v)
|
163
|
+
v
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
define_method("#{field_name}=") do |value|
|
169
|
+
self.send("#{field_name}_will_change!")
|
170
|
+
instance_variable_set("@#{field_name}", value)
|
171
|
+
end
|
182
172
|
end
|
183
173
|
end
|
184
174
|
|
data/lib/mongoid/kms/version.rb
CHANGED