lib/symmetric_encryption/config.rb in symmetric-encryption-4.4.0 vs lib/symmetric_encryption/config.rb in symmetric-encryption-4.5.0

- old
+ new

@@ -25,11 +25,11 @@ true end # Reads the entire configuration for all environments from the supplied file name. def self.read_file(file_name) - config = YAML.load(ERB.new(File.new(file_name).read).result) + config = load_yaml(ERB.new(File.new(file_name).read).result) config = deep_symbolize_keys(config) config.each_pair { |_env, cfg| SymmetricEncryption::Config.send(:migrate_old_formats!, cfg) } config end @@ -73,11 +73,11 @@ def config @config ||= begin raise(ConfigError, "Cannot find config file: #{file_name}") unless File.exist?(file_name) - env_config = YAML.load(ERB.new(File.new(file_name).read).result)[env] + env_config = self.class.load_yaml(ERB.new(File.new(file_name).read).result)[env] raise(ConfigError, "Cannot find environment: #{env} in config file: #{file_name}") unless env_config env_config = self.class.send(:deep_symbolize_keys, env_config) self.class.send(:migrate_old_formats!, env_config) end @@ -161,7 +161,13 @@ end config end private_class_method :migrate_old_formats! + + def self.load_yaml(src) + return YAML.safe_load(src, permitted_classes: [Symbol], aliases: true) if Psych::VERSION.to_i >= 4 + + YAML.load(src) + end end end