Class: Fog::Rackspace::Identity::Real

Inherits:
Service
  • Object
show all
Includes:
Common
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/list_user_roles.rb,
lib/fog/rackspace/requests/identity/get_user_by_name.rb,
lib/fog/rackspace/requests/identity/list_credentials.rb

Instance Attribute Summary

Attributes included from Common

#auth_token, #service_catalog

Instance Method Summary collapse

Methods included from Common

#apply_options, #authenticate

Methods inherited from Service

#authenticate, #endpoint_uri, #region, #request, #request_without_retry, #service_name, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



74
75
76
77
78
79
# File 'lib/fog/rackspace/identity.rb', line 74

def initialize(options={})
  apply_options(options)
  @connection = Fog::Core::Connection.new(@uri.to_s, @persistent, @connection_options)

  authenticate
end

Instance Method Details

#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_without_retry(
    :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, options = {})
  data = {
    'user' => {
      'username' => username,
      'email' => email,
      'enabled' => enabled
    }
  }
  data['user']['OS-KSADM:password'] = options[:password] unless options[: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_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_tenantsObject



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_usersObject



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

#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, options = {})
  data = {
    'user' => {
      'username' => username,
      'email' => email,
      'enabled' => enabled
    }
  }

  request(
    :body => Fog::JSON.encode(data),
    :expects => [200, 203],
    :method => 'POST',
    :path => "users/#{user_id}"
  )
end