Sha256: 14295c12302b0f21f8b7b995f22fffb7a8496e2fc1f5d85c02a2ea86095b6301

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

require 'yao'
require 'yaml'

module Kakine
  class Config
    OS_PARAMS = %w[auth_url username password]

    @@config = {}

    def self.setup
      load_config
      load_env
      validate_config
      setup_yao
    end

    private

    def self.load_config
      config =
        begin
          YAML.load_file(File.join(Dir.home, '.kakine'))
        rescue Errno::ENOENT
          return
        end

      @@config.merge!(config)
    end

    def self.load_env
      OS_PARAMS.each do |param|
        env = "OS_#{param.upcase}"
        @@config[param] = ENV[env] if ENV[env]
      end
    end

    def self.validate_config
      OS_PARAMS.each do |param|
        unless @@config[param]
          raise "Configuration '#{param}' is missing. Check your ~/.kakine or export OS_#{param.upcase}."
        end
      end
    end

    def self.setup_yao
      Yao.configure do
        auth_url    @@config['auth_url']
        tenant_name Kakine::Option.tenant_name
        username    @@config['username']
        password    @@config['password']
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kakine-0.6.4 lib/kakine/config.rb
kakine-0.6.2 lib/kakine/config.rb
kakine-0.6.1 lib/kakine/config.rb
kakine-0.6.0 lib/kakine/config.rb
kakine-0.5.0 lib/kakine/config.rb