module ChefFixie::AuthzMapper

Public Class Methods

included(base) click to toggle source

It would be really awesome if this was integrated with the AuthzObjectMixin so that when it was mixed in, we automatically added code to the reverse mapping

Much of this might be better folded up into a sql stored procedure

# File lib/chef_fixie/authz_mapper.rb, line 36
def self.included(base)
  base.extend(ClassMethods)
end
mapper() click to toggle source
# File lib/chef_fixie/authz_mapper.rb, line 99
def self.mapper
  @mapper ||= ReverseMapper.new
end
register(klass, name, type) click to toggle source
# File lib/chef_fixie/authz_mapper.rb, line 103
def self.register(klass, name, type)
  mapper.register(klass, name, type)
end
struct_to_name(s) click to toggle source

Translates the json from authz for group membership and acls into a human readable form This makes some assumptions about the shape of the data structure, but works well enough to be quite useful

# File lib/chef_fixie/authz_mapper.rb, line 110
def self.struct_to_name(s)
  mapper = AuthzMapper.mapper
  if s.kind_of?(Hash)
    s.keys.inject({}) do |h, k|
      v = s[k]
      if v.kind_of?(Array)
        case k
        when "actors"
          h[k] = v.map { |a| mapper.authz_to_name(a, :actor) } #.sort We should sort these, but the way we're returning unknown causes sort
        when "groups"
          h[k] = v.map { |a| mapper.authz_to_name(a, :group) } #.sort to fail
        else
          h[k] = v
        end
      else
        h[k] = struct_to_name(v)
      end
      h
    end
  end
end

Public Instance Methods

authz_to_name(authz_id) click to toggle source
# File lib/chef_fixie/authz_mapper.rb, line 40
def authz_to_name(authz_id)
  objects = by_authz_id(authz_id).all(1)
  scope = :unknown
  name = :unknown
  if objects.count == 1
    object = objects.first
    name = object.name
    scope =
      if object.respond_to?(:org_id)
        ChefFixie::Sql::Orgs.org_guid_to_name(object.org_id)
      else
        :global
      end
    [scope, name]
  else
    :unknown
  end
end