2012-02-22 09:40:32 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Identity
|
|
|
|
class OpenStack
|
|
|
|
class User < Fog::Model
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :email
|
|
|
|
attribute :enabled
|
|
|
|
attribute :name
|
2012-03-09 04:28:32 -05:00
|
|
|
attribute :tenant_id, :aliases => 'tenantId'
|
2012-02-26 21:43:42 -05:00
|
|
|
attribute :password
|
|
|
|
|
|
|
|
attr_accessor :email, :name, :tenant_id, :enabled, :password
|
|
|
|
|
|
|
|
def initialize(attributes)
|
|
|
|
@connection = attributes[:connection]
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
|
|
|
requires :name, :tenant_id, :password
|
2012-03-09 07:46:17 -05:00
|
|
|
enabled = true if enabled.nil?
|
2012-02-26 21:43:42 -05:00
|
|
|
data = connection.create_user(name, password, email, tenant_id, enabled)
|
|
|
|
merge_attributes(data.body['user'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(options = {})
|
|
|
|
requires :id
|
|
|
|
options.merge('id' => id)
|
|
|
|
response = connection.update_user(id, options)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_password(password)
|
|
|
|
update({'password' => password, 'url' => "/users/#{id}/OS-KSADM/password"})
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_tenant(tenant)
|
|
|
|
tenant = tenant.id if tenant.class != String
|
|
|
|
update({:tenantId => tenant, 'url' => "/users/#{id}/OS-KSADM/tenant"})
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_enabled(enabled)
|
|
|
|
update({:enabled => enabled, 'url' => "/users/#{id}/OS-KSADM/enabled"})
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
|
|
|
connection.delete_user(id)
|
|
|
|
true
|
|
|
|
end
|
2012-02-22 09:40:32 -05:00
|
|
|
|
2012-04-17 08:31:47 -04:00
|
|
|
def roles(tenant_id = self.tenant_id)
|
|
|
|
connection.list_roles_for_user_on_tenant(tenant_id, self.id).body['roles']
|
2012-02-22 09:40:32 -05:00
|
|
|
end
|
2012-02-26 21:43:42 -05:00
|
|
|
end # class User
|
2012-02-22 09:40:32 -05:00
|
|
|
end # class OpenStack
|
|
|
|
end # module Identity
|
|
|
|
end # module Fog
|
|
|
|
|