Skip to content

Instantly share code, notes, and snippets.

@elight
Created May 2, 2014 14:41
Show Gist options
  • Save elight/11476756 to your computer and use it in GitHub Desktop.
Save elight/11476756 to your computer and use it in GitHub Desktop.
def request(params)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:path => "#{@path}/#{@tenant_id}/#{params[:path]}",
:query => params[:query]
}))
rescue Excon::Errors::Unauthorized => error
if error.response.body != 'Bad username or password' # token expiration
@openstack_must_reauthenticate = true
authenticate
retry
else # Bad Credentials
raise error
end
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Compute::OpenStack::NotFound.slurp(error)
else
error
end
end
if !response.body.empty? and response.get_header('Content-Type') == 'application/json'
response.body = Fog::JSON.decode(response.body)
end
response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment