Parent

Class/Module Index [+]

Quicksearch

Fog::Rackspace::Identity::Real

Attributes

auth_token[R]
service_catalog[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/rackspace/identity.rb, line 47
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
  @persistent = options[:persistent] || false
  @connection_options = options[:connection_options] || {}
  @connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options)

  authenticate
end

Public Instance Methods

authenticate() click to toggle source
# File lib/fog/rackspace/identity.rb, line 82
def authenticate
  data = self.create_token(@rackspace_username, @rackspace_api_key).body
  @service_catalog = ServiceCatalog.from_response(self, data)
  @auth_token = data['access']['token']['id']
end
create_token(username, api_key) click to toggle source
# 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 = {}) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/fog/rackspace/identity.rb, line 65
def request(params)
  begin
    parameters = params.merge!({
      :headers => {
        'Content-Type' => 'application/json',
        'Accept' => '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 = {}) click to toggle source
# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.