1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
require 'fog/openstack/models/model'
module Fog
module OpenStack
class Identity
class V2
class User < Fog::OpenStack::Model
identity :id
attribute :email
attribute :enabled
attribute :name
attribute :tenant_id, :aliases => 'tenantId'
attribute :password
attr_accessor :email, :name, :tenant_id, :enabled, :password
def ec2_credentials
requires :id
service.ec2_credentials(:user => self)
end
def save
raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted?
requires :name
enabled = true if enabled.nil?
data = service.create_user(name, password, email, tenant_id, enabled)
merge_attributes(data.body['user'])
true
end
def update(options = {})
requires :id
options.merge('id' => id)
service.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
service.delete_user(id)
true
end
def roles(tenant_id = self.tenant_id)
if tenant_id
service.list_roles_for_user_on_tenant(tenant_id, id).body['roles']
else
[]
end
end
end
end
end
end
end
|