Sha256: f0a91dadc48489b22b3fad00ffdbef163c5e5b4aac3e02ff2c5a94574ee6daa6

Contents?: true

Size: 802 Bytes

Versions: 3

Compression:

Stored size: 802 Bytes

Contents

require 'inifile'
require 'yaml'
require "aws_keys/version"

module AwsKeys
 
  def self.load(profile: nil, yml_file: ENV['HOME'] + "/.aws.yml")
  
    aws_credential_path = ENV['HOME'] + "/aws/credentials"

    case
    when !(ENV.keys & %w[AWS_ACCESS_KEY AWS_SECRET_KEY]).empty?
     {
        "aws_access_key"=>ENV["AWS_ACCESS_KEY"], 
        "aws_secret_key"=>ENV["AWS_SECRET_KEY"]
      }
    when File.exist?(yml_file)
      data = YAML.load_file(yml_file)
      profile.nil? ? data : data[profile]
    when File.exist?(aws_credential_path)
      file = IniFile.load(aws_credential_path)
      profile.nil? ? file["default"] : file[profile]
    else
      fail NoAwsKeys, "None of ENV variables, ~/aws/credentials or aws.yml were found"
    end
  end 

  class NoAwsKeys < StandardError; end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
aws-keys-0.1.1 lib/aws_keys.rb
aws-keys-0.1.0 lib/aws_keys.rb
aws_keys-0.1.0 lib/aws_keys.rb