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

Merge pull request #387 from chmouel/master

Fix for supporting OpenStack swift.
This commit is contained in:
Wesley Beary 2011-07-07 14:27:29 -07:00
commit 8ca8f9af76
4 changed files with 34 additions and 11 deletions

View file

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

View file

@ -13,18 +13,19 @@ module Fog
rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com" rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com"
url = rackspace_auth_url.match(/^https?:/) ? \ url = rackspace_auth_url.match(/^https?:/) ? \
rackspace_auth_url : 'https://' + rackspace_auth_url rackspace_auth_url : 'https://' + rackspace_auth_url
uri = URI.parse(url)
connection = Fog::Connection.new(url) connection = Fog::Connection.new(url)
@rackspace_api_key = options[:rackspace_api_key] @rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username] @rackspace_username = options[:rackspace_username]
response = connection.request({ response = connection.request({
:expects => 204, :expects => [200, 204],
:headers => { :headers => {
'X-Auth-Key' => @rackspace_api_key, 'X-Auth-Key' => @rackspace_api_key,
'X-Auth-User' => @rackspace_username 'X-Auth-User' => @rackspace_username
}, },
:host => rackspace_auth_url, :host => uri.host,
:method => 'GET', :method => 'GET',
:path => 'v1.0' :path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
}) })
response.headers.reject do |key, value| response.headers.reject do |key, value|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key) !['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 def save
requires :key requires :key
connection.put_container(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'] @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') connection.cdn.put_container(key, 'X-CDN-Enabled' => 'False')
@public_url = nil @public_url = nil
end end

View file

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