lib/symmetric_encryption/keystore/file.rb in symmetric-encryption-4.0.0 vs lib/symmetric_encryption/keystore/file.rb in symmetric-encryption-4.0.1
- old
+ new
@@ -4,19 +4,19 @@
attr_accessor :file_name, :key_encrypting_key
# Returns [Hash] initial configuration.
# Generates the encrypted key file for every environment except development and test.
def self.new_config(key_path: '/etc/symmetric-encryption',
- app_name: 'symmetric-encryption',
- environments: %i(development test release production),
- cipher_name: 'aes-256-cbc')
+ app_name: 'symmetric-encryption',
+ environments: %i[development test release production],
+ cipher_name: 'aes-256-cbc')
configs = {}
environments.each do |environment|
environment = environment.to_sym
configs[environment] =
- if %i(development test).include?(environment)
+ if %i[development test].include?(environment)
Keystore.dev_config
else
cfg = new_key_config(key_path: key_path, cipher_name: cipher_name, app_name: app_name, environment: environment)
{
ciphers: [cfg]
@@ -82,11 +82,11 @@
private
# Read from the file, raising an exception if it is not found
def read_from_file
- ::File.open(file_name, 'rb') { |f| f.read }
+ ::File.open(file_name, 'rb', &:read)
rescue Errno::ENOENT
raise(SymmetricEncryption::ConfigError, "Symmetric Encryption key file: '#{file_name}' not found or readable")
end
# Write to the supplied file_name, backing up the existing file if present
@@ -94,9 +94,8 @@
key_path = ::File.dirname(file_name)
::FileUtils.mkdir_p(key_path) unless ::File.directory?(key_path)
::File.rename(file_name, "#{file_name}.#{Time.now.to_i}") if ::File.exist?(file_name)
::File.open(file_name, 'wb') { |file| file.write(data) }
end
-
end
end
end