Refactor auth/HMAC request rejection call sites to remove duplicated constants#7383
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor rejectRequest calls to avoid hardcoded constants
Refactor auth/HMAC request rejection call sites to remove duplicated constants
Jun 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors repeated rejectRequest(...) call sites in the auth and HMAC middleware by introducing thin, unexported wrapper helpers that encapsulate the fixed "auth" log category and fixed runtime error type tokens, reducing duplication while preserving existing rejection behavior and HTTP response semantics.
Changes:
- Added
rejectAuthRequest(...)ininternal/server/middleware.goand replaced repeated auth rejection call sites with it. - Added
rejectHMACRequest(...)ininternal/server/hmac.goand replaced repeated HMAC rejection call sites with it.
Show a summary per file
| File | Description |
|---|---|
| internal/server/middleware.go | Introduces rejectAuthRequest helper and uses it for consistent auth rejection calls. |
| internal/server/hmac.go | Introduces rejectHMACRequest helper and uses it for consistent HMAC rejection calls. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rejectRequestwas repeatedly invoked with fixed"auth"category and fixed error-type tokens across auth and HMAC middleware, creating noisy 8-arg call sites and a refactor hazard. This change centralizes those constants behind thin, file-local wrappers while preserving existing behavior and response semantics.Auth middleware cleanup (
internal/server/middleware.go)rejectAuthRequest(w, r, status, code, msg, detail)wrapper.rejectRequest(..., "auth", "authentication_failed", detail)calls with the wrapper.HMAC middleware cleanup (
internal/server/hmac.go)rejectHMACRequest(w, r, status, code, msg, detail)wrapper.rejectRequest(..., "auth", "hmac_validation_failed", detail)calls with the wrapper.Outcome