Sha256: ec91060d751e50658a082fd9d47a9bd5f7de539081d34a10577bd8a113d14e67
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
module CloudstackClient require "yaml" module Configuration def self.load(configuration) file = configuration[:config_file] || Configuration.locate_config_file unless File.exists?(file) raise ConfigurationError, "Configuration file '#{file}' not found." end begin config = YAML::load(IO.read file) rescue => e message = "Can't load configuration from file '#{file}'." if configuration[:debug] message += "\nMessage: #{e.message}" message += "\nBacktrace:\n\t#{e.backtrace.join("\n\t")}" end raise message end if env ||= config[:default] unless config = config[env] raise ConfigurationError, "Can't find environment #{env}." end end unless config.key?(:url) && config.key?(:api_key) && config.key?(:secret_key) message = "The environment #{env || '\'-\''} does not contain all required keys." raise ConfigurationError, message end config.merge(environment: env) end def self.locate_config_file %w(.cloudstack .cloudstack-cli).each do |file| file = File.join(Dir.home, "#{file}.yml") return file if File.exists?(file) end nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cloudstack_client-1.5.1 | lib/cloudstack_client/configuration.rb |