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

Prepare for zeitwerk

parent 5f9ba5b5
No related branches found
Tags v0.1.0
No related merge requests found
Pipeline #144131 failed
# frozen_string_literal: true
module ForemanUuidBoot
module HostFinderExtensions
def search
host = super
host ||= find_host_by_uuid unless token_from_params.present?
host
end
private
def find_host_by_uuid
return unless (uuid = query_params['uuid'])
facets = ForemanUuidBoot::UuidbootHostFacet.where(uuid: uuid).order(:created_at)
if facets.any?
Rails.logger.warn("Multiple hosts found with #{uuid}, choosing the most recent") if facets.count > 1
return facets.last.host.reload
end
return unless SETTINGS[:uuidboot_factsearch]
# Fallback fact search
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)
Rails.logger.warn("Multiple hosts found with #{uuid}, choosing the most recent") if hosts.count > 1
return unless hosts.present?
hosts.last.reload
end
end
end
# frozen_string_literal: true
module HostFinderExtensions
def search
host = super
host ||= find_host_by_uuid unless token_from_params.present?
host
end
private
def find_host_by_uuid
return unless (uuid = query_params['uuid'])
facets = ForemanUuidBoot::UuidbootHostFacet.where(uuid: uuid).order(:created_at)
if facets.any?
Rails.logger.warn("Multiple hosts found with #{uuid}, choosing the most recent") if facets.count > 1
return facets.last.host.reload
end
return unless SETTINGS[:uuidboot_factsearch]
# Fallback fact search
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)
Rails.logger.warn("Multiple hosts found with #{uuid}, choosing the most recent") if hosts.count > 1
return unless hosts.present?
hosts.last.reload
end
end
......@@ -13,13 +13,15 @@ module ForemanUuidBoot
end
end
initializer 'foreman_uuid_boot.register_plugin', before: :finisher_hook do |_app|
Foreman::Plugin.register :foreman_uuid_boot do
requires_foreman '>= 2.5'
register_facet ForemanUuidBoot::UuidbootHostFacet, :uuidboot_facet do
configure_host do
set_dependent_action :destroy
initializer 'foreman_uuid_boot.register_plugin', before: :finisher_hook do |app|
app.reloader.to_prepare do
Foreman::Plugin.register :foreman_uuid_boot do
requires_foreman '>= 3.12'
register_facet ForemanUuidBoot::UuidbootHostFacet, :uuidboot_facet do
configure_host do
set_dependent_action :destroy
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