2012-06-23 15:41:53 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class Identity
|
|
|
|
class User < Fog::Model
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :username
|
|
|
|
attribute :password, :alias => 'OS-KSADM:password'
|
|
|
|
attribute :email
|
|
|
|
attribute :enabled
|
|
|
|
attribute :created
|
|
|
|
attribute :updated
|
|
|
|
|
|
|
|
def save
|
|
|
|
requires :username, :email, :enabled
|
2012-12-22 21:45:05 -05:00
|
|
|
unless persisted?
|
2012-12-22 18:24:03 -05:00
|
|
|
data = service.create_user(username, email, enabled, :password => password)
|
2012-06-23 15:41:53 -04:00
|
|
|
else
|
2012-12-22 18:24:03 -05:00
|
|
|
data = service.update_user(identity, username, email, enabled, :password => password)
|
2012-06-23 15:41:53 -04:00
|
|
|
end
|
|
|
|
merge_attributes(data.body['user'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
2012-12-22 18:24:03 -05:00
|
|
|
service.delete_user(identity)
|
2012-06-23 15:41:53 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def roles
|
|
|
|
@roles ||= begin
|
|
|
|
Fog::Rackspace::Identity::Roles.new({
|
2012-12-22 18:24:03 -05:00
|
|
|
:service => service,
|
2012-06-23 15:41:53 -04:00
|
|
|
:user => self
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def credentials
|
|
|
|
@credentials ||= begin
|
|
|
|
Fog::Rackspace::Identity::Credentials.new({
|
2012-12-22 18:24:03 -05:00
|
|
|
:service => service,
|
2012-06-23 15:41:53 -04:00
|
|
|
:user => self
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|