module Configliere::EncryptedParam

Public Instance Methods

resolve!() click to toggle source

decrypts any encrypted params then calls the next step in the resolve! chain.

Calls superclass method
# File lib/configliere/encrypted.rb, line 7
def resolve!
  resolve_encrypted!
  super()
  self
end
resolve_encrypted!() click to toggle source

import values, decrypting all params marked as encrypted

# File lib/configliere/encrypted.rb, line 14
def resolve_encrypted!
  remove_and_adopt_encrypt_pass_param_if_any!
  encrypted_params.each do |param|
    encrypted_val = deep_delete(*encrypted_key_path(param)) or next
    self[param] = self.decrypted(encrypted_val)
  end
end

Protected Instance Methods

decrypted(val) click to toggle source
# File lib/configliere/encrypted.rb, line 62
def decrypted val
  return val.to_s if val.to_s.empty?
  Configliere::Crypter.decrypt(val, @encrypt_pass)
end
encrypted(val) click to toggle source
# File lib/configliere/encrypted.rb, line 67
def encrypted val
  return unless val
  Configliere::Crypter.encrypt(val, @encrypt_pass)
end
encrypted_key_path(param) click to toggle source

the chain of symbol keys for a dotted path key, prefixing the last one with “encrypted_”

@example

encrypted_key_path('amazon.api.key')
#=> [:amazon, :api, :encrypted_key]
# File lib/configliere/encrypted.rb, line 51
def encrypted_key_path param
  encrypted_path = Array(convert_key(param))
  encrypted_path[-1] = "encrypted_#{encrypted_path.last}".to_sym
  encrypted_path
end
encrypted_params() click to toggle source

list of all params to encrypt on serialization

# File lib/configliere/encrypted.rb, line 58
def encrypted_params
  params_with(:encrypted).keys.select{|p| definition_of(p, :encrypted) }
end
export() click to toggle source

@example

Settings.defaults :username=>"mysql_username", :password=>"mysql_password"
Settings.define :password, :encrypted => true
Settings.export
  #=> {:username => 'mysql_username', :password=>"\345?r`\222\021"\210\312\331\256\356\351\037\367\326" }
Calls superclass method
# File lib/configliere/encrypted.rb, line 29
def export
  remove_and_adopt_encrypt_pass_param_if_any!
  hsh = super()
  encrypted_params.each do |param|
    val = hsh.deep_delete(*convert_key(param)) or next
    hsh.deep_set( *(encrypted_key_path(param) | [encrypted(val)]) )
  end
  hsh
end
remove_and_adopt_encrypt_pass_param_if_any!() click to toggle source

if :encrypted_pass was set as a param, remove it from the hash and set it as an attribute

# File lib/configliere/encrypted.rb, line 40
def remove_and_adopt_encrypt_pass_param_if_any!
  @encrypt_pass ||= self.delete(:encrypt_pass) if self[:encrypt_pass]
  @encrypt_pass ||= ENV['ENCRYPT_PASS']        if ENV['ENCRYPT_PASS']
end