3147: PySDK tests use mock>=1.0 and easier mock side_effect.
[arvados.git] / services / api / app / controllers / arvados / v1 / virtual_machines_controller.rb
1 class Arvados::V1::VirtualMachinesController < ApplicationController
2   skip_before_filter :find_object_by_uuid, :only => :get_all_logins
3   skip_before_filter :render_404_if_no_object, :only => :get_all_logins
4   before_filter(:admin_required,
5                 :only => [:logins, :get_all_logins])
6
7   def logins
8     get_all_logins
9   end
10
11   def get_all_logins
12     @users = {}
13     User.includes(:authorized_keys).all.each do |u|
14       @users[u.uuid] = u
15     end
16     @response = []
17     @vms = VirtualMachine.includes(:login_permissions)
18     if @object
19       @vms = @vms.where('uuid=?', @object.uuid)
20     else
21       @vms = @vms.all
22     end
23     @vms.each do |vm|
24       vm.login_permissions.each do |perm|
25         user_uuid = perm.tail_uuid
26         @users[user_uuid].andand.authorized_keys.andand.each do |ak|
27           username = perm.properties.andand['username']
28           if username
29             @response << {
30               username: username,
31               hostname: vm.hostname,
32               public_key: ak.public_key,
33               user_uuid: user_uuid,
34               virtual_machine_uuid: vm.uuid,
35               authorized_key_uuid: ak.uuid
36             }
37           end
38         end
39       end
40     end
41     render json: { kind: "arvados#HashList", items: @response }
42   end
43 end