Sha256: 8e351425eca5f4f4f20cc78ac002c3e38c89ee696749c1d0694ac68d87a2f338

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

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"

    # @return [Yao::Resources::Project]
    def project
      @project ||= Yao::Project.get(scope["project"]["id"])
    end

    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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yao-0.21.0 lib/yao/resources/role_assignment.rb
yao-0.20.0 lib/yao/resources/role_assignment.rb
yao-0.19.0 lib/yao/resources/role_assignment.rb
yao-0.18.0 lib/yao/resources/role_assignment.rb
yao-0.17.0 lib/yao/resources/role_assignment.rb
yao-0.16.0 lib/yao/resources/role_assignment.rb