class EncryptedYaml::Configurator

represents an encrypted YAML file as a Hash

Public Class Methods

new(filename, options = {}) click to toggle source

@note The options param has some sane defaults:

* for both key and iv, it will prefer the string blob over the filename
* if neither the key/iv or filename is defined, it will default to a file named 'key' or 'iv'
  in the current directory

@param [String] filename path to the encrypted @param [Hash] options optional settings for how to find the key and iv @option options [String] :key the encryption key (as a string blob) @option options [String] :iv the encryption iv (as a string blob) @option options [String] :keyfile path to the key file @option options [String] :ivfile path to the iv file

# File lib/encrypted_yaml/configurator.rb, line 17
def initialize(filename, options = {})
  @key = if options[:key]
           options[:key]
         else
           keyfile = options[:keyfile] || File.dirname(filename) + '/key'
           File.read keyfile
         end
  
  @iv = if options[:iv]
          options[:iv]
        else
          ivfile = options[:ivfile] || File.dirname(filename) + '/iv'
          File.read ivfile
        end
  
  @filename = filename      
  load_config
end

Public Instance Methods

reload_config() click to toggle source

returns a new copy with the current values in the configuration file @note does not reload the key or iv @return [EncryptedConfig::Configurator] new copy with the config file reloaded

# File lib/encrypted_yaml/configurator.rb, line 39
def reload_config
  EncryptedYaml::Configurator.new(@filename, {
    :key      => @key,
    :iv       => @iv
  })
end
reload_config!() click to toggle source

reloads the configuration file @note does not reload the key or iv

# File lib/encrypted_yaml/configurator.rb, line 48
def reload_config!
  self.clear
  load_config
end

Private Instance Methods

load_config() click to toggle source
# File lib/encrypted_yaml/configurator.rb, line 55
def load_config
  encrypted_data = File.read @filename
  decrypt = EncryptedYaml::Decrypt.new(@key, @iv)
  data = decrypt.decrypt encrypted_data
  self.replace YAML.load(data)
end