fix: add user for patch to call content sources API#2264
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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 :) |
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
To fix the rejected requests from patch 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:
Tests: