2011-01-10 01:12:48 -05:00
|
|
|
require 'fog/core'
|
2010-12-16 14:24:52 -05:00
|
|
|
|
2009-10-10 22:05:17 -04:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2011-01-07 20:02:41 -05:00
|
|
|
|
2010-09-07 15:21:16 -04:00
|
|
|
extend Fog::Provider
|
|
|
|
|
2011-01-07 20:02:41 -05:00
|
|
|
service(:cdn, 'cdn/rackspace')
|
2011-01-07 21:12:05 -05:00
|
|
|
service(:compute, 'compute/rackspace')
|
2011-01-07 18:34:20 -05:00
|
|
|
service(:storage, 'storage/rackspace')
|
2010-09-07 15:21:16 -04:00
|
|
|
|
2010-03-19 21:29:42 -04:00
|
|
|
def self.authenticate(options)
|
2010-08-19 15:28:10 -04:00
|
|
|
rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com"
|
2011-06-15 16:19:58 -04:00
|
|
|
url = rackspace_auth_url.match(/^https?:/) ? \
|
|
|
|
rackspace_auth_url : 'https://' + rackspace_auth_url
|
2011-07-01 16:04:42 -04:00
|
|
|
uri = URI.parse(url)
|
2011-06-15 16:19:58 -04:00
|
|
|
connection = Fog::Connection.new(url)
|
2010-06-12 16:21:32 -04:00
|
|
|
@rackspace_api_key = options[:rackspace_api_key]
|
|
|
|
@rackspace_username = options[:rackspace_username]
|
2010-03-19 21:29:42 -04:00
|
|
|
response = connection.request({
|
2011-07-01 16:04:42 -04:00
|
|
|
:expects => [200, 204],
|
2010-03-19 21:29:42 -04:00
|
|
|
:headers => {
|
|
|
|
'X-Auth-Key' => @rackspace_api_key,
|
|
|
|
'X-Auth-User' => @rackspace_username
|
|
|
|
},
|
2011-07-01 16:04:42 -04:00
|
|
|
:host => uri.host,
|
2010-03-19 21:29:42 -04:00
|
|
|
:method => 'GET',
|
2011-07-01 16:04:42 -04:00
|
|
|
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
|
2010-03-19 21:29:42 -04:00
|
|
|
})
|
|
|
|
response.headers.reject do |key, value|
|
|
|
|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
|
2009-11-08 01:29:25 -05:00
|
|
|
end
|
2009-10-10 22:05:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|