diff --git a/app/services/foreman/unattended_installation/concerns/host_finder_extensions.rb b/app/services/foreman/unattended_installation/concerns/host_finder_extensions.rb index d9be12b0e780089fa975d54f2e7770bf2dce35cc..20e6ffb9b9ac1b53f121c9d64ffd570faf8e339a 100644 --- a/app/services/foreman/unattended_installation/concerns/host_finder_extensions.rb +++ b/app/services/foreman/unattended_installation/concerns/host_finder_extensions.rb @@ -1,30 +1,28 @@ # frozen_string_literal: true -module ForemanUuidBoot - module HostFinderExtensions - def search - host = super - host ||= find_host_by_uuid unless token_from_params.present? +module HostFinderExtensions + def search + host = super + host ||= find_host_by_uuid unless token_from_params.present? - host - end + host + end - private + private - def find_host_by_uuid - return unless (uuid = query_params['uuid']) + def find_host_by_uuid + return unless (uuid = query_params['uuid']) - fact_name_id = FactName.where(name: 'uuid').map(&:id) - return unless fact_name_id.any? + fact_name_id = FactName.where(name: 'uuid').map(&:id) + return unless fact_name_id.any? - query = { fact_values: { fact_name_id: fact_name_id, value: uuid } } - hosts = Host.joins(:fact_values).where(query).order(:created_at) + query = { fact_values: { fact_name_id: fact_name_id, value: uuid } } + hosts = Host.joins(:fact_values).where(query).order(:created_at) - Rails.logger.warn("Multiple hosts found with #{uuid}, picking up the most recent") if hosts.count > 1 + Rails.logger.warn("Multiple hosts found with #{uuid}, picking up the most recent") if hosts.count > 1 - return unless hosts.present? + return unless hosts.present? - hosts.last.reload - end + hosts.last.reload end end