Sha256: 01d63f7e7b8bc85b72fa1f30990f8129dd1f788ef48882730a73d4aaae85fcbe

Contents?: true

Size: 1.33 KB

Versions: 34

Compression:

Stored size: 1.33 KB

Contents

module Yao::Resources
  class Role < Base
    friendly_attributes :name, :description, :id

    self.service        = "identity"
    self.resource_name  = "role"
    self.resources_name = "roles"
    self.resources_path = "/OS-KSADM/roles"
    self.admin          = true

    class << self
      def get_by_name(name)
        self.list.find {|role| role.name == name }
      end
      alias find_by_name get_by_name

      def list_for_user(user_name, on:)
        user   = Yao::User.get_by_name(user_name)
        tenant = Yao::Tenant.get_by_name(on)
        path = ["tenants", tenant.id, "users", user.id, "roles"].join("/")

        with_resources_path(path) { self.list }
      end

      def grant(role_name, to:, on:)
        role   = Yao::Role.get_by_name(role_name)
        user   = Yao::User.get_by_name(to)
        tenant = Yao::Tenant.get_by_name(on)

        PUT path_for_grant_revoke(tenant, user, role)
      end

      def revoke(role_name, from:, on:)
        role   = Yao::Role.get_by_name(role_name)
        user   = Yao::User.get_by_name(from)
        tenant = Yao::Tenant.get_by_name(on)

        DELETE path_for_grant_revoke(tenant, user, role)
      end

      private

      def path_for_grant_revoke(tenant, user, role)
        ["tenants", tenant.id, "users", user.id, "roles", "OS-KSADM", role.id].join("/")
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
yao-0.7.0 lib/yao/resources/role.rb
yao-0.6.3 lib/yao/resources/role.rb
yao-0.6.2 lib/yao/resources/role.rb
yao-0.6.1 lib/yao/resources/role.rb
yao-0.6.0 lib/yao/resources/role.rb
yao-0.5.0 lib/yao/resources/role.rb
yao-0.4.3 lib/yao/resources/role.rb
yao-0.4.2 lib/yao/resources/role.rb
yao-0.4.1 lib/yao/resources/role.rb
yao-0.4.0 lib/yao/resources/role.rb
yao-0.3.8 lib/yao/resources/role.rb
yao-0.3.7 lib/yao/resources/role.rb
yao-0.3.6 lib/yao/resources/role.rb
yao-0.3.5 lib/yao/resources/role.rb
yao-0.3.4 lib/yao/resources/role.rb
yao-0.3.3 lib/yao/resources/role.rb
yao-0.3.2 lib/yao/resources/role.rb
yao-0.3.1 lib/yao/resources/role.rb
yao-0.3.0 lib/yao/resources/role.rb
yao-0.2.13 lib/yao/resources/role.rb