1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Fix make OpenStack swift working properly.

- expect 204 for OpenStack swift.
- Don't always assume there is a CDN  attached to the service.
- Sometime the path have v1.0 and sometime don't

(thanks for @geemus help on #387)
This commit is contained in:
Chmouel Boudjnah 2011-07-01 15:04:42 -05:00
parent f7e4797834
commit 3fa8d7f1dc
4 changed files with 34 additions and 11 deletions

View file

@ -45,13 +45,21 @@ module Fog
require 'json'
credentials = Fog::Rackspace.authenticate(options)
@auth_token = credentials['X-Auth-Token']
@enabled = false
uri = URI.parse(credentials['X-CDN-Management-Url'])
@host = uri.host
@path = uri.path
@port = uri.port
@scheme = uri.scheme
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
if credentials['X-CDN-Management-Url']
uri = URI.parse(credentials['X-CDN-Management-Url'])
@host = uri.host
@path = uri.path
@port = uri.port
@scheme = uri.scheme
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
@enabled = true
end
end
def enabled?
@enabled
end
def reload

View file

@ -13,18 +13,19 @@ module Fog
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)
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
response = connection.request({
:expects => 204,
:expects => [200, 204],
:headers => {
'X-Auth-Key' => @rackspace_api_key,
'X-Auth-User' => @rackspace_username
},
:host => rackspace_auth_url,
:host => uri.host,
:method => 'GET',
:path => 'v1.0'
: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)

View file

@ -55,9 +55,18 @@ module Fog
def save
requires :key
connection.put_container(key)
if @public
# if user set cont as public but wed don't have a CDN connnection
# then error out.
if @public and !@connection.cdn
raise(Fog::Storage::Rackspace::Error.new("Directory can not be set as :public without a CDN provided"))
# if we set as public then set it and we sure we have connection.cdn
# or it would have error out.
elsif @public
@public_url = connection.cdn.put_container(key, 'X-CDN-Enabled' => 'True').headers['X-CDN-URI']
else
# if we have cdn connectio but cont has not been public then let the
# CDN knows about it
elsif @connection.cdn
connection.cdn.put_container(key, 'X-CDN-Enabled' => 'False')
@public_url = nil
end

View file

@ -30,8 +30,12 @@ module Fog
@cdn ||= Fog::CDN.new(
:provider => 'Rackspace',
:rackspace_api_key => @rackspace_api_key,
:rackspace_auth_url => @rackspace_auth_url,
:rackspace_username => @rackspace_username
)
if @cdn.enabled?
return @cdn
end
end
end
@ -75,6 +79,7 @@ module Fog
@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]
credentials = Fog::Rackspace.authenticate(options)
@auth_token = credentials['X-Auth-Token']