1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class Arvados::V1::VirtualMachinesController < ApplicationController
6 skip_before_action :find_object_by_uuid, :only => :get_all_logins
7 skip_before_action :render_404_if_no_object, :only => :get_all_logins
8 before_action(:admin_required,
9 :only => [:logins, :get_all_logins])
11 # Get all login permissons (user uuid, login account, SSH key) for a
14 render_logins_for VirtualMachine.where(uuid: @object.uuid)
17 # Get all login permissons for all VMs
19 render_logins_for VirtualMachine
24 def render_logins_for vm_query
26 @vms = vm_query.eager_load :login_permissions
28 User.eager_load(:authorized_keys).
29 where('users.uuid in (?)',
30 @vms.map { |vm| vm.login_permissions.map(&:tail_uuid) }.flatten.uniq).
35 vm.login_permissions.each do |perm|
36 user_uuid = perm.tail_uuid
37 next if not @users[user_uuid]
38 next if perm.properties['username'].blank?
39 aks = @users[user_uuid].authorized_keys
41 # We'll emit one entry, with no public key.
46 username: perm.properties['username'],
47 hostname: vm.hostname,
48 groups: (perm.properties['groups'].to_a rescue []),
49 public_key: ak ? ak.public_key : nil,
51 virtual_machine_uuid: vm.uuid,
52 authorized_key_uuid: ak ? ak.uuid : nil,
57 send_json kind: "arvados#HashList", items: @response