class AWS::Core::CredentialProviders::CredentialFileProvider

This credential provider gets credentials from a credential file with the following format:

AWSAccessKeyId=your_key
AWSSecretKey=your_secret

Constants

CREDENTIAL_FILE_KEY_MAP

Map of AWS credential file key names to accepted provider key names

Attributes

credential_file[R]

Public Class Methods

new(credential_file) click to toggle source

@param [String] credential_file The file path of a credential file

# File lib/aws/core/credential_providers.rb, line 247
def initialize(credential_file)
  @credential_file = credential_file
end

Public Instance Methods

get_credentials() click to toggle source

(see Provider#get_credentials)

# File lib/aws/core/credential_providers.rb, line 252
def get_credentials
  credentials = {}
  if File.exist?(credential_file) && File.readable?(credential_file)
    File.open(credential_file, 'r') do |fh|
      fh.each_line do |line|
        key, val = line.strip.split(%r(\s*=\s*))
        if key && val && CREDENTIAL_FILE_KEY_MAP[key] && KEYS.include?(CREDENTIAL_FILE_KEY_MAP[key])
          credentials[CREDENTIAL_FILE_KEY_MAP[key]] = val
        end
      end
      fh.close
    end
  end
  credentials
end