Class: EncryptedYaml::Configurator

Inherits:
Hash
  • Object
show all
Defined in:
lib/encrypted_yaml/configurator.rb

Overview

represents an encrypted YAML file as a Hash

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ Configurator

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

Returns a new instance of Configurator.

Parameters:

  • filename (String)

    path to the encrypted

  • options (Hash) (defaults to: {})

    optional settings for how to find the key and iv

Options Hash (options):

  • :key (String)

    the encryption key (as a string blob)

  • :iv (String)

    the encryption iv (as a string blob)

  • :keyfile (String)

    path to the key file

  • :ivfile (String)

    path to the iv file



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Method Details

#reload_configEncryptedConfig::Configurator

Note:

does not reload the key or iv

returns a new copy with the current values in the configuration file

Returns:

  • (EncryptedConfig::Configurator)

    new copy with the config file reloaded



39
40
41
42
43
44
# File 'lib/encrypted_yaml/configurator.rb', line 39

def reload_config
  EncryptedYaml::Configurator.new(@filename, {
    :key      => @key,
    :iv       => @iv
  })
end

#reload_config!Object

Note:

does not reload the key or iv

reloads the configuration file



48
49
50
51
# File 'lib/encrypted_yaml/configurator.rb', line 48

def reload_config!
  self.clear
  load_config
end