Created
June 19, 2013 20:36
-
-
Save krames/5817816 to your computer and use it in GitHub Desktop.
This patch should address issue with the Rackspace CDN service not re-authenticating when the after the authentication token expires. This patch should be named 01_cdn_patch.rb and placed in the initializers directory to ensure that the patch is properly applied. This patch is only good for Fog 1.12.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if Fog::VERSION == "1.12.1" | |
| Fog::Logger.warning "PATCHING Fog::CDN::Rackspace to re-authenticate after authentication token expires" | |
| require 'rubygems' | |
| require 'fog' | |
| module Fog | |
| module CDN | |
| class Rackspace < Fog::Service | |
| class Real < Fog::Rackspace::Service | |
| def initialize(options={}) | |
| @options = options | |
| @connection_options = options[:connection_options] || {} | |
| @rackspace_auth_url = options[:rackspace_auth_url] | |
| @rackspace_cdn_url = options[:rackspace_cdn_url] | |
| @rackspace_region = options[:rackspace_region] || :dfw | |
| authenticate(options) | |
| @enabled = false | |
| @persistent = options[:persistent] || false | |
| if endpoint_uri | |
| @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) | |
| @enabled = true | |
| end | |
| end | |
| def request(params, parse_json = true) | |
| first_attempt = true | |
| begin | |
| response = @connection.request(params.merge({ | |
| :headers => { | |
| 'Content-Type' => 'application/json', | |
| 'Accept' => 'application/json', | |
| 'X-Auth-Token' => auth_token | |
| }.merge(params[:headers] || {}), | |
| :host => endpoint_uri.host, | |
| :path => "#{endpoint_uri.path}/#{params[:path]}" | |
| })) | |
| rescue Excon::Errors::Unauthorized => error | |
| raise error unless first_attempt | |
| first_attempt = false | |
| authenticate(@options) | |
| retry | |
| rescue Excon::Errors::NotFound => error | |
| raise Fog::Storage::Rackspace::NotFound.slurp(error, region) | |
| rescue Excon::Errors::BadRequest => error | |
| raise Fog::Storage::Rackspace::BadRequest.slurp error | |
| rescue Excon::Errors::InternalServerError => error | |
| raise Fog::Storage::Rackspace::InternalServerError.slurp error | |
| rescue Excon::Errors::HTTPStatusError => error | |
| raise Fog::Storage::Rackspace::ServiceError.slurp error | |
| end | |
| if response && response.body && parse_json && response.headers['Content-Type'] =~ %r{application/json} | |
| response.body = Fog::JSON.decode(response.body) | |
| end | |
| response | |
| end | |
| end | |
| end | |
| end | |
| end | |
| else | |
| Fog::Logger.warning "PATCHING Fog::CDN::Rackspace - 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