[APIP] Populate TokenId with hashed API-key#206
Conversation
|
Warning Review limit reached
More reviews will be available in 12 minutes and 29 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe API key authentication policy is updated to compute a Suggested Reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
policies/api-key-auth/apikey.go (1)
233-233: ⚡ Quick winExtract TokenId computation to a named variable or helper for improved readability.
The inline anonymous function is syntactically correct but not idiomatic Go. Consider computing the hash before struct creation:
// Option 1: Compute inline tokenId := hex.EncodeToString(sha256.Sum256([]byte(providedKey))[:]) shared.AuthContext = &policy.AuthContext{ // ... TokenId: tokenId, } // Option 2: Extract to helper (if reused) func computeTokenId(key string) string { return hex.EncodeToString(sha256.Sum256([]byte(key))[:]) }This improves clarity and follows Go conventions for struct initialization.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@policies/api-key-auth/apikey.go` at line 233, Extract the TokenId computation from the inline anonymous function into a simple variable assignment before struct initialization. Compute the SHA256 hash of the providedKey, encode it as hex, and assign it to a tokenId variable, then use that variable in the TokenId field of the AuthContext struct initialization. This replaces the anonymous function call with a straightforward variable reference, making the code more readable and idiomatic to Go conventions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@policies/api-key-auth/apikey.go`:
- Line 233: Extract the TokenId computation from the inline anonymous function
into a simple variable assignment before struct initialization. Compute the
SHA256 hash of the providedKey, encode it as hex, and assign it to a tokenId
variable, then use that variable in the TokenId field of the AuthContext struct
initialization. This replaces the anonymous function call with a straightforward
variable reference, making the code more readable and idiomatic to Go
conventions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4150d472-c176-4677-9763-e568519dea5a
⛔ Files ignored due to path filters (1)
policies/api-key-auth/go.sumis excluded by!**/*.sum
📒 Files selected for processing (3)
policies/api-key-auth/apikey.gopolicies/api-key-auth/go.modpolicies/api-key-auth/policy-definition.yaml
Refactored TokenId generation into a separate function for better readability and reusability.
Related to wso2/api-platform#2131
This pull request introduces an enhancement to the API key authentication policy by including a hashed token identifier in the authentication process, along with dependency updates and a version bump.
API Key Authentication Enhancements:
TokenIdto the authentication context, which stores a SHA-256 hash of the provided API key for improved traceability and security. (policies/api-key-auth/apikey.go)crypto/sha256andencoding/hexpackages to support the hashing functionality. (policies/api-key-auth/apikey.go)Dependency and Version Updates:
github.com/wso2/api-platform/sdk/coredependency to v0.2.14. (policies/api-key-auth/go.mod)policy-definition.yaml.