Class: OpscodeAcl::UserInviteRecind

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

Instance Method Summary collapse

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/knife/user_invite_recind.rb', line 29

def run
  if (name_args.length < 1) && ! config.key?(:all)
    show_usage
    ui.fatal("You must specify a username.")
    exit 1
  end

  # To recind we need to send a DELETE to association_requests/INVITE_ID
  # For user friendliness we look up the invite ID based on username.
  @invites = {}
  usernames = name_args
  rest.get_rest("association_requests").each { |i| @invites[i["username"]] = i["id"] }
  if config[:all]
    ui.confirm("Are you sure you want to recind all association requests")
    @invites.each do |u, i|
      rest.delete_rest("association_requests/#{i}")
    end
  else
    ui.confirm("Are you sure you want to recind the association requests for: #{usernames.join(", ")}")
    usernames.each do |u|
      if @invites.key?(u)
        rest.delete_rest("association_requests/#{@invites[u]}")
      else
        ui.fatal("No association request for #{u}.")
        exit 1
      end
    end
  end
end