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 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):

  • :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.



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

def initialize options = {}
  @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 Method Details

#access_key_idString?

Returns:

  • (String, nil)


43
44
45
46
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 43

def access_key_id
  refresh_if_stale
  @access_key_id
end

#expirationTime?

Returns:

  • (Time, nil)


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

def expiration
  refresh_if_stale
  @expiration
end

#refresh!Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 66

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)


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

def secret_access_key
  refresh_if_stale
  @secret_access_key
end

#session_tokenString?

Returns:

  • (String, nil)


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

def session_token
  refresh_if_stale
  @session_token
end