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/role.rb
Dan Prince 65a90fd655 OpenStack: get identity tests passing in real mode
Updates to the OpenStack identity tests to they pass in both real
and mock modes.

Also, fixes an issue in the delete_user_role request where it
was expecting 200 instead of 204 (which seems to match the
spec and implementation).
2013-01-28 13:07:22 -05:00

50 lines
1.2 KiB
Ruby

require 'fog/core/model'
module Fog
module Identity
class OpenStack
class Role < Fog::Model
identity :id
attribute :name
def save
requires :name
data = service.create_role(name)
merge_attributes(data.body['role'])
true
end
def destroy
requires :id
service.delete_role(id)
true
end
def add_to_user(user, tenant)
add_remove_to_user(user, tenant, :add)
end
def remove_to_user(user, tenant)
add_remove_to_user(user, tenant, :remove)
end
private
def add_remove_to_user(user, tenant, ops)
requires :id
user_id = get_id(user)
tenant_id = get_id(tenant)
case ops
when :add
service.create_user_role(tenant_id, user_id, id).status == 200
when :remove
service.delete_user_role(tenant_id, user_id, id).status == 204
end
end
def get_id(_)
_.is_a?(String) ? _ : _.id
end
end # class Role
end # class OpenStack
end # module Identity
end # module Fog