-
Notifications
You must be signed in to change notification settings - Fork 41
RHINENG-22863: limit systems to 1000 in update and delete template system apis #2031
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
base: master
Are you sure you want to change the base?
Conversation
|
Referenced Jiras: |
Reviewer's GuideAdds a hard limit of 1000 systems per request to the template systems update and delete APIs and validates incoming payloads against this limit, returning a 400 error with a clear message when exceeded, along with tests for the new behavior. Sequence diagram for template systems update with max-systems validationsequenceDiagram
actor Client
participant GinRouter
participant TemplateSystemsUpdateHandler
participant Utils
participant Candlepin
Client->>GinRouter: HTTP PATCH /templates/{id}/systems
GinRouter->>TemplateSystemsUpdateHandler: TemplateSystemsUpdateHandler(c)
TemplateSystemsUpdateHandler->>TemplateSystemsUpdateHandler: ParseAndValidateRequestBody
TemplateSystemsUpdateHandler->>TemplateSystemsUpdateHandler: Check account and groups
TemplateSystemsUpdateHandler->>TemplateSystemsUpdateHandler: len(req.Systems) > TemplateSystemsUpdateLimit?
alt Over_limit
TemplateSystemsUpdateHandler->>Utils: LogAndRespBadRequest(c, err, msg)
Utils-->>Client: HTTP 400 Cannot update more than 1000 systems at once
else Within_limit
TemplateSystemsUpdateHandler->>TemplateSystemsUpdateHandler: DBFromContext(c)
TemplateSystemsUpdateHandler->>Candlepin: Update template systems
Candlepin-->>TemplateSystemsUpdateHandler: Success
TemplateSystemsUpdateHandler-->>Client: HTTP 200 OK
end
Sequence diagram for template systems delete with max-systems validationsequenceDiagram
actor Client
participant GinRouter
participant TemplateSystemsDeleteHandler
participant Utils
participant Candlepin
Client->>GinRouter: HTTP DELETE /templates/{id}/systems
GinRouter->>TemplateSystemsDeleteHandler: TemplateSystemsDeleteHandler(c)
TemplateSystemsDeleteHandler->>TemplateSystemsDeleteHandler: ParseAndValidateRequestBody
TemplateSystemsDeleteHandler->>TemplateSystemsDeleteHandler: Check account and groups
TemplateSystemsDeleteHandler->>TemplateSystemsDeleteHandler: len(req.Systems) > TemplateSystemsUpdateLimit?
alt Over_limit
TemplateSystemsDeleteHandler->>Utils: LogAndRespBadRequest(c, err, msg)
Utils-->>Client: HTTP 400 Cannot update more than 1000 systems at once
else Within_limit
TemplateSystemsDeleteHandler->>TemplateSystemsDeleteHandler: DBFromContext(c)
TemplateSystemsDeleteHandler->>Candlepin: Remove systems from template
Candlepin-->>TemplateSystemsDeleteHandler: Success
TemplateSystemsDeleteHandler-->>Client: HTTP 200 OK
end
Updated class diagram for template systems controllers with max-systems limitclassDiagram
class TemplateSystemsUpdateRequest {
+[]string Remove
+[]string Apply
+[]string Systems
}
class TemplateSystemsUpdateHandlerController {
+TemplateSystemsUpdateHandler(c *gin.Context)
+int TemplateSystemsUpdateLimit
}
class TemplateSystemsDeleteHandlerController {
+TemplateSystemsDeleteHandler(c *gin.Context)
}
class Utils {
+LogAndRespBadRequest(c *gin.Context, err error, msg string)
}
TemplateSystemsUpdateHandlerController --> TemplateSystemsUpdateRequest : uses
TemplateSystemsUpdateHandlerController --> Utils : calls
TemplateSystemsDeleteHandlerController --> Utils : calls
TemplateSystemsDeleteHandlerController --> TemplateSystemsUpdateHandlerController : uses_TemplateSystemsUpdateLimit
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The over-limit check and error message are duplicated between TemplateSystemsUpdateHandler and TemplateSystemsDeleteHandler; consider extracting a small shared helper (or shared error message constant) to keep behavior and wording in sync.
- The error message uses "update" even in the delete handler and its tests; consider rephrasing to something operation-agnostic like "process" or using separate messages for update vs delete to avoid confusing API consumers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The over-limit check and error message are duplicated between TemplateSystemsUpdateHandler and TemplateSystemsDeleteHandler; consider extracting a small shared helper (or shared error message constant) to keep behavior and wording in sync.
- The error message uses "update" even in the delete handler and its tests; consider rephrasing to something operation-agnostic like "process" or using separate messages for update vs delete to avoid confusing API consumers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2031 +/- ##
==========================================
+ Coverage 59.25% 59.30% +0.05%
==========================================
Files 134 134
Lines 8615 8626 +11
==========================================
+ Hits 5105 5116 +11
Misses 2967 2967
Partials 543 543
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Dugowitch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
MichaelMraka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks and congratulation on your first PR to Patch. ;)
| err := errors.New(msg) | ||
| utils.LogAndRespBadRequest(c, err, msg) | ||
| return | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sourcery has a good point this could be a small helper function to keep wording an behavior consitent, e.g.
func CheckTemplateSystemsLimit(nSystems int) err {
if len(nSystems) > TemplateSystemsUpdateLimit {
msg := fmt.Sprintf("Cannot update more than %d systems at once", TemplateSystemsUpdateLimit)
err := errors.New(msg)
utils.LogAndRespBadRequest(c, err, msg)
return err
}
return nil
}
and then in code
if err = CheckTemplateSystemsLimit(len(req.Systems)); err != nil {
// result code handeled in CheckTemplateSystemsLimit()
return
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And possibly 'Cannot update' could be changed to some neutral wording which fits both update and delete. Maybe 'Cannot process'?!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes this is better, thank you! updated :)
Updating or deleting a template from more than 1000 systems at one time results in a candlepin error, likely because we are hitting a defined limit:
This PR limits the number of requested systems to 1000 in the update and delete template system apis.
Summary by Sourcery
Enforce a maximum number of systems that can be updated or removed from a template in a single API call to prevent downstream Candlepin errors.
Bug Fixes:
Enhancements: