Class: Fog::Rackspace::Identity::Real
- Inherits:
-
Object
- Object
- Fog::Rackspace::Identity::Real
- Defined in:
- lib/fog/rackspace/identity.rb,
lib/fog/rackspace/requests/identity/list_users.rb,
lib/fog/rackspace/requests/identity/create_user.rb,
lib/fog/rackspace/requests/identity/delete_user.rb,
lib/fog/rackspace/requests/identity/update_user.rb,
lib/fog/rackspace/requests/identity/create_token.rb,
lib/fog/rackspace/requests/identity/list_tenants.rb,
lib/fog/rackspace/requests/identity/get_user_by_id.rb,
lib/fog/rackspace/requests/identity/get_credentials.rb,
lib/fog/rackspace/requests/identity/list_user_roles.rb,
lib/fog/rackspace/requests/identity/get_user_by_name.rb,
lib/fog/rackspace/requests/identity/list_credentials.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #create_token(username, api_key) ⇒ Object
- #create_user(username, email, enabled, options = {}) ⇒ Object
- #delete_user(user_id) ⇒ Object
- #get_credentials(user_id) ⇒ Object
- #get_user_by_id(user_id) ⇒ Object
- #get_user_by_name(username) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_credentials(user_id) ⇒ Object
- #list_tenants ⇒ Object
- #list_user_roles(user_id) ⇒ Object
- #list_users ⇒ Object
- #request(params) ⇒ Object
- #update_user(user_id, username, email, enabled, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/rackspace/identity.rb', line 43 def initialize(={}) @rackspace_username = [:rackspace_username] @rackspace_api_key = [:rackspace_api_key] @rackspace_auth_url = [:rackspace_auth_url] || US_ENDPOINT uri = URI.parse(@rackspace_auth_url) @host = uri.host @path = uri.path @port = uri.port @scheme = uri.scheme @persistent = [:persistent] || false @connection_options = [:connection_options] || {} @connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options) authenticate end |
Instance Method Details
#authenticate ⇒ Object
76 77 78 79 |
# File 'lib/fog/rackspace/identity.rb', line 76 def authenticate data = self.create_token(@rackspace_username, @rackspace_api_key).body @auth_token = data['access']['token']['id'] end |
#create_token(username, api_key) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/identity/create_token.rb', line 5 def create_token(username, api_key) data = { 'auth' => { 'RAX-KSKEY:apiKeyCredentials' => { 'username' => username, 'apiKey' => api_key } } } request( :body => Fog::JSON.encode(data), :expects => [200, 203], :method => 'POST', :path => 'tokens' ) end |
#create_user(username, email, enabled, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/identity/create_user.rb', line 5 def create_user(username, email, enabled, = {}) data = { 'user' => { 'username' => username, 'email' => email, 'enabled' => enabled } } data['user']['OS-KSADM:password'] = [:password] unless [:password].nil? request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'users' ) end |
#delete_user(user_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/identity/delete_user.rb', line 5 def delete_user(user_id) request( :expects => [204], :method => 'DELETE', :path => "users/#{user_id}" ) end |
#get_credentials(user_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/identity/get_credentials.rb', line 5 def get_credentials(user_id) request( :expects => [200, 203], :method => 'GET', :path => "users/#{user_id}/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials" ) end |
#get_user_by_id(user_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/identity/get_user_by_id.rb', line 5 def get_user_by_id(user_id) request( :expects => [200, 203], :method => 'GET', :path => "users/#{user_id}" ) end |
#get_user_by_name(username) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/identity/get_user_by_name.rb', line 5 def get_user_by_name(username) request( :expects => [200, 203], :method => 'GET', :path => "users?name=#{username}" ) end |
#list_credentials(user_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/rackspace/requests/identity/list_credentials.rb', line 5 def list_credentials(user_id) response = request( :expects => [200, 203], :method => 'GET', :path => "users/#{user_id}/OS-KSADM/credentials" ) unless response.body['credentials'].is_a?(Array) response.body['credentials'] = [response.body['credential']] response.body.delete('credential') end response end |
#list_tenants ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/rackspace/requests/identity/list_tenants.rb', line 5 def list_tenants() response = request( :expects => [200, 203], :method => 'GET', :path => 'tenants' ) unless response.body['tenants'].is_a?(Array) response.body['tenants'] = [response.body['tenant']] response.body.delete('tenant') end response end |
#list_user_roles(user_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/rackspace/requests/identity/list_user_roles.rb', line 5 def list_user_roles(user_id) response = request( :expects => [200, 203], :method => 'GET', :path => "users/#{user_id}/roles" ) unless response.body['roles'].is_a?(Array) response.body['roles'] = [response.body['role']] response.body.delete('role') end response end |
#list_users ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/rackspace/requests/identity/list_users.rb', line 5 def list_users() response = request( :expects => [200, 203], :method => 'GET', :path => 'users' ) unless response.body['users'].is_a?(Array) response.body['users'] = [response.body['user']] response.body.delete('user') end response end |
#request(params) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/rackspace/identity.rb', line 60 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 |
#update_user(user_id, username, email, enabled, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/rackspace/requests/identity/update_user.rb', line 5 def update_user(user_id, username, email, enabled, = {}) data = { 'user' => { 'username' => username, 'email' => email, 'enabled' => enabled } } request( :body => Fog::JSON.encode(data), :expects => [200, 203], :method => 'POST', :path => "users/#{user_id}" ) end |