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
13 def self._logins_method_description
14 "List login permission links for a given virtual machine."
18 render_logins_for VirtualMachine.where(uuid: @object.uuid)
21 def self._get_all_logins_method_description
22 "List login permission links for all virtual machines."
25 # Get all login permissons for all VMs
27 render_logins_for VirtualMachine
32 def render_logins_for vm_query
34 @vms = vm_query.eager_load :login_permissions
36 User.eager_load(:authorized_keys).
37 where('users.uuid in (?)',
38 @vms.map { |vm| vm.login_permissions.map(&:tail_uuid) }.flatten.uniq).
43 vm.login_permissions.each do |perm|
44 user_uuid = perm.tail_uuid
45 next if not @users[user_uuid]
46 next if perm.properties['username'].blank?
47 aks = @users[user_uuid].authorized_keys
49 # We'll emit one entry, with no public key.
54 username: perm.properties['username'],
55 hostname: vm.hostname,
56 groups: (perm.properties['groups'].to_a rescue []),
57 public_key: ak ? ak.public_key : nil,
59 virtual_machine_uuid: vm.uuid,
60 authorized_key_uuid: ak ? ak.uuid : nil,
65 send_json kind: "arvados#HashList", items: @response