Class: OpscodeAcl::ActorMap

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/actor_map.rb

Instance Method Summary collapse

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/knife/actor_map.rb', line 33

def run
  chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
  usags = chef_rest.get_rest("groups").keys.select do |gname|
    gname.length == 32 && gname =~ /^[0-9a-f]+$/
  end
  user_map = {:users => {}, :usags => {}}
  user_map = usags.inject(user_map) do |map, usag|
    a_group = chef_rest.get_rest("groups/#{usag}")
    actors = a_group["actors"]
    if actors.length == 1
      user_map[:users][actors.first] = usag
      user_map[:usags][usag] = actors.first
    end
    user_map
  end
  clients = chef_rest.get_rest("clients").keys.inject({}) { |h, c| h[c] = c; h }
  open("actor-map.yaml", "w") do |f|
    f.write({ :user_map => user_map, :clients => clients }.to_yaml)
  end
  ui.msg "Found %d users and %d clients" % [user_map[:users].size, clients.size]
  ui.msg "wrote map to 'actor-map.yaml'"
end