Class: Aws::SharedCredentials

Inherits:
Credentials show all
Defined in:
aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb

Instance Attribute Summary collapse

Attributes inherited from Credentials

#access_key_id, #secret_access_key, #session_token

Instance Method Summary collapse

Methods inherited from Credentials

#set?

Constructor Details

#initialize(options = {}) ⇒ SharedCredentials

Constructs a new SharedCredentials object. This will load AWS access credentials from an ini file, which supports profiles. The default profile name is 'default'. You can specify the profile name with the ENV['AWS_PROFILE'] or with the :profile_name option.

Parameters:

  • [String] (Hash)

    a customizable set of options


22
23
24
25
26
27
28
# File 'aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 22

def initialize(options = {})
  @path = options[:path] || default_path
  @profile_name = options[:profile_name]
  @profile_name ||= ENV['AWS_PROFILE']
  @profile_name ||= 'default'
  load_from_path if loadable?
end

Instance Attribute Details

#pathString (readonly)

Returns:

  • (String)

31
32
33
# File 'aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 31

def path
  @path
end

#profile_nameString (readonly)

Returns:

  • (String)

34
35
36
# File 'aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 34

def profile_name
  @profile_name
end

Instance Method Details

#loadable?Boolean

Note:

This method does not indicate if the file found at #path will be parsable, only if it can be read.

Returns true if a credential file exists and has appropriate read permissions at #path.

Returns:

  • (Boolean)

    Returns true if a credential file exists and has appropriate read permissions at #path.


50
51
52
# File 'aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 50

def loadable?
  !path.nil? && File.exists?(path) && File.readable?(path)
end