12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/portunus/rotators/dek.rb', line 12
def rotate
encryptable = data_encryption_key.encryptable
if encryptable.blank?
Rails.logger.debug("Dek id: #{data_encryption_key.id} is missing it's encryptable... deleting")
data_encryption_key.destroy
return true
end
Rails.logger.debug(
"Rotating Encryptable: #{encryptable.class}, id: #{encryptable.id}"
)
ActiveRecord::Base.transaction do
encryptable.class.encrypted_fields_list.map do |field_name|
field_value_map[field_name.to_sym] = encryptable.send(field_name.to_sym)
end
data_encryption_key.update(encrypted_key: new_encrypted_key)
encryptable.data_encryption_key.reload
field_value_map.map do |field_name, value|
encryptable.send("#{field_name}=".to_sym, value)
end
encryptable.save
data_encryption_key.update(last_dek_rotation: DateTime.now)
end
true
rescue StandardError => error
raise ::Portunus::Error.new(
"Rotating DEK failed: #{error.full_message}"
)
end
|