Skip to content

Commit

Permalink
Refs #38072 - add host searching to bootc images api
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Dec 17, 2024
1 parent fb3bd87 commit 29a8e15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/controllers/katello/api/v2/host_bootc_images_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Katello
class Api::V2::HostBootcImagesController < Api::V2::ApiController
include Katello::Concerns::FilteredAutoCompleteSearch

resource_description do
api_version 'v2'
api_base_url "/api"
Expand All @@ -9,7 +11,8 @@ class Api::V2::HostBootcImagesController < Api::V2::ApiController
param :page, :number, :desc => N_("Page number, starting at 1")
param :per_page, :number, :desc => N_("Number of results per page to return")
def bootc_images
bootc_image_map = bootc_host_image_map
bootc_image_map = bootc_host_image_map(params[:search])

page = params[:page].to_i || 1
per_page = params[:per_page].to_i || Setting[:entries_per_page]
paged_images = bootc_image_map.to_a.paginate(page: page, per_page: per_page)
Expand All @@ -19,8 +22,20 @@ def bootc_images

private

def bootc_host_image_map
aggregate_bootc_data = ::Katello::Host::ContentFacet.where.not(bootc_booted_image: nil, bootc_booted_digest: nil).
def index_relation
query = resource_class.authorized(:view_hosts).distinct
query.joins(:content_facet).where.not(bootc_booted_image: nil, bootc_booted_digest: nil)
query
end

def resource_class
::Host::Managed
end

def bootc_host_image_map(host_search)
# Todo: can this be optimized such that it doesn't require two queries?

Check failure on line 36 in app/controllers/katello/api/v2/host_bootc_images_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/CommentAnnotation: Annotation keywords like `Todo` should be all upper case, followed by a colon, and a space, then a note describing the problem.
content_facets = ::Katello::Host::ContentFacet.where(host_id: ::Host::Managed.joins(:content_facet).search_for(host_search).pluck(:id))
aggregate_bootc_data = content_facets.where.not(bootc_booted_image: nil, bootc_booted_digest: nil).
select(:bootc_booted_image, :bootc_booted_digest, 'COUNT(hosts.id) as host_count').
joins(:host).group(:bootc_booted_image, :bootc_booted_digest).order(:bootc_booted_image)
bootc_image_map = Hash.new { |h, k| h[k] = [] }
Expand Down
4 changes: 4 additions & 0 deletions config/routes/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class ActionDispatch::Routing::Mapper
end
end

api_resources :host_bootc_images, :only => [:bootc_images] do
get :auto_complete_search, :on => :collection
end

api_resources :capsules, :only => [:index, :show] do
member do
resource :content, :only => [], :controller => 'capsule_content' do
Expand Down

0 comments on commit 29a8e15

Please sign in to comment.