Skip to content

Conversation

jeremylenz
Copy link
Member

@jeremylenz jeremylenz commented Sep 5, 2025

What are the changes introduced in this pull request?

Katello provides 3 ways to give a url to contact Hosted Candlepin, in order:

  1. (For devel environments only) you can use the environment variable REDHAT_RHSM_API_URL.
  2. If your organization's upstream consumer has a value for 'apiUrl', it uses that.
  3. Finally, it falls back to hard-coded URLs.

We can see the format of the expected URL by looking at the hard-coded ones:

In Glue::Provider:
API_URL = 'https://subscription.rhsm.redhat.com/subscription/consumers/'.freeze

But in Katello::Resources::Candlepin::UpstreamJob it doesn't append '/consumers/':
API_URL = 'https://subscription.rhsm.redhat.com/subscription'.freeze

The result is that if the upstream consumer in your manifest has an apiUrl that appends the '/consumers/' path, calls from Glue::Provider will succeed but calls to UpstreamJob will fail. But if your manifest does NOT append the '/consumers/' path, calls from Glue::Provider will fail and calls to UpstreamJob will succeed.

Katello needs to handle adding or subtracting the '/consumers/' as needed.

This change will allow your apiUrl to either have or not have /consumers/ at the end, and manifest refreshes should work either way.

Considerations taken when implementing this change?

What are the testing steps for this pull request?

Summary by Sourcery

Ensure Katello correctly handles apiUrl values with or without the "/consumers/" suffix by normalizing URLs in both Glue::Provider and UpstreamJob

Enhancements:

  • Normalize API URL handling by always appending "/consumers/" in Glue::Provider when missing
  • Strip trailing "/consumers/" in UpstreamJob.get to avoid duplicate path segments
  • Introduce API_BASE_URL and CONSUMERS_PATH constants to centralize URL components
  • Add url_from_manifest helper to unify manifest URL parsing in Glue::Provider

Copy link

sourcery-ai bot commented Sep 5, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Normalize manifest apiUrl handling by introducing base and consumers path constants, and by appending or stripping '/consumers/' in both the Glue provider and the Candlepin upstream job so that API URLs work regardless of manifest formatting.

Class diagram for updated API URL handling in Glue::Provider and UpstreamJob

classDiagram
class Glue_Provider {
  +API_BASE_URL: String
  +CONSUMERS_PATH: String
  +API_URL: String
  +url_from_manifest(upstream)
  +api_url(upstream)
}
class UpstreamJob {
  +API_URL: String
  +CONSUMERS_PATH: String
  +get(id, upstream)
}
Glue_Provider <|-- UpstreamJob
Loading

Flow diagram for manifest apiUrl normalization logic

flowchart TD
  A["Manifest provides apiUrl"] --> B{Does apiUrl end with '/consumers/'?}
  B -- Yes --> C["Use apiUrl as-is for Glue::Provider"]
  B -- No --> D["Append '/consumers/' for Glue::Provider"]
  C --> E["Use apiUrl for API calls"]
  D --> E
  A --> F["For UpstreamJob, strip '/consumers/' if present"]
  F --> G["Use normalized apiUrl for API calls"]
Loading

File-Level Changes

Change Details Files
Refactor provider API URL constants
  • Add API_BASE_URL and CONSUMERS_PATH constants
  • Update API_URL to be API_BASE_URL + CONSUMERS_PATH
app/models/katello/glue/provider.rb
Implement url normalization in provider
  • Add url_from_manifest to append CONSUMERS_PATH if missing
  • Update api_url to use url_from_manifest instead of raw upstream['apiUrl']
app/models/katello/glue/provider.rb
Handle consumers path in Candlepin upstream job
  • Define CONSUMERS_PATH constant
  • Strip trailing CONSUMERS_PATH from upstream['apiUrl'] in get method
app/lib/katello/resources/candlepin/upstream_job.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

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

Successfully merging this pull request may close these issues.

1 participant