Class: Aws::SharedCredentials

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

Instance Attribute Summary collapse

Attributes included from CredentialProvider

#expiration, #metrics

Instance Method Summary collapse

Methods included from CredentialProvider

#set?

Constructor Details

#initialize(options = {}) ⇒ SharedCredentials

Constructs a new SharedCredentials object. This will load static (access_key_id, secret_access_key and session_token) 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.

To use credentials from the default credential resolution chain create a client without the credential option specified. You may access the resolved credentials through client.config.credentials.



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

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
  @metrics = ['CREDENTIALS_CODE']
end

Instance Attribute Details

#credentialsCredentials (readonly)



53
54
55
# File 'lib/aws-sdk-core/shared_credentials.rb', line 53

def credentials
  @credentials
end

#pathString (readonly)



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

def path
  @path
end

#profile_nameString (readonly)



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

def profile_name
  @profile_name
end

Instance Method Details

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
# File 'lib/aws-sdk-core/shared_credentials.rb', line 56

def inspect
  parts = [
    self.class.name,
    "profile_name=#{profile_name.inspect}",
    "path=#{path.inspect}",
  ]
  "#<#{parts.join(' ')}>"
end

#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.



70
71
72
# File 'lib/aws-sdk-core/shared_credentials.rb', line 70

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