lib/yao/resources/role_assignment.rb in yao-0.14.0 vs lib/yao/resources/role_assignment.rb in yao-0.15.0
- old
+ new
@@ -1,19 +1,51 @@
module Yao::Resources
class RoleAssignment < Base
friendly_attributes :scope, :role, :user
+
+ map_attribute_to_resource role: Role
+ map_attribute_to_resource user: User
+
self.service = "identity"
self.resource_name = "role_assignment"
self.resources_name = "role_assignments"
self.admin = true
self.api_version = "v3"
- self.client.url_prefix = Yao.config.auth_url.gsub(/v2.0|v3/, '')
# @return [Yao::Resources::Tenant]
def project
@project ||= Yao::Tenant.get(scope["project"]["id"])
end
- map_attribute_to_resource role: Role
- map_attribute_to_resource user: User
+ class << self
+ # @param _subpath [String]
+ # @return [String]
+ def create_url(_subpath='')
+ resources_name
+ end
+
+ # @param query [Hash]
+ def get(opt = {})
+ query = {}
+
+ if (user = opt[:user])
+ query['user.id'] = resource_id_or_string(user)
+ end
+
+ if (project = opt[:project] || opt[:tenant])
+ query['scope.project.id'] = resource_id_or_string(project)
+ end
+
+ list(query)
+ end
+
+ private
+ def resource_id_or_string(item)
+ if item.respond_to?(:id)
+ item.id
+ else
+ item
+ end
+ end
+ end
end
end