mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] SPIKE: converting authentication module to super class
This commit is contained in:
parent
3d4189416b
commit
f54720c233
3 changed files with 64 additions and 48 deletions
|
@ -1,37 +0,0 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
module Authentication
|
||||
|
||||
private
|
||||
|
||||
def authentication_method
|
||||
return :authenticate_v2 unless @rackspace_auth_url
|
||||
if @rackspace_auth_url =~ /v2(\.\d)?\w*$/
|
||||
:authenticate_v2
|
||||
else
|
||||
:authenticate_v1
|
||||
end
|
||||
end
|
||||
|
||||
def v1_authentication?
|
||||
@identity_service.nil?
|
||||
end
|
||||
|
||||
def v2_authentication?
|
||||
@identity_service != nil
|
||||
end
|
||||
|
||||
def authenticate_v2(identity_options)
|
||||
h = {
|
||||
:rackspace_api_key => identity_options[:rackspace_api_key],
|
||||
:rackspace_username => identity_options[:rackspace_username],
|
||||
:rackspace_auth_url => identity_options[:rackspace_auth_url]
|
||||
}
|
||||
|
||||
@identity_service = Fog::Rackspace::Identity.new(h)
|
||||
@auth_token = @identity_service.auth_token
|
||||
endpoint_uri
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
53
lib/fog/rackspace/service.rb
Normal file
53
lib/fog/rackspace/service.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Service
|
||||
|
||||
def endpoint_uri(service_endpoint_url=nil)
|
||||
raise Fog::Errors::NotImplemented.new("Retrieving endpoint is not implemented for this service.")
|
||||
end
|
||||
|
||||
def authenticate(options)
|
||||
self.send authentication_method, options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authentication_method
|
||||
return :authenticate_v2 unless @rackspace_auth_url
|
||||
if @rackspace_auth_url =~ /v2(\.\d)?\w*$/
|
||||
:authenticate_v2
|
||||
else
|
||||
:authenticate_v1
|
||||
end
|
||||
end
|
||||
|
||||
def v1_authentication?
|
||||
@identity_service.nil?
|
||||
end
|
||||
|
||||
def v2_authentication?
|
||||
@identity_service != nil
|
||||
end
|
||||
|
||||
def authenticate_v2(identity_options)
|
||||
hash = {
|
||||
:rackspace_api_key => identity_options[:rackspace_api_key],
|
||||
:rackspace_username => identity_options[:rackspace_username],
|
||||
:rackspace_auth_url => identity_options[:rackspace_auth_url]
|
||||
}
|
||||
|
||||
@identity_service = Fog::Rackspace::Identity.new(hash)
|
||||
@identity_service.auth_token
|
||||
end
|
||||
|
||||
def authenticate_v1(options)
|
||||
raise Fog::Errors::NotImplemented.new("Authentication of legacy endpoints is not implemented for this service.")
|
||||
end
|
||||
|
||||
def endpoint_uri_v2(service_name, region)
|
||||
@identity_service.service_catalog.get_endpoint(service_name, region)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require 'fog/rackspace'
|
||||
require 'fog/rackspace/authentication'
|
||||
require 'fog/rackspace/service'
|
||||
require 'fog/storage'
|
||||
|
||||
module Fog
|
||||
|
@ -54,8 +54,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
include Utils
|
||||
include Fog::Rackspace::Authentication
|
||||
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
|
@ -82,10 +81,9 @@ module Fog
|
|||
|
||||
end
|
||||
|
||||
class Real
|
||||
class Real < Fog::Rackspace::Service
|
||||
include Utils
|
||||
include Fog::Rackspace::Authentication
|
||||
|
||||
|
||||
attr_reader :rackspace_cdn_ssl
|
||||
|
||||
def initialize(options={})
|
||||
|
@ -165,7 +163,8 @@ module Fog
|
|||
:rackspace_username => @rackspace_username,
|
||||
:rackspace_auth_url => @rackspace_auth_url
|
||||
}
|
||||
@uri = self.send authentication_method, options
|
||||
@auth_token = super(options)
|
||||
@uri = endpoint_uri
|
||||
else
|
||||
@auth_token = @rackspace_auth_token
|
||||
@uri = URI.parse(@rackspace_storage_url)
|
||||
|
@ -175,14 +174,15 @@ module Fog
|
|||
def endpoint_uri(service_endpoint_url=nil)
|
||||
return @uri if @uri
|
||||
|
||||
url = @rackspace_storage_url || service_endpoint_url
|
||||
url = @rackspace_storage_url || service_endpoint_url
|
||||
|
||||
unless url
|
||||
if v1_authentication?
|
||||
raise "Service Endpoint must be specified via :rackspace_storage_url parameter"
|
||||
else
|
||||
url = @identity_service.service_catalog.get_endpoint(:cloudFiles, @rackspace_region)
|
||||
url = endpoint_uri_v2(:cloudFiles, @rackspace_region)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@uri = URI.parse url
|
||||
@uri.host = "snet-#{@uri.host}" if service_net?
|
||||
|
@ -193,8 +193,8 @@ module Fog
|
|||
|
||||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
endpoint_uri credentials['X-Storage-Url']
|
||||
credentials['X-Auth-Token']
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue