class AWS::Core::CredentialProviders::EC2Provider
metadata service.
This credential provider tries to get credentials from the EC2
def get session, path
-
(String)
- Returns the http response body.
Raises:
-
(FailedRequestError)
-
Parameters:
-
path
(String
) -- -
session
(Net::HTTPSession
) --
def get session, path response = session.request(Net::HTTP::Get.new(path)) if response.code.to_i == 200 response.body else raise FailedRequestError end end
def get_credentials
def get_credentials begin http = Net::HTTP.new(ip_address, port) http.open_timeout = http_open_timeout http.read_timeout = http_read_timeout http.set_debug_output(http_debug_output) if http_debug_output http.start # get the first/default instance profile name path = '/latest/meta-data/iam/security-credentials/' profile_name = get(http, path).lines.map(&:strip).first # get the session details from the instance profile name path << profile_name session = JSON.parse(get(http, path)) http.finish credentials = {} credentials[:access_key_id] = session['AccessKeyId'] credentials[:secret_access_key] = session['SecretAccessKey'] credentials[:session_token] = session['Token'] credentials rescue *FAILURES => e {} end end
def initialize options = {}
(**options)
-
:http_debug_output
(Object
) -- HTTP wire -
:http_read_timeout
(Float
) -- -
:http_open_timeout
(Float
) -- -
:port
(Integer
) -- -
:ip_address
(String
) --
Parameters:
-
options
(Hash
) --
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] end