Module: ChefFixie::AuthzMapper

Included in:
Sql::SqlTable
Defined in:
lib/chef_fixie_shahid/authz_mapper.rb

Defined Under Namespace

Modules: ClassMethods Classes: ReverseMapper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

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



36
37
38
# File 'lib/chef_fixie_shahid/authz_mapper.rb', line 36

def self.included(base)
  base.extend(ClassMethods)
end

.mapperObject



99
100
101
# File 'lib/chef_fixie_shahid/authz_mapper.rb', line 99

def self.mapper
  @mapper ||= ReverseMapper.new
end

.register(klass, name, type) ⇒ Object



103
104
105
# File 'lib/chef_fixie_shahid/authz_mapper.rb', line 103

def self.register(klass, name, type)
  mapper.register(klass, name, type)
end

.struct_to_name(s) ⇒ Object

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/chef_fixie_shahid/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

Instance Method Details

#authz_to_name(authz_id) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef_fixie_shahid/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