Sha256: 150202a608806d38af281541820f4e8e8e9d7baf3712b4c553889a5deb4a0f08

Contents?: true

Size: 1022 Bytes

Versions: 16

Compression:

Stored size: 1022 Bytes

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')
        Aws.config.update({
                            region: creds['region'],
                            credentials: Aws::Credentials.new(
                              creds['aws_access_key_id'],
                              creds['aws_secret_access_key'])
                          }) if creds
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
awspec-0.24.2 lib/awspec/helper/credentials_loader.rb
awspec-0.24.1 lib/awspec/helper/credentials_loader.rb
awspec-0.24.0 lib/awspec/helper/credentials_loader.rb
awspec-0.23.0 lib/awspec/helper/credentials_loader.rb
awspec-0.22.1 lib/awspec/helper/credentials_loader.rb
awspec-0.22.0 lib/awspec/helper/credentials_loader.rb
awspec-0.21.6 lib/awspec/helper/credentials_loader.rb
awspec-0.21.5 lib/awspec/helper/credentials_loader.rb
awspec-0.21.4 lib/awspec/helper/credentials_loader.rb
awspec-0.21.3 lib/awspec/helper/credentials_loader.rb
awspec-0.21.2 lib/awspec/helper/credentials_loader.rb
awspec-0.21.1 lib/awspec/helper/credentials_loader.rb
awspec-0.21.0 lib/awspec/helper/credentials_loader.rb
awspec-0.20.2 lib/awspec/helper/credentials_loader.rb
awspec-0.20.1 lib/awspec/helper/credentials_loader.rb
awspec-0.20.0 lib/awspec/helper/credentials_loader.rb