Method: ChefFixie::AuthzMapper.struct_to_name

Defined in:
lib/chef_fixie/authz_mapper.rb

.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/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