lib/rubber/environment.rb in rubber-2.1.2 vs lib/rubber/environment.rb in rubber-2.2.0
- old
+ new
@@ -1,9 +1,11 @@
require 'yaml'
require 'socket'
require 'delegate'
+require 'rubber/encryption'
+
module Rubber
module Configuration
# Contains the configuration defined in rubber.yml
# Handles selecting of correct config values based on
# the host/role passed into bind
@@ -26,26 +28,43 @@
env_yml = "#{@config_root}/rubber-#{Rubber.env}-env.yml"
@config_files << env_yml if File.exist?(env_yml)
@items = {}
@config_files.each { |file| read_config(file) }
- @config_secret = bind().rubber_secret
- read_config(@config_secret) if @config_secret
+
+ read_secret_config
end
def read_config(file)
Rubber.logger.debug{"Reading rubber configuration from #{file}"}
if File.exist?(file)
begin
- @items = Environment.combine(@items, YAML::load(ERB.new(IO.read(file)).result) || {})
+ data = IO.read(file)
+ data = yield(data) if block_given?
+ @items = Environment.combine(@items, YAML::load(ERB.new(data).result) || {})
rescue Exception => e
Rubber.logger.error{"Unable to read rubber configuration from #{file}"}
raise
end
end
end
+ def read_secret_config
+ bound = bind()
+ @config_secret = bound.rubber_secret
+ if @config_secret
+ obfuscation_key = bound.rubber_secret_key
+ if obfuscation_key
+ read_config(@config_secret) do |data|
+ Rubber::Encryption.decrypt(data, obfuscation_key)
+ end
+ else
+ read_config(@config_secret)
+ end
+ end
+ end
+
def known_roles
return @known_roles if @known_roles
roles = []
# all the roles known about in config directory
@@ -87,11 +106,11 @@
return new if old.nil?
value = old
if old.is_a?(Hash) && new.is_a?(Hash)
value = old.clone
new.each do |nk, nv|
- if nk[0] == '^'
+ if nk.to_s[0..0] == '^'
nk = nk[1..-1]
value[nk] = combine(nil, nv)
else
value[nk] = combine(value[nk], nv)
end
@@ -210,6 +229,6 @@
end
end
end
-end
\ No newline at end of file
+end