mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|cdn] updated cdn to use auth 2.0
This commit is contained in:
parent
ce140dc4e5
commit
f7b8e9b0dc
4 changed files with 89 additions and 8 deletions
|
@ -6,7 +6,7 @@ module Fog
|
|||
class Rackspace < Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :persistent
|
||||
recognizes :rackspace_auth_url, :persistent, :rackspace_region
|
||||
|
||||
request_path 'fog/rackspace/requests/cdn'
|
||||
request :get_containers
|
||||
|
@ -50,13 +50,12 @@ module Fog
|
|||
|
||||
def initialize(options={})
|
||||
@connection_options = options[:connection_options] || {}
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
@rackspace_auth_url = options[:rackspace_auth_url]
|
||||
uri = authenticate(options)
|
||||
@enabled = false
|
||||
@persistent = options[:persistent] || false
|
||||
|
||||
if credentials['X-CDN-Management-Url']
|
||||
uri = URI.parse(credentials['X-CDN-Management-Url'])
|
||||
if uri
|
||||
@host = uri.host
|
||||
@path = uri.path
|
||||
@port = uri.port
|
||||
|
@ -66,6 +65,31 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def authenticate(options)
|
||||
uri = self.send authentication_method, options
|
||||
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(:cloudFilesCDN, options[:rackspace_region] || :dfw)
|
||||
URI.parse url
|
||||
end
|
||||
|
||||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
URI.parse(credentials['X-CDN-Management-Url']) if credentials['X-CDN-Management-Url']
|
||||
end
|
||||
|
||||
def authentication_method
|
||||
if @rackspace_auth_url && @rackspace_auth_url =~ /v1(\.\d)?\w*$/
|
||||
:authenticate_v1
|
||||
else
|
||||
:authenticate_v2
|
||||
end
|
||||
end
|
||||
|
||||
def purge(object)
|
||||
if object.is_a? Fog::Storage::Rackspace::File
|
||||
delete_object object.directory.key, object.key
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
UK_ENDPOINT = 'https://lon.identity.api.rackspacecloud.com/v2.0'
|
||||
|
||||
requires :rackspace_username, :rackspace_api_key
|
||||
recognizes :rackspace_auth_url
|
||||
recognizes :rackspace_auth_url, :rackspace_region
|
||||
|
||||
model_path 'fog/rackspace/models/identity'
|
||||
model :user
|
||||
|
|
|
@ -38,7 +38,8 @@ module Fog
|
|||
:provider => 'Rackspace',
|
||||
:rackspace_api_key => @rackspace_api_key,
|
||||
:rackspace_auth_url => @rackspace_auth_url,
|
||||
:rackspace_username => @rackspace_username
|
||||
:rackspace_username => @rackspace_username,
|
||||
:rackspace_region => @rackspace_region
|
||||
)
|
||||
if @cdn.enabled?
|
||||
@cdn
|
||||
|
@ -182,7 +183,7 @@ module Fog
|
|||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
uri = URI.parse(credentials['X-Storage-Url'])
|
||||
URI.parse(credentials['X-Storage-Url'])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
56
tests/rackspace/cdn_tests.rb
Normal file
56
tests/rackspace/cdn_tests.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
def assert_method(url, method)
|
||||
@service.instance_variable_set "@rackspace_auth_url", method
|
||||
returns(method) { @service.send :authentication_method }
|
||||
end
|
||||
|
||||
tests('#authentication_method') do
|
||||
@service = Fog::CDN::Rackspace.new
|
||||
assert_method nil, :authenticate_v2
|
||||
|
||||
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
|
||||
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
|
||||
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
|
||||
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
|
||||
end
|
||||
|
||||
tests('legacy authentication') do
|
||||
pending if Fog.mocking?
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
|
||||
|
||||
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(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
end
|
||||
|
||||
tests('current authentation') do
|
||||
pending if Fog.mocking?
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
|
||||
|
||||
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, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('dfw region') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
|
||||
puts @service.instance_variable_get("@host")
|
||||
returns(true) { (@service.instance_variable_get("@host") =~ /cdn1/) != nil }
|
||||
end
|
||||
tests('ord region') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
|
||||
returns(true) { (@service.instance_variable_get("@host") =~ /cdn2/) != nil }
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue