Class: Aws::InstanceProfileCredentials

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

Defined Under Namespace

Classes: Non200Response

Constant Summary collapse

FAILURES =

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

These are the errors we trap when attempting to talk to the instance metadata service. Any of these imply the service is not present, no responding or some other non-recoverable error.

[
  Errno::EHOSTUNREACH,
  Errno::ECONNREFUSED,
  SocketError,
  Timeout::Error,
  Non200Response,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Credentials

#inspect, #set?

Constructor Details

#initialize(options = {}) ⇒ InstanceProfileCredentials

Returns a new instance of InstanceProfileCredentials.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :retries (Integer) — default: 0

    Number of times to retry when retrieving credentials.

  • :ip_address (String) — default: '169.254.169.254'
  • :port (Integer) — default: 80
  • :http_open_timeout (Float) — default: 1
  • :http_read_timeout (Float) — default: 1
  • :http_debug_output (IO) — default: nil

    HTTP wire traces are sent to this object. You can specify something like $stdout.



34
35
36
37
38
39
40
41
42
43
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 34

def initialize options = {}
  @retries = options[:retries] || 0
  @ip_address = options[:ip_address] || '169.254.169.254'
  @port = options[:port] || 80
  @http_open_timeout = options[:http_open_timeout] || 1
  @http_read_timeout = options[:http_read_timeout] || 1
  @http_debug_output = options[:http_debug_output]
  @refresh_mutex = Mutex.new
  refresh!
end

Instance Attribute Details

#retriesInteger (readonly)

Returns The number of times to retry failed atttempts to fetch credentials from the instance metadata service. Defaults to 0.

Returns:

  • (Integer)

    The number of times to retry failed atttempts to fetch credentials from the instance metadata service. Defaults to 0.



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

def retries
  @retries
end

Instance Method Details

#access_key_idString?

Returns:

  • (String, nil)


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

def access_key_id
  refresh_if_stale
  @access_key_id
end

#expirationTime?

Returns:

  • (Time, nil)


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

def expiration
  refresh_if_stale
  @expiration
end

#refresh!Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 73

def refresh!
  @refresh_mutex.synchronize do
    credentials = MultiJson.load(get_credentials)
    @access_key_id = credentials['AccessKeyId']
    @secret_access_key = credentials['SecretAccessKey']
    @session_token = credentials['Token']
    if expires = credentials['Expiration']
      @expiration = Time.parse(expires)
    else
      @expiration = nil
    end
  end
end

#secret_access_keyString?

Returns:

  • (String, nil)


56
57
58
59
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 56

def secret_access_key
  refresh_if_stale
  @secret_access_key
end

#session_tokenString?

Returns:

  • (String, nil)


62
63
64
65
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 62

def session_token
  refresh_if_stale
  @session_token
end