move authorized_keys#get_all_logins to virtual_machines#get_all_logins
[arvados.git] / services / api / app / controllers / arvados / v1 / virtual_machines_controller.rb
1 class Arvados::V1::VirtualMachinesController < ApplicationController
2   before_filter :admin_required, :only => :get_all_logins
3   def get_all_logins
4     @users = {}
5     User.includes(:authorized_keys).all.each do |u|
6       @users[u.uuid] = u
7     end
8     @response = []
9     @vms = VirtualMachine.includes(:login_permissions).all
10     @vms.each do |vm|
11       vm.login_permissions.each do |perm|
12         user_uuid = perm.tail_uuid
13         @users[user_uuid].andand.authorized_keys.each do |ak|
14           username = perm.properties.andand['username']
15           if username
16             @response << {
17               username: username,
18               hostname: vm.hostname,
19               public_key: ak.public_key,
20               user_uuid: user_uuid,
21               virtual_machine_uuid: vm.uuid,
22               authorized_key_uuid: ak.uuid
23             }
24           end
25         end
26       end
27     end
28     render json: { kind: "arvados#HashList", items: @response }
29   end
30 end