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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ef5d00b5940a40440f302133dffa2b364b73a86
4
- data.tar.gz: b970e5a37fbf0b68aa52b7a61f7197fdf008d896
3
+ metadata.gz: 5889640818fefd09ba8da7d2913101709824eb70
4
+ data.tar.gz: 84db0216fc606c8f566c9e7fb144fff8e9eb4761
5
5
  SHA512:
6
- metadata.gz: 9f5c68d2c32a9785209e2138ed795311d103cfa8071fae65875d6a0f1cc9e73b76e0b71a31252b043857ccf9d1a6107c297265a93dbaba36dcd9c64feaa05ac4
7
- data.tar.gz: 4ccbbe113dd32f9a9d50aff1e6c2a41a049ebf1afc1be7e54841076d2ce8f292e0d3c037d4e712dda5db10dfd60cff68993b2a8c19ee6c89ea026d48d2edb035
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
- add_secure_field(field_name, args)
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
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Kms
3
- VERSION = "0.0.20"
3
+ VERSION = "0.0.21"
4
4
  end
5
5
  end
@@ -56,8 +56,6 @@ describe Mongoid::Kms do
56
56
  o = ExtendedClass.new(super_secure: "batman", unsecure: "robin", timestamp: Time.now, additional_secure: "wha!")
57
57
  o.save!
58
58
 
59
- byebug
60
-
61
59
  o = ExtendedClass.find(o.id)
62
60
  expect(o.additional_secure).to eq("wha!")
63
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-kms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Winslett