Skip to content

fix: add user for patch to call content sources API#2264

Merged
xbhouse merged 1 commit into
RedHatInsights:masterfrom
xbhouse:add-user
Jul 10, 2026
Merged

fix: add user for patch to call content sources API#2264
xbhouse merged 1 commit into
RedHatInsights:masterfrom
xbhouse:add-user

Conversation

@xbhouse

@xbhouse xbhouse commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

To fix the rejected requests from patch to content sources:

  • Adds a user environment variable to the deployment
  • Adds this user to the identity of the request to content sources endpoint that lists template advisory IDs for a specific template
  • If this user is empty, no request is sent to content sources

Related to content-services/content-sources-backend#1556

Summary by Sourcery

Add support for configuring a content sources user and include it in identity used for content sources requests.

Enhancements:

  • Extend core configuration and deployment to provide a CONTENT_SOURCES_USER environment parameter.
  • Include the configured content sources user in the XRHID identity used for content sources calls.
  • Guard template advisory synchronization so it only runs when a content sources user is configured.

Tests:

  • Update identity tests to validate the content sources user is included in the generated XRHID.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds configuration for a content sources user, injects that user into the XRH identity for content sources requests, and gates template advisory sync on the presence of both the content sources base URL and user.

File-Level Changes

Change Details Files
Inject configured content sources user into generated XRH identities used for content sources requests.
  • Update XRHIDForOrg to populate the Identity.User.Username field from the core configuration
  • Adjust the XRH identity unit test to set and validate the configured content sources user and to clean up the global config after the test
base/utils/identity.go
base/utils/identity_test.go
Add CONTENT_SOURCES_USER configuration and wiring through environment, config, and deployment.
  • Extend core configuration struct to include ContentSourcesUser field and initialize it from the CONTENT_SOURCES_USER environment variable
  • Expose CONTENT_SOURCES_USER as a parameter and environment variable for the listener service in the ClowdApp deployment manifest
  • Add CONTENT_SOURCES_USER entries to environment configuration files
base/utils/config.go
deploy/clowdapp.yaml
conf/common.env
conf/local.env
Gate content sources template advisory sync on the presence of a configured content sources user.
  • Update TemplateUpdate to require both a non-empty contentSourcesBaseURL and a non-empty ContentSourcesUser before calling syncTemplateAdvisories
listener/templates.go

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

@codecov-commenter

codecov-commenter commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.79%. Comparing base (48834b4) to head (846412c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2264      +/-   ##
==========================================
+ Coverage   58.77%   58.79%   +0.02%     
==========================================
  Files         147      147              
  Lines        9235     9240       +5     
==========================================
+ Hits         5428     5433       +5     
  Misses       3235     3235              
  Partials      572      572              
Flag Coverage Δ
unittests 58.79% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xbhouse xbhouse marked this pull request as ready for review July 9, 2026 15:32
@xbhouse xbhouse requested a review from a team as a code owner July 9, 2026 15:32
@xbhouse

xbhouse commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

related MR: https://gitlab.cee.redhat.com/service/app-interface/-/merge_requests/196165

i haven't set deployment variables like this in patch before so let me know if it looks off :)

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider passing the content sources username into XRHIDForOrg instead of reading CoreCfg directly to keep identity construction decoupled from global configuration and easier to reuse.
  • You gate advisory sync on ContentSourcesUser being non-empty, but still build identities with a possibly empty Username; if an empty user should never reach content-sources, it may be clearer to validate or fail fast when the config is missing rather than silently skipping.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider passing the content sources username into XRHIDForOrg instead of reading CoreCfg directly to keep identity construction decoupled from global configuration and easier to reuse.
- You gate advisory sync on ContentSourcesUser being non-empty, but still build identities with a possibly empty Username; if an empty user should never reach content-sources, it may be clearer to validate or fail fast when the config is missing rather than silently skipping.

## Individual Comments

### Comment 1
<location path="base/utils/identity_test.go" line_range="54" />
<code_context>
 	assert.Equal(t, orgID, xrhid.Identity.OrgID)
 	assert.Equal(t, orgID, xrhid.Identity.Internal.OrgID)
 	assert.Equal(t, "User", xrhid.Identity.Type)
+	assert.Equal(t, CoreCfg.ContentSourcesUser, xrhid.Identity.User.Username)
 }
</code_context>
<issue_to_address>
**suggestion (testing):** Extend identity tests to cover the nil/empty-user edge cases

This test currently only covers the case where `CoreCfg.ContentSourcesUser` is non-empty. Please also (1) assert that `xrhid.Identity.User` is non-nil here, and (2) add a test (e.g., `TestXRHIDForOrgWithoutContentSourcesUser`) that sets `CoreCfg.ContentSourcesUser` to `""` and verifies the resulting `xrhid.Identity` (including whether `User` is nil vs. having an empty `Username`). That will define behavior for when the content sources user is not configured.

Suggested implementation:

```golang
	orgID := "1234"
	xrhid := XRHIDForOrg(orgID)

	assert.Equal(t, orgID, xrhid.Identity.OrgID)
	assert.Equal(t, orgID, xrhid.Identity.Internal.OrgID)
	assert.Equal(t, "User", xrhid.Identity.Type)
	assert.NotNil(t, xrhid.Identity.User)
	assert.Equal(t, CoreCfg.ContentSourcesUser, xrhid.Identity.User.Username)
}

func TestContentSourcesXRHIDForOrg(t *testing.T) {
	const testUser = "test-user"
	originalUser := CoreCfg.ContentSourcesUser
	CoreCfg.ContentSourcesUser = testUser
	t.Cleanup(func() {
		CoreCfg.ContentSourcesUser = originalUser
	})

	orgID := "1234"
	xrhid := XRHIDForOrg(orgID)

	assert.Equal(t, orgID, xrhid.Identity.OrgID)
	assert.Equal(t, orgID, xrhid.Identity.Internal.OrgID)
	assert.Equal(t, "User", xrhid.Identity.Type)
	assert.NotNil(t, xrhid.Identity.User)
	assert.Equal(t, testUser, xrhid.Identity.User.Username)
}

func TestXRHIDForOrgWithoutContentSourcesUser(t *testing.T) {
	originalUser := CoreCfg.ContentSourcesUser
	CoreCfg.ContentSourcesUser = ""
	t.Cleanup(func() {
		CoreCfg.ContentSourcesUser = originalUser
	})

	orgID := "1234"
	xrhid := XRHIDForOrg(orgID)

	assert.Equal(t, orgID, xrhid.Identity.OrgID)
	assert.Equal(t, orgID, xrhid.Identity.Internal.OrgID)
	assert.Equal(t, "User", xrhid.Identity.Type)
	assert.Nil(t, xrhid.Identity.User)
}

```

If the first `orgID := "1234"` block is already inside a test function (e.g., `TestXRHIDForOrg`), wrap it with the appropriate `func Test...` signature so that the added `assert.NotNil` and `Username` assertion compile. Also ensure that `XRHIDForOrg` is expected to return a `nil` `User` when `CoreCfg.ContentSourcesUser` is empty; if the actual behavior is "non-nil `User` with empty `Username`", adjust the final assertion in `TestXRHIDForOrgWithoutContentSourcesUser` to `assert.NotNil(t, xrhid.Identity.User)` and `assert.Empty(t, xrhid.Identity.User.Username)` instead.
</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.

Comment thread base/utils/identity_test.go Outdated

@TenSt TenSt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm!

@TenSt TenSt self-assigned this Jul 10, 2026
@xbhouse xbhouse merged commit be6b782 into RedHatInsights:master Jul 10, 2026
8 checks passed
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