Class: OpenStack::Keystone::Admin::User
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Common
- Base
- OpenStack::Keystone::Admin::User
- 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
Class Method Summary collapse
-
.all_by_tenant(tenant) ⇒ Object
List of users in a given tenant.
-
.find_by_name(name) ⇒ Object
List of user with a given name.
-
.find_by_tenant(id, tenant) ⇒ Object
Find a user in a given tenant.
Instance Method Summary collapse
-
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method.
-
#initialize(attributes = {}, persisted = false) ⇒ User
constructor
:notnew:.
-
#roles(scope = :all, tenant = nil) ⇒ Object
File role(s) (i.e. instances of OpenStack::Keystone::Admin::UserRole) for this user in a given tenant.
-
#tenant ⇒ Object
The primary (default) tenant (i.e. an instance of OpenStack::Keystone::Admin::Tenant) associated with this user.
Methods inherited from Base
Methods inherited from Common
collection_path, custom_method_collection_url, element_path
Methods inherited from Base
Methods inherited from ActiveResource::Base
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ User
:notnew:
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/open_stack/keystone/admin/user.rb', line 48 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
82 83 84 85 86 |
# File 'lib/open_stack/keystone/admin/user.rb', line 82 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
104 105 106 |
# File 'lib/open_stack/keystone/admin/user.rb', line 104 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
93 94 95 96 97 98 |
# File 'lib/open_stack/keystone/admin/user.rb', line 93 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/open_stack/keystone/admin/user.rb', line 63 def encode(={}) #: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}", ) 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
118 119 120 121 122 |
# File 'lib/open_stack/keystone/admin/user.rb', line 118 def roles(scope = :all, tenant = nil) tenant_id = tenant.is_a?(OpenStack::Keystone::Admin::Tenant) ? tenant.id : (tenant || self.tenant_id) OpenStack::Keystone::Admin::UserRole.find(scope, :params => {:tenant_id => tenant_id, :user_id => self.id}) end |