lib/kaname/adapter/read_only.rb in kaname-0.7.1 vs lib/kaname/adapter/read_only.rb in kaname-0.8.0
- old
+ new
@@ -8,16 +8,20 @@
def list_users
@_users ||= Yao::User.list
end
def find_user(name)
- user = Yao::User.find_by_name(name)
+ user = Yao::User.find_by_name(name).first
{"id" => user.id, "name" => user.name}
end
def list_tenants
- @_tenants ||= Yao::Tenant.list
+ @_tenants ||= if keystone_v2?
+ Yao::Tenant.list
+ else
+ Yao::Project.list
+ end
end
def list_roles
@_roles ||= Yao::Role.list
end
@@ -59,9 +63,13 @@
delete_user_role(tenant, user_hash, before_role)
create_user_role(tenant, user_hash, after_role)
end
private
+
+ def keystone_v2?
+ Yao.default_client.pool["identity"].url_prefix.to_s.match(/v2\.0/)
+ end
def tenant_role_hash(user_id)
list_role_assignments.each_with_object(Hash.new) do |t,th|
if t.user.id == user_id
th[list_tenants.find {|ts| ts.id == t.scope["project"]["id"]}["name"]] = list_roles.find {|r| r.id == t.role.id }['name']