You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::Core::CredentialProviders::SharedCredentialFileProvider

Inherits:
Object
  • Object
show all
Includes:
Provider
Defined in:
lib/aws/core/credential_providers.rb

Constant Summary

Constant Summary

Constants included from Provider

Provider::KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Provider

#access_key_id, #credentials, #refresh, #secret_access_key, #session_token, #set?

Constructor Details

#initialize(options = {}) ⇒ SharedCredentialFileProvider

Returns a new instance of SharedCredentialFileProvider

Parameters:

  • [String] (Hash)

    a customizable set of options



291
292
293
294
295
296
# File 'lib/aws/core/credential_providers.rb', line 291

def initialize(options = {})
  @path = options[:path] || shared_credential_file_path
  @profile_name = options[:profile_name]
  @profile_name ||= ENV['AWS_PROFILE']
  @profile_name ||= 'default'
end

Instance Attribute Details

#pathString (readonly)

Returns:

  • (String)


299
300
301
# File 'lib/aws/core/credential_providers.rb', line 299

def path
  @path
end

#profile_nameString (readonly)

Returns:

  • (String)


302
303
304
# File 'lib/aws/core/credential_providers.rb', line 302

def profile_name
  @profile_name
end

Instance Method Details

#get_credentialsHash

This method is called on a credential provider to fetch credentials. The credentials hash returned from this method will be cached until the client calls Provider#refresh.

Returns:

  • (Hash)


305
306
307
308
309
310
311
# File 'lib/aws/core/credential_providers.rb', line 305

def get_credentials
  if File.exist?(path) && File.readable?(path)
    load_from_path
  else
    {}
  end
end

#shared_credential_file_pathObject



273
274
275
276
277
278
279
280
281
# File 'lib/aws/core/credential_providers.rb', line 273

def shared_credential_file_path
  if RUBY_VERSION < '1.9'
    msg = "Must specify the :path to your shared credential file when using"
    msg << " Ruby #{RUBY_VERSION}"
    raise ArgumentError, msg
  else
    File.join(Dir.home, '.aws', 'credentials')
  end
end