2013-02-28 12:35:25 -05:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class Service
|
|
|
|
|
2013-02-28 15:57:09 -05:00
|
|
|
def service_name
|
|
|
|
raise Fog::Errors::NotImplemented.new("Please implement the #service_name method")
|
|
|
|
end
|
|
|
|
|
|
|
|
def region
|
|
|
|
raise Fog::Errors::NotImplemented.new("Please implement the #region method")
|
|
|
|
end
|
|
|
|
|
|
|
|
def endpoint_uri(service_endpoint=nil, endpoint_name=nil)
|
|
|
|
return @uri if @uri
|
|
|
|
|
|
|
|
url = service_endpoint
|
|
|
|
|
|
|
|
unless url
|
|
|
|
if v1_authentication?
|
|
|
|
raise "Service Endpoint must be specified via #{endpoint_name} parameter"
|
|
|
|
else
|
|
|
|
url = endpoint_uri_v2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@uri = URI.parse url
|
2013-02-28 12:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate(options)
|
|
|
|
self.send authentication_method, options
|
2013-04-22 18:16:32 -04:00
|
|
|
end
|
2013-02-28 12:35:25 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authentication_method
|
2013-03-15 12:55:40 -04:00
|
|
|
if v2_authentication?
|
2013-02-28 12:35:25 -05:00
|
|
|
:authenticate_v2
|
|
|
|
else
|
2013-03-05 15:54:03 -05:00
|
|
|
Fog::Logger.deprecation "Authentication using a v1.0/v1.1 endpoint is deprecated. Please specify a v2.0 endpoint using :rackpace_auth_url.\
|
|
|
|
For a list of v2.0 endpoints refer to http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/Endpoints-d1e180.html"
|
2013-02-28 12:35:25 -05:00
|
|
|
:authenticate_v1
|
2013-03-15 12:55:40 -04:00
|
|
|
end
|
2013-02-28 12:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def v1_authentication?
|
2013-03-15 12:55:40 -04:00
|
|
|
!v2_authentication?
|
2013-02-28 12:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def v2_authentication?
|
2013-03-15 12:55:40 -04:00
|
|
|
@rackspace_auth_url.nil? || @rackspace_auth_url =~ /v2(\.\d)?\w*$/
|
2013-02-28 12:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate_v2(identity_options)
|
|
|
|
hash = {
|
|
|
|
:rackspace_api_key => identity_options[:rackspace_api_key],
|
|
|
|
:rackspace_username => identity_options[:rackspace_username],
|
2013-05-30 13:52:37 -04:00
|
|
|
:rackspace_auth_url => identity_options[:rackspace_auth_url],
|
|
|
|
:connection_options => identity_options[:connection_options] || {}
|
2013-02-28 12:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@identity_service = Fog::Rackspace::Identity.new(hash)
|
2013-03-01 15:48:26 -05:00
|
|
|
@auth_token = @identity_service.auth_token
|
2013-02-28 12:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate_v1(options)
|
|
|
|
raise Fog::Errors::NotImplemented.new("Authentication of legacy endpoints is not implemented for this service.")
|
|
|
|
end
|
|
|
|
|
2013-02-28 15:57:09 -05:00
|
|
|
def endpoint_uri_v2
|
2013-03-01 15:48:26 -05:00
|
|
|
@uri = @identity_service.service_catalog.get_endpoint(service_name, region)
|
|
|
|
end
|
|
|
|
|
|
|
|
def auth_token
|
|
|
|
@auth_token || @identity_service.auth_token
|
2013-02-28 12:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|