mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] updated storage to support custom endpoints when using auth 2.0
This commit is contained in:
parent
ca7d7135f5
commit
b1261efd40
3 changed files with 44 additions and 20 deletions
|
@ -3,7 +3,7 @@ module Fog
|
|||
|
||||
def initialize(url, persistent=false, params={})
|
||||
Excon.defaults[:headers]['User-Agent'] ||= "fog/#{Fog::VERSION}"
|
||||
@excon = Excon.new(url, params)
|
||||
@excon = Excon.new(url.to_s, params)
|
||||
@persistent = persistent
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :rackspace_servicenet, :rackspace_cdn_ssl, :persistent, :rackspace_region
|
||||
recognizes :rackspace_temp_url_key
|
||||
recognizes :rackspace_temp_url_key, :rackspace_storage_url
|
||||
|
||||
model_path 'fog/rackspace/models/storage'
|
||||
model :directory
|
||||
|
@ -112,8 +112,8 @@ module Fog
|
|||
@connection_options = options[:connection_options] || {}
|
||||
authenticate
|
||||
@persistent = options[:persistent] || false
|
||||
Excon.defaults[:ssl_verify_peer] = false if options[:rackspace_servicenet] == true
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
||||
Excon.defaults[:ssl_verify_peer] = false if service_net?
|
||||
@connection = Fog::Connection.new(endpoint_uri, @persistent, @connection_options)
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -127,8 +127,8 @@ module Fog
|
|||
'Content-Type' => 'application/json',
|
||||
'X-Auth-Token' => @auth_token
|
||||
}.merge!(params[:headers] || {}),
|
||||
:host => @host,
|
||||
:path => "#{@path}/#{params[:path]}",
|
||||
:host => endpoint_uri.host,
|
||||
:path => "#{endpoint_uri.path}/#{params[:path]}",
|
||||
}), &block)
|
||||
rescue Excon::Errors::Unauthorized => error
|
||||
if error.response.body != 'Bad username or password' # token expiration
|
||||
|
@ -152,6 +152,14 @@ module Fog
|
|||
response
|
||||
end
|
||||
|
||||
def service_net?
|
||||
@rackspace_servicenet == true
|
||||
end
|
||||
|
||||
def v1_authentication?
|
||||
@identity_service.nil?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticate
|
||||
|
@ -164,26 +172,38 @@ module Fog
|
|||
uri = self.send authentication_method, options
|
||||
else
|
||||
@auth_token = @rackspace_auth_token
|
||||
uri = URI.parse(@rackspace_storage_url)
|
||||
@uri = URI.parse(@rackspace_storage_url)
|
||||
end
|
||||
|
||||
@host = @rackspace_servicenet == true ? "snet-#{uri.host}" : uri.host
|
||||
@path = uri.path
|
||||
@port = uri.port
|
||||
@scheme = uri.scheme
|
||||
end
|
||||
|
||||
def authenticate_v2(options)
|
||||
@identity_service = Fog::Rackspace::Identity.new(options)
|
||||
@auth_token = @identity_service.auth_token
|
||||
url = @identity_service.service_catalog.get_endpoint(:cloudFiles, @rackspace_region)
|
||||
URI.parse url
|
||||
endpoint_uri
|
||||
end
|
||||
|
||||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
URI.parse(credentials['X-Storage-Url'])
|
||||
endpoint_uri credentials
|
||||
end
|
||||
|
||||
def endpoint_uri(credentials=nil)
|
||||
return @uri if @uri
|
||||
|
||||
url = @rackspace_storage_url
|
||||
unless url
|
||||
if v1_authentication?
|
||||
raise "Credentials parameter must be specified for authentication v1" unless credentials
|
||||
url = credentials['X-Storage-Url']
|
||||
else
|
||||
url = @identity_service.service_catalog.get_endpoint(:cloudFiles, @rackspace_region)
|
||||
end
|
||||
end
|
||||
|
||||
@uri = URI.parse url
|
||||
@uri.host = "snet-#{uri.host}" if service_net?
|
||||
@uri
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@path").nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
|
||||
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
end
|
||||
|
@ -35,17 +35,21 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@path").nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
|
||||
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('dfw region') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
|
||||
returns(true) { (@service.instance_variable_get("@host") =~ /dfw\d/) != nil }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw\d/) != nil }
|
||||
end
|
||||
tests('ord region') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
|
||||
returns(true) { (@service.instance_variable_get("@host") =~ /ord\d/) != nil }
|
||||
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord\d/) != nil }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
|
||||
:rackspace_storage_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue