module Lamma::SharedHelpers

Constants

DEFAULT_PROFILE

Public Instance Methods

ini_config(profile=DEFAULT_PROFILE) click to toggle source
# File lib/lamma/shared_helpers.rb, line 9
def ini_config(profile=DEFAULT_PROFILE)
  load_inifile(File.expand_path(File.join('~', '.aws', 'config')), profile)
end
ini_credentials(profile=DEFAULT_PROFILE) click to toggle source
# File lib/lamma/shared_helpers.rb, line 13
def ini_credentials(profile=DEFAULT_PROFILE)
  load_inifile(File.expand_path(File.join('~', '.aws', 'credentials')), profile)
end
region_or_raise(profile=DEFAULT_PROFILE) click to toggle source
# File lib/lamma/shared_helpers.rb, line 17
def region_or_raise(profile=DEFAULT_PROFILE)
  region = ENV['AWS_REGION'] ||
    ENV['AWS_DEFAULT_REGION'] ||
    ini_config(profile)['region']

  if region
    return region
  else
    raise Exception.new("Region must be specified by either AWS_REGION, AWS_DEFAULT_REGION or ~/.aws/config file")
  end
end
search_conf_path(from) click to toggle source
# File lib/lamma/shared_helpers.rb, line 29
def search_conf_path(from)
  bn = File.basename(File.expand_path(from))
  dn = File.dirname(File.expand_path(from))
  pn = Pathname(dn)

  while pn != pn.parent
    cp = File.join(pn, bn)
    if File.exist?(cp)
      return cp
    end

    pn = pn.parent
  end

  ''
end

Private Instance Methods

load_inifile(path, profile) click to toggle source
# File lib/lamma/shared_helpers.rb, line 48
def load_inifile(path, profile)
  if File.exist?(path)
    return IniFile.load(path)[profile]
  else
    {}
  end
end