Files
ubicloud/model/storage_key_encryption_key.rb
Burak Yucesoy 6157fe829d Simplify UBID usage in models
Previously, to enable UBIDs, one would need to define ubid_type function in the
each respective model file. However, this function works same for each model;
the difference is it returns different constant. With some string manipulation,
it is possible to generate the name of the constant. Sequel and we already use
similar inflictions to make things feel more "magical", so I don't have much
concerns regarding generating constant names via string manipulation.

Thanks to this commit, we don't need to define ubid_type for each model anymore.
Similarly we also don't need to add new type to when/case block in ubid.rb

While doing this, I found two unused constants and removed them. Also slightly
modified two other constants' names to match it with the class names.

Finally, as a small bonus, we reduced the line count by 77 and unit tests now
complete 0.2 seconds faster. Possibly due to removing long when/case block.
2023-07-25 11:04:26 +03:00

25 lines
553 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class StorageKeyEncryptionKey < Sequel::Model
plugin :column_encryption do |enc|
enc.column :key
enc.column :init_vector
end
include ResourceMethods
def secret_key_material_hash
# default to_hash doesn't decrypt encrypted columns, so implement
# this to decrypt keys when they need to be sent to a running copy
# of spdk.
{
"key" => key,
"init_vector" => init_vector,
"algorithm" => algorithm,
"auth_data" => auth_data
}
end
end