Skip to content
Snippets Groups Projects
Verified Commit f5c6ee6a authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Fix extension namespacing

parent d0b4e274
No related branches found
No related tags found
No related merge requests found
Pipeline #87566 passed
# frozen_string_literal: true # frozen_string_literal: true
module ForemanUuidBoot module HostFinderExtensions
module HostFinderExtensions def search
def search host = super
host = super host ||= find_host_by_uuid unless token_from_params.present?
host ||= find_host_by_uuid unless token_from_params.present?
host host
end end
private private
def find_host_by_uuid def find_host_by_uuid
return unless (uuid = query_params['uuid']) return unless (uuid = query_params['uuid'])
fact_name_id = FactName.where(name: 'uuid').map(&:id) fact_name_id = FactName.where(name: 'uuid').map(&:id)
return unless fact_name_id.any? return unless fact_name_id.any?
query = { fact_values: { fact_name_id: fact_name_id, value: uuid } } query = { fact_values: { fact_name_id: fact_name_id, value: uuid } }
hosts = Host.joins(:fact_values).where(query).order(:created_at) 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 hosts.last.reload
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment