Sha256: 4aa6715d766c8831c5e7127a85e457ba31c4ca96669be728b121da6cc3c9f91a

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

module Heirloom
  class Config

    attr_accessor :access_key, :secret_key, :metadata_region, :logger, :environment, :use_iam_profile

    def initialize(args={})
      @opts        = args[:opts] ||= Hash.new
      @logger      = args[:logger] ||= HeirloomLogger.new
      @environment = args[:environment] ||= 'default'
      @config      = load_config_file
      load_config
    end

    def load_config
      @access_key      = @opts.fetch :aws_access_key,
                                     @config['access_key']
      @secret_key      = @opts.fetch :aws_secret_key,
                                     @config['secret_key']
      @metadata_region = @opts.fetch :metadata_region,
                                     @config['metadata_region']
      @use_iam_profile = @opts.fetch :use_iam_profile,
                                     false
    end

    def proxy
      @proxy ||= env.load 'https_proxy'
    end

    private

    def load_config_file
      if File.exists? config_file
        data = YAML::load File.open(config_file)
        if data && data.has_key?(@environment)
          return data[@environment]
        else
          @logger.warn "Environment '#{@environment}' not found in config file."
        end
      end
      {}
    end

    def config_file
     @config_file ||= env_config_file || default_config_file
    end

    def env_config_file
      env.load 'HEIRLOOM_CONFIG_FILE'
    end

    def default_config_file
      "#{env.load 'HOME'}/.heirloom.yml"
    end

    def env
      @env ||= Env.new
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
heirloom-0.12.7 lib/heirloom/config.rb
heirloom-0.12.5 lib/heirloom/config.rb
heirloom-0.12.4 lib/heirloom/config.rb