-
Notifications
You must be signed in to change notification settings - Fork 380
fix: add validation for redundancy level in bytes and bzz handlers #5311
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
Conversation
…bytes upload handler
3c3c515 to
b7d9bcc
Compare
038716d to
d5857af
Compare
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.
Pull request overview
This PR adds validation for the redundancy level parameter in both bytes and bzz upload/download handlers. It introduces a new Validate() method for the redundancy.Level type to ensure values fall within the valid range (NONE to PARANOID), and integrates this validation with a custom validator registration in the API service.
- Adds
Validate()method toredundancy.Levelfor range checking - Creates custom validation infrastructure with
setupValidation()function and custom error messages - Applies validation tags to
RLevelfields across bytes and bzz handlers (both upload and download)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/file/redundancy/level.go | Adds Validate() method to check if redundancy level is within valid range (NONE to PARANOID) |
| pkg/api/validation.go | New file containing custom validation setup, registering the "rLevel" validator and custom error messages |
| pkg/api/api.go | Updates Service struct to include customValidationMessages map, calls setupValidation() during initialization, and enhances error handling to use custom validation messages |
| pkg/api/bytes.go | Adds "rLevel" validation tag to RLevel field in bytesUploadHandler |
| pkg/api/bzz.go | Adds "rLevel" validation tag to RLevel fields in bzzUploadHandler, serveReference, and downloadHandler (using "omitempty,rLevel" for pointer types) |
| pkg/api/bytes_test.go | Adds comprehensive tests for redundancy level validation including boundary cases (minimum, maximum, below minimum, above maximum) |
| pkg/api/bzz_test.go | Adds tests for redundancy level validation in both upload and download scenarios |
| openapi/Swarm.yaml | Refactors parameter definitions to use references instead of inline definitions (formatting improvement) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Checklist
Description
Adds validation for the
Swarm-Redundancy-Levelheader in bytes and BZZ upload/download handlers to ensure values are within the valid range (NONE to PARANOID).Changes
rLevelvalidation tag instead oflte=4to reuse existingLevel.Validate()method and provide clearer error messages referencing enum constantsFiles Changed
openapi/Swarm.yamlpkg/api/api.gopkg/api/bytes.gopkg/api/bytes_test.gopkg/api/bzz.gopkg/api/bzz_test.gopkg/api/validation.gopkg/file/redundancy/level.goOpen API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):