Skip to content

Instantly share code, notes, and snippets.

@krames
Last active January 4, 2016 03:09
Show Gist options
  • Save krames/8559613 to your computer and use it in GitHub Desktop.
Save krames/8559613 to your computer and use it in GitHub Desktop.
I would like to try getting some more additional debugging information out of the OpenStack provider. Can I get you to require this patch and then re-execute your code?
if Fog::VERSION == "1.19.0"
require 'rubygems'
require 'fog'
require 'fog/openstack'
require 'fog/storage'
Fog::Logger.warning "PATCHING Fog::Storage::OpenStack to added debugging information to JSON decoding"
module Fog
module Storage
class OpenStack < Fog::Service
class Real
def request(params, parse_json = true)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:path => "#{@path}/#{params[:path]}",
}))
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::Storage::OpenStack::NotFound.slurp(error)
else
error
end
end
puts "[#{@path}/#{params[:path]}] empty? #{!response.body.empty?} parse_json: #{parse_json} type: #{response.get_header('Content-Type') =~ %r{application/json}}"
puts "[#{@path}/#{params[:path]}] content-type: '#{response.get_header('Content-Type')}'"
puts "[#{@path}/#{params[:path]}] %r{application/json} '#{response.get_header('Content-Type') =~ %r{application/json}}'"
puts "[#{@path}/#{params[:path]}] /application\/json/ '#{response.get_header('Content-Type') =~ /application\/json/}'"
puts "[#{@path}/#{params[:path]}] /application\/json/i '#{response.get_header('Content-Type') =~ /application\/json/i}'"
puts "[#{@path}/#{params[:path]}] /json/ '#{response.get_header('Content-Type') =~ /json/}'"
if !response.body.empty? && parse_json && response.get_header('Content-Type') =~ %r{application/json}
puts "[#{@path}/#{params[:path]}] DECODING"
response.body = Fog::JSON.decode(response.body)
end
response
end
end
end
end
end
else
Fog::Logger.warning "PATCHING Fog::Storage::OpenStack - does not apply for #{Fog::VERSION}. Please remove it."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment