-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #934 from jeremylenz/add-rabl-and-scoped-search
Add endpoint and rabl nodes for IoP
- Loading branch information
Showing
9 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/controllers/api/v2/advisor_engine/advisor_engine_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Api | ||
module V2 | ||
module AdvisorEngine | ||
class AdvisorEngineController < ::Api::V2::BaseController | ||
include ::Api::Version2 | ||
|
||
api :GET, "/advisor_engine/host_details", N_('Fetch Insights-related host details') | ||
param :host_uuids, Array, required: true, desc: N_('List of host UUIDs') | ||
def host_details | ||
uuids = params.require(:host_uuids) | ||
@hosts = ::Host.joins(:insights).where(:insights => { :uuid => uuids }) | ||
if @hosts.empty? | ||
render json: { error: 'No hosts found for the given UUIDs' }, status: :not_found | ||
else | ||
respond_to do |format| | ||
format.json { render 'api/v2/advisor_engine/host_details' } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
collection @hosts | ||
|
||
attributes :name | ||
node :insights_uuid do |host| | ||
host.insights_facet&.uuid | ||
end | ||
node :insights_hit_details do |host| | ||
host&.facts('insights::hit_details')&.values&.first | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/controllers/insights_cloud/api/advisor_engine_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'test_plugin_helper' | ||
|
||
module InsightsCloud | ||
module Api | ||
class AdvisorEngineControllerTest < ActionController::TestCase | ||
tests ::Api::V2::AdvisorEngine::AdvisorEngineController | ||
|
||
setup do | ||
@test_org = FactoryBot.create(:organization) | ||
@host1 = FactoryBot.create(:host, :with_insights_hits, organization: @test_org, hostname: 'insightshost1') | ||
@host2 = FactoryBot.create(:host, :with_insights_hits, organization: @test_org, hostname: 'insightshost2') | ||
@host3 = FactoryBot.create(:host, organization: @test_org) | ||
end | ||
|
||
test 'shows hosts with uuids' do | ||
uuids = [@host1.insights.uuid, @host2.insights.uuid] | ||
get :host_details, params: { organization_id: @test_org.id, host_uuids: uuids } | ||
assert_response :success | ||
assert_template 'api/v2/advisor_engine/host_details' | ||
assert_equal @test_org.hosts.joins(:insights).where(:insights => { :uuid => uuids }).count, assigns(:hosts).count | ||
refute_equal @test_org.hosts.count, assigns(:hosts).count | ||
end | ||
|
||
test 'shows error when no hosts found' do | ||
get :host_details, params: { organization_id: @test_org.id, host_uuids: ['nonexistentuuid'] } | ||
assert_response :not_found | ||
assert_equal 'No hosts found for the given UUIDs', JSON.parse(response.body)['error'] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters