Sha256: d4c63b12c0960506a60880adb651228d3066dbdfc3df00edd655e8bef8a8f6f7

Contents?: true

Size: 1.18 KB

Versions: 14

Compression:

Stored size: 1.18 KB

Contents

require 'aws-sdk'
require 'aws_config'

module Awspec::Helper
  module CredentialsLoader
    def self.load(profile = nil)
      profile = ENV['AWS_PROFILE'] if profile.nil?
      if profile
        # SharedCredentials
        aws_config = AWSConfig.profiles[profile]
        aws_config = AWSConfig.profiles['default'] unless aws_config
        Aws.config[:region] = aws_config.config_hash[:region] if aws_config
        Aws.config[:credentials] = Aws::SharedCredentials.new(profile_name: profile)
      else
        # secrets.yml
        creds = YAML.load_file('spec/secrets.yml') if File.exist?('spec/secrets.yml')
        creds = YAML.load_file('secrets.yml') if File.exist?('secrets.yml')
        return if creds.nil?
        Aws.config.update({
                            region: creds['region']
                          }) if creds.include?('region')
        Aws.config.update({
                            credentials: Aws::Credentials.new(
                              creds['aws_access_key_id'],
                              creds['aws_secret_access_key'])
                          }) if creds.include?('aws_access_key_id') && creds.include?('aws_secret_access_key')
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
awspec-0.30.0 lib/awspec/helper/credentials_loader.rb
awspec-0.29.0 lib/awspec/helper/credentials_loader.rb
awspec-0.28.1 lib/awspec/helper/credentials_loader.rb
awspec-0.28.0 lib/awspec/helper/credentials_loader.rb
awspec-0.27.2 lib/awspec/helper/credentials_loader.rb
awspec-0.27.1 lib/awspec/helper/credentials_loader.rb
awspec-0.27.0 lib/awspec/helper/credentials_loader.rb
awspec-0.26.2 lib/awspec/helper/credentials_loader.rb
awspec-0.26.1 lib/awspec/helper/credentials_loader.rb
awspec-0.26.0 lib/awspec/helper/credentials_loader.rb
awspec-0.25.3 lib/awspec/helper/credentials_loader.rb
awspec-0.25.2 lib/awspec/helper/credentials_loader.rb
awspec-0.25.1 lib/awspec/helper/credentials_loader.rb
awspec-0.25.0 lib/awspec/helper/credentials_loader.rb