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])
7 # Get all login permissons (user uuid, login account, SSH key) for a
10 render_logins_for VirtualMachine.where(uuid: @object.uuid)
13 # Get all login permissons for all VMs
15 render_logins_for VirtualMachine
20 def render_logins_for vm_query
22 @vms = vm_query.eager_load :login_permissions
24 User.eager_load(:authorized_keys).
25 where('users.uuid in (?)',
26 @vms.map { |vm| vm.login_permissions.map &:tail_uuid }.flatten.uniq).
31 vm.login_permissions.each do |perm|
32 user_uuid = perm.tail_uuid
33 next if not @users[user_uuid]
34 next if perm.properties['username'].blank?
35 aks = @users[user_uuid].authorized_keys
37 # We'll emit one entry, with no public key.
42 username: perm.properties['username'],
43 hostname: vm.hostname,
44 groups: (perm.properties['groups'].to_a rescue []),
45 public_key: ak ? ak.public_key : nil,
47 virtual_machine_uuid: vm.uuid,
48 authorized_key_uuid: ak ? ak.uuid : nil,
53 send_json kind: "arvados#HashList", items: @response