1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/openstack/models/identity/roles.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

2012-02-22 09:40:32 -05:00
require 'fog/core/collection'
require 'fog/openstack/models/identity/role'
module Fog
module Identity
class OpenStack
class Roles < Fog::Collection
model Fog::Identity::OpenStack::Role
attribute :user
attribute :tenant
def all
requires :user, :tenant
load(connection.
list_roles_for_user_on_tenant(tenant.id, user.id).body['roles'])
end
2012-02-24 06:38:05 -05:00
def get(role)
connection.get_role(id)
end
def add_user_role(user, role, tenant)
user_id = user.class == String ? user : user.id
role_id = role.class == String ? role : role.id
tenant_id = tenant.class == String ? tenant : tenant.id
connection.create_user_role(tenant_id, user_id, role_id).status == 200
end
def remove_user_role(user, role, tenant)
user_id = user.class == String ? user : user.id
role_id = role.class == String ? role : role.id
tenant_id = tenant.class == String ? tenant : tenant.id
connection.delete_user_role(tenant_id, user_id, role_id).status == 200
end
end
2012-02-22 09:40:32 -05:00
end # class OpenStack
end # module Compute
end # module Fog