Sha256: c6dfb23eaf443a48408facfab790e34c448010948147b029c447f17654dd714d

Contents?: true

Size: 905 Bytes

Versions: 7

Compression:

Stored size: 905 Bytes

Contents

module Ec2Tools::Config
  class FileNotFoundError < StandardError ; end
  class InvalidConfigError < StandardError ; end
  require 'yaml'
  attr_reader :access_key_id, :secret_access_key, :server
  
  def self.load(file = nil)
    file = search_config_file if file.nil?
    raise  FileNotFoundError unless File.exists?(file)
    data = YAML.load_file(file)
    
    raise InvalidConfigError.new("config file must contain key, secret, server") unless valid_config?(data)
    
    { :access_key_id => data['key'],
      :secret_access_key => data['secret'],
      :server => data['server'] }
  end
  
  private
  def self.search_config_file
    ["config/amazon_ec2.yml", ".account.yml"].each do |file|
      return file if File.exists?(file)
    end
    raise FileNotFoundError
  end
  
  def self.valid_config?(data)
    data.has_key?('key') && data.has_key?('secret') && data.has_key?('server')
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ec2_tools-0.3.3 lib/ec2_tools/config.rb
ec2_tools-0.3.2 lib/ec2_tools/config.rb
ec2_tools-0.3.1 lib/ec2_tools/config.rb
ec2_tools-0.3.0 lib/ec2_tools/config.rb
ec2_tools-0.2.1 lib/ec2_tools/config.rb
ec2_tools-0.2.0 lib/ec2_tools/config.rb
ec2_tools-0.1.0 lib/ec2_tools/config.rb