Class: OpenStack::Keystone::Admin::User

Inherits:
Base show all
Defined in:
lib/open_stack/keystone/admin/user.rb

Overview

An OpenStack User (“admin view”)

Attributes

  • name - The name of this user

  • password - Password (possibly encrypted) of this user

  • email - E-mail address of this user

  • enabled - True if this user is enabled

  • tenant_id - Default (i.e. primary) tenant for this user

Defined Under Namespace

Classes: UserRole

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

site, site=

Methods inherited from Common

collection_path, custom_method_collection_url, element_path

Methods inherited from Base

headers

Methods inherited from ActiveResource::Base

#load

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ User

:notnew:



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/open_stack/keystone/admin/user.rb', line 54

def initialize(attributes = {}, persisted = false) # :notnew:
  attributes = attributes.with_indifferent_access

  if attributes[:tenant].present?
    attributes[:tenant_id] = attributes.delete(:tenant).id
  end

  if attributes[:tenantId].present?
    attributes[:tenant_id] = attributes.delete(:tenantId)
  end

  super(attributes, persisted)
end

Class Method Details

.all_by_tenant(tenant) ⇒ Object

List of users in a given tenant

Attributes

  • tenant - An instance of OpenStack::Keystone::Admin::Tenant or a tenant id



88
89
90
91
92
# File 'lib/open_stack/keystone/admin/user.rb', line 88

def self.all_by_tenant(tenant)
  tenant_id = tenant.is_a?(OpenStack::Keystone::Admin::Tenant) ? tenant.id : tenant

  all.select { |user| user.tenant_id == tenant_id }
end

.find_by_name(name) ⇒ Object

List of user with a given name

Attributes

  • name - A string



110
111
112
# File 'lib/open_stack/keystone/admin/user.rb', line 110

def self.find_by_name(name)
  all.detect { |user| user.name == name }
end

.find_by_tenant(id, tenant) ⇒ Object

Find a user in a given tenant

Attributes

  • id - The user id

  • tenant - An instance of OpenStack::Keystone::Admin::Tenant or a tenant id



99
100
101
102
103
104
# File 'lib/open_stack/keystone/admin/user.rb', line 99

def self.find_by_tenant(id, tenant)
  tenant_id = tenant.is_a?(OpenStack::Keystone::Admin::Tenant) ? tenant.id : tenant

  user = self.find(id)
  user.tenant_id == tenant_id ? user : nil
end

Instance Method Details

#encode(options = {}) ⇒ Object

Overloads ActiveRecord::encode method



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/open_stack/keystone/admin/user.rb', line 69

def encode(options={}) # :nodoc: Custom encoding to deal with openstack API
  to_encode = {
      :user => {
          :name => name,
          :password => password,
          :email => email,
          :enabled => enabled
      }
  }

  to_encode[:user][:tenantId] = tenant_id if @attributes[:tenant_id].present?

  to_encode.send("to_#{self.class.format.extension}", options)
end

#roles(scope = :all, tenant = nil) ⇒ Object

File role(s) (i.e. instances of OpenStack::Keystone::Admin::UserRole) for this user in a given tenant

Attributes

  • scope - The ActiveResource scope (defaults to :all)

  • tenant - An optional instance of OpenStack::Keystone::Admin::Tenant (or a tenant id). Defaults to the primary tenant for this user



132
133
134
135
136
# File 'lib/open_stack/keystone/admin/user.rb', line 132

def roles(scope = :all, tenant = nil)
  tenant_id = tenant.is_a?(OpenStack::Keystone::Admin::Tenant) ? tenant.id : (tenant || self.tenant_id)

  UserRole.find(scope, :params => {:tenant_id => tenant_id, :user_id => self.id})
end

#tenantObject

The primary (default) tenant (i.e. an instance of OpenStack::Keystone::Admin::Tenant) associated with this user



115
116
117
# File 'lib/open_stack/keystone/admin/user.rb', line 115

def tenant
  OpenStack::Keystone::Admin::Tenant.find tenant_id
end

#tenant=(primary_tenant) ⇒ Object

Set the primary (default) tenant associated with this user

Attributes

  • primary_tenant - A valid tenant or a tenant_id



123
124
125
# File 'lib/open_stack/keystone/admin/user.rb', line 123

def tenant=(primary_tenant)
  self.tenant_id = primary_tenant.is_a?(OpenStack::Keystone::Admin::Tenant) ? primary_tenant.id : primary_tenant
end