lib/fog/rackspace/identity.rb in fog-maestrodev-1.8.0.20130114204828 vs lib/fog/rackspace/identity.rb in fog-maestrodev-1.14.0.20130806165225

- old
+ new

@@ -1,25 +1,27 @@ require 'fog/rackspace' module Fog module Rackspace class Identity < Fog::Service + US_ENDPOINT = 'https://identity.api.rackspacecloud.com/v2.0' 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 collection :users model :role collection :roles model :credential collection :credentials model :tenant collection :tenants + model :service_catalog request_path 'fog/rackspace/requests/identity' request :create_token request :list_users @@ -29,53 +31,42 @@ request :get_user_by_id request :get_user_by_name request :create_user request :update_user request :delete_user - request :get_credentials - class Mock + class Mock < Fog::Rackspace::Service + attr_reader :service_catalog + def request Fog::Mock.not_implemented end end - class Real + class Real < Fog::Rackspace::Service + attr_reader :service_catalog, :auth_token + def initialize(options={}) @rackspace_username = options[:rackspace_username] @rackspace_api_key = options[:rackspace_api_key] + @rackspace_region = options[:rackspace_region] @rackspace_auth_url = options[:rackspace_auth_url] || US_ENDPOINT - uri = URI.parse(@rackspace_auth_url) - @host = uri.host - @path = uri.path - @port = uri.port - @scheme = uri.scheme + @uri = URI.parse(@rackspace_auth_url) + @host = @uri.host + @path = @uri.path + @port = @uri.port + @scheme = @uri.scheme @persistent = options[:persistent] || false @connection_options = options[:connection_options] || {} - @connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options) + @connection = Fog::Connection.new(@uri.to_s, @persistent, @connection_options) authenticate end - - def request(params) - begin - parameters = params.merge!({ - :headers => { - 'Content-Type' => 'application/json', - 'X-Auth-Token' => @auth_token - }, - :host => @host, - :path => "#{@path}/#{params[:path]}" - }) - response = @connection.request(parameters) - response.body = Fog::JSON.decode(response.body) unless response.body.empty? - response - end - end - - def authenticate + + def authenticate(options={}) data = self.create_token(@rackspace_username, @rackspace_api_key).body + @service_catalog = ServiceCatalog.from_response(self, data) @auth_token = data['access']['token']['id'] end end end end