Skip to content

Allow hosts controller to find hosts by Subscription UUID #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jeremylenz
Copy link
Collaborator

@jeremylenz jeremylenz commented Jul 24, 2025

What are the changes introduced in this pull request?

Override the find_resource method of Foreman's Api::V2::HostsController and HostsController, so that you can access hosts by Insights UUID Subscription UUID.

Considerations taken when implementing this change?

We already have a gem in place, FriendlyId, that allows us to use host FQDNs as IDs. Sadly, though, that gem does not allow using more than one field name as an ID. So I had to develop this custom solution.

Originally I had only extended Api::V2::HostsController, but the Host Statuses card was not working. I realized that makes a call to /hosts/:id/statuses (note the lack of api/v2) so I had to extend the other controller as well.

What are the testing steps for this pull request?

Try to access the host details page via Subscription UUID in the url, such as

https://centos9-katello-devel.fedora.example.com/new/hosts/c39d1627-c958-433b-afc9-b3242be6717a#/Insights

Summary by Sourcery

Override the find_resource method in Foreman’s API V2 and UI HostsController to enable fetching hosts by Subscription UUID

Enhancements:

  • Include a concern in the engine to extend both Api::V2::HostsController and HostsController with custom behavior
  • Override find_resource to first attempt host lookup via Katello::Host::SubscriptionFacet by UUID before falling back to default ID lookup

Copy link

sourcery-ai bot commented Jul 24, 2025

Reviewer's Guide

This PR enables host lookup by Subscription UUID by introducing a custom controller extension that overrides the find_resource method in both the API and UI HostsController, and registering these extensions in the engine.

File-Level Changes

Change Details Files
Register controller extensions in engine configuration
  • Included the HostsControllerExtensions concern into Api::V2::HostsController
  • Included the HostsControllerExtensions concern into HostsController
lib/foreman_rh_cloud/engine.rb
Implement custom find_resource override for subscription UUID lookup
  • Added a new concern defining find_resource to lookup hosts via SubscriptionFacet.find_by(uuid:)
  • Logged when a host is found by subscription UUID and fell back to default lookup
app/controllers/foreman_rh_cloud/concerns/api/v2/hosts_controller_extensions.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@jeremylenz jeremylenz force-pushed the iop-friendly-id-uuid branch 2 times, most recently from fb8986b to 1eaa925 Compare July 25, 2025 21:13
@jeremylenz jeremylenz changed the title Allow hosts controller to find hosts by Insights UUID Allow hosts controller to find hosts by Subscription UUID Jul 25, 2025
@jeremylenz jeremylenz force-pushed the iop-friendly-id-uuid branch from 1eaa925 to 20aecae Compare July 25, 2025 21:16
@jeremylenz jeremylenz marked this pull request as ready for review July 25, 2025 21:16
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jeremylenz - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `lib/foreman_rh_cloud/engine.rb:90` </location>
<code_context>
+      # API controller extensions
+      ::Api::V2::HostsController.include ::ForemanRhCloud::Concerns::Api::V2::HostsControllerExtensions
+
+      # Controller extensions
+      ::HostsController.include ::ForemanRhCloud::Concerns::Api::V2::HostsControllerExtensions
     end

</code_context>

<issue_to_address>
Including the same concern in both API and non-API controllers may introduce unintended behavior.

The concern's logic seems designed for API controllers, particularly regarding parameter handling. Please verify it works correctly with both API and non-API controllers to avoid potential issues.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@jeremylenz
Copy link
Collaborator Author

@vkrizan I didn't realize before that Insights UUID and Subscription UUID were not the same. I changed it to use Subscription UUID.

(Now I have no idea what the Insights facet UUID is for.. 🤷 )

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the code and confirmed that it's working as expected. The host is successfully resolved via the subscription UUID.

However, when I click on the host in the UI, it redirects to the old Host Details page instead of the new one.

@jeremylenz
Copy link
Collaborator Author

when I click on the host in the UI, it redirects to the old Host Details page instead of the new one

You mean the link from Vuln? The link would need to use /new/hosts/ and not just /hosts/ in their url.

@nofaralfasi
Copy link
Contributor

nofaralfasi commented Jul 28, 2025

You mean the link from Vuln? The link would need to use /new/hosts/ and not just /hosts/ in their url.

Yes, when I click on one of the hosts from the https://sat.example.com/foreman_rh_cloud/insights_vulnerability/CVE-ID page.

I'm redirected to the old host details page:
https://sat.example.com/hosts/SUB_UUID#/Vulnerabilities
instead of the expected URL format:
https://sat.example.com/new/hosts/SUB_UUID#/Vulnerabilities.

@vkrizan
Copy link
Contributor

vkrizan commented Jul 29, 2025

@nofaralfasi @ShimShtein please coordinate the required URLs/paths with @leSamo. Thanks!

@jeremylenz
Copy link
Collaborator Author

Opened #1048 as an alternate solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants