Skip to content

Commit

Permalink
Add scoped search and rabl nodes for IoP
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Dec 18, 2024
1 parent d8d9703 commit 1d61d10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/concerns/rh_cloud_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ module RhCloudHost
scoped_search :relation => :inventory_sync_status_object, :on => :status, :rename => :insights_inventory_sync_status,
:complete_value => { :disconnect => ::InventorySync::InventoryStatus::DISCONNECT,
:sync => ::InventorySync::InventoryStatus::SYNC }
scoped_search :relation => :insights, :on => :uuid, :only_explicit => true, :rename => :insights_uuid

def insights_facet
insights
end
end
end
5 changes: 5 additions & 0 deletions app/views/api/v2/hosts/insights/base.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
attributes :uuid

node :insights_hit_details do |facet|
facet&.host&.facts('insights::hit_details')&.values&.first
end
3 changes: 3 additions & 0 deletions app/views/api/v2/hosts/insights/insights.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node :insights_attributes do
partial 'api/v2/hosts/insights/base', object: @object&.insights_facet
end
7 changes: 7 additions & 0 deletions lib/foreman_rh_cloud/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def self.register_scheduled_task(task_class, cronline)

register_facet InsightsFacet, :insights do
configure_host do
api_view :list => 'api/v2/hosts/insights/insights'
set_dependent_action :destroy
end
end
Expand Down Expand Up @@ -151,6 +152,12 @@ def self.register_scheduled_task(task_class, cronline)
end
end

initializer "foreman_rh_cloud.add_rabl_view_path" do
Rabl.configure do |config|
config.view_paths << ForemanRhCloud::Engine.root.join('app', 'views')
end
end

initializer 'foreman_rh_cloud.register_scheduled_tasks', :before => :finisher_hook do |_app|
# skip database manipulations while tables do not exist, like in migrations
# skip object creation when admin user is not present, for example in test DB
Expand Down

0 comments on commit 1d61d10

Please sign in to comment.