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

Class: Aws::SharedCredentials

Inherits:
Object
  • Object
show all
Includes:
CredentialProvider
Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CredentialProvider

#access_key_id, #secret_access_key, #session_token, #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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'gems/aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 26

def initialize(options = {})
  shared_config = Aws.shared_config
  @path = options[:path]
  @path ||= shared_config.credentials_path
  @profile_name = options[:profile_name]
  @profile_name ||= ENV['AWS_PROFILE']
  @profile_name ||= shared_config.profile_name
  if @path && @path == shared_config.credentials_path
    @credentials = shared_config.credentials(profile: @profile_name)
  else
    config = SharedConfig.new(
      credentials_path: @path,
      profile_name: @profile_name
    )
    @credentials = config.credentials(profile: @profile_name)
  end
end

Instance Attribute Details

#credentialsCredentials (readonly)

Returns:



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

def credentials
  @credentials
end

#pathString (readonly)

Returns:

  • (String)


45
46
47
# File 'gems/aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 45

def path
  @path
end

#profile_nameString (readonly)

Returns:

  • (String)


48
49
50
# File 'gems/aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 48

def profile_name
  @profile_name
end

Instance Method Details

#loadable?Boolean

Deprecated.

This method is no longer used.

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.



68
69
70
# File 'gems/aws-sdk-core/lib/aws-sdk-core/shared_credentials.rb', line 68

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