Created
April 10, 2014 03:32
-
-
Save krames/10340459 to your computer and use it in GitHub Desktop.
This file should patch the capitalization change in Rackspace identity service for Fog 1.1.2
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
| require 'rubygems' | |
| require 'fog' | |
| require 'fog/rackspace' | |
| require 'fog/storage' | |
| Fog::Logger.warning "PATCHING Fog::Storage::Rackspace to support lowercase headers" | |
| module Fog | |
| module Rackspace | |
| def self.authenticate(options, connection_options = {}) | |
| rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com" | |
| url = rackspace_auth_url.match(/^https?:/) ? \ | |
| rackspace_auth_url : 'https://' + rackspace_auth_url | |
| uri = URI.parse(url) | |
| connection = Fog::Connection.new(url, false, connection_options) | |
| @rackspace_api_key = options[:rackspace_api_key] | |
| @rackspace_username = options[:rackspace_username] | |
| response = connection.request({ | |
| :expects => [200, 204], | |
| :headers => { | |
| 'X-Auth-Key' => @rackspace_api_key, | |
| 'X-Auth-User' => @rackspace_username | |
| }, | |
| :host => uri.host, | |
| :method => 'GET', | |
| :path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0' | |
| }) | |
| response.headers.reject do |key, value| | |
| !['x-server-management-url', 'x-storage-url', 'x-cdn-management-url', 'x-auth-token'].include?(key) | |
| end | |
| end | |
| end | |
| end | |
| module Fog | |
| module Storage | |
| class Rackspace < Fog::Service | |
| class Real | |
| def initialize(options={}) | |
| require 'mime/types' | |
| require 'multi_json' | |
| @rackspace_api_key = options[:rackspace_api_key] | |
| @rackspace_username = options[:rackspace_username] | |
| @rackspace_cdn_ssl = options[:rackspace_cdn_ssl] | |
| @rackspace_auth_url = options[:rackspace_auth_url] | |
| @connection_options = options[:connection_options] || {} | |
| credentials = Fog::Rackspace.authenticate(options, @connection_options) | |
| @auth_token = credentials['x-auth-token'] | |
| uri = URI.parse(credentials['x-storage-url']) | |
| @host = options[:rackspace_servicenet] == true ? "snet-#{uri.host}" : uri.host | |
| @path = uri.path | |
| @persistent = options[:persistent] || false | |
| @port = uri.port | |
| @scheme = uri.scheme | |
| Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true | |
| @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment