def fetch_access_token options = {}
c = options[:connection] || Faraday.default_connection
retry_with_error do
headers = { "Metadata-Flavor" => "Google" }
resp = c.get COMPUTE_AUTH_TOKEN_URI, nil, headers
case resp.status
when 200
Signet::OAuth2.parse_credentials(resp.body,
resp.headers["content-type"])
when 404
raise Signet::AuthorizationError, NO_METADATA_SERVER_ERROR
else
msg = "Unexpected error code #{resp.status}" \
"#{UNEXPECTED_ERROR_SUFFIX}"
raise Signet::AuthorizationError, msg
end
end
end