lib/simple_deploy/configuration.rb in simple_deploy-0.9.2 vs lib/simple_deploy/configuration.rb in simple_deploy-0.10.0.beta.1
- old
+ new
@@ -2,32 +2,60 @@
module SimpleDeploy
module Configuration
extend self
def configure(environment, custom_config = {})
- raw_config = custom_config.fetch(:config) { load_config_file }
- Config.new raw_config['environments'][environment],
- raw_config['notifications']
+ if custom_config.has_key?(:config)
+ env_config = custom_config[:config]['environments'][environment]
+ notifications = custom_config[:config]['notifications']
+ else
+ env_config, notifications = load_appropriate_config(environment)
+ end
+ Config.new env_config, notifications
end
def environments(custom_config = {})
raw_config = custom_config.fetch(:config) { load_config_file }
raw_config['environments']
end
private
+ def load_appropriate_config(env)
+ if env == :read_from_env
+ load_config_from_env_vars
+ else
+ load_config_from_file env
+ end
+ end
+
def load_config_file
begin
YAML::load File.open(config_file)
rescue Errno::ENOENT
raise "#{config_file} not found"
rescue ArgumentError, Psych::SyntaxError => e
raise "#{config_file} is corrupt"
end
end
+ def load_config_from_file(env)
+ config = load_config_file
+ return config['environments'][env], config['notifications']
+ end
+
+ def load_config_from_env_vars
+ env_config = {
+ 'access_key' => ENV['AWS_ACCESS_KEY_ID'],
+ 'region' => ENV['AWS_REGION'],
+ 'secret_key' => ENV['AWS_SECRET_ACCESS_KEY'],
+ 'security_token' => ENV['AWS_SECURITY_TOKEN']
+ }
+
+ return env_config, {}
+ end
+
def config_file
env_config_file || default_config_file
end
def env_config_file
@@ -80,23 +108,30 @@
def secret_key
@environment['secret_key']
end
+ def security_token
+ @environment['security_token']
+ end
+
def region
@environment['region']
end
+ def temporary_credentials?
+ !!security_token
+ end
+
private
def env_home
env.load 'HOME'
end
def env_user
env.load 'USER'
end
-
end
end
end