fix: Missing plan check and ip whitelist parsing
What does this PR do?
This checks whether the Workspace is allowed to have IP whitelisting. It also fixes the parsing of the whitelisted IPs as which lead to a 500 error before.
Fixes #2372
Type of change
- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] Chore (refactoring code, technical debt, workflow improvements)
- [ ] Enhancement (small improvements)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
How should this be tested?
Manually send the updated whitelist topic call with an API and workspace ID with the pro or free plan. This should give an error and not go through.
Afterwards, test by doing a curl and overwriting the True-Client-IP to an invalid and then valid IP to see if the IP Whitelist works properly.
Checklist
Required
- [X] Filled out the "How to test" section in this PR
- [X] Read Contributing Guide
- [X] Self-reviewed my own code
- [X] Commented on my code in hard-to-understand areas
- [X] Ran
pnpm build - [X] Ran
pnpm fmt - [X] Checked for warnings, there are none
- [X] Removed all
console.logs - [X] Merged the latest changes from main onto my branch with
git pull origin main - [X] My changes don't cause any responsiveness issues
Appreciated
- [ ] If a UI change was made: Added a screen recording or screenshots to this PR
- [ ] Updated the Unkey Docs if changes were necessary
Summary by CodeRabbit
-
New Features
- Enhanced input validation for updating IP whitelists, now restricted to enterprise plans.
- Introduced new request and response schemas for the key verification process, allowing for more detailed interactions.
-
Bug Fixes
- Improved handling of
ipWhitelistproperty formatting across various tests and services.
- Improved handling of
-
Documentation
- Clarified response type formats for better readability.
-
Tests
- Updated test suites to reflect changes in
ipWhitelisthandling and added new tests for rate limit overrides.
- Updated test suites to reflect changes in
⚠️ No Changeset found
Latest commit: 6915471b756c1e055a50afaa5868c1163e673740
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| dashboard | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 20, 2024 7:22am |
| engineering | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 20, 2024 7:22am |
| play | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 20, 2024 7:22am |
| workflows | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 20, 2024 7:22am |
| www | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 20, 2024 7:22am |
📝 Walkthrough
📝 Walkthrough
Walkthrough
The pull request introduces modifications to the KeyService class, specifically enhancing response type structures and refining the handling of IP whitelisting. Changes include a reformatting of response types for clarity, a simplified approach to parsing the ipWhitelist, and improved readability of the ratelimits object declaration. Additionally, the verifyKey route has been updated to reflect schema changes, including the introduction of a new ratelimits field and modifications to the response structure. The updateApiIpWhitelist function has also been modified to include new validation steps based on workspace features.
Changes
| File Path | Change Summary |
|---|---|
| apps/api/src/pkg/keys/service.ts | Reformatted response types and updated ipWhitelist handling in _verifyKey. Reformatted ratelimits declaration. |
| apps/api/src/routes/v1_keys_verifyKey.ts | Updated request and response schemas, deprecated ratelimit, and added new ratelimits field. Modified response structure. |
| apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts | Enhanced input validation for updateApiIpWhitelist, including checks for workspace ID and plan. |
| apps/dashboard/app/(app)/apis/[apiId]/settings/update-ip-whitelist.tsx | Updated logic for enabling IP whitelist feature based on features instead of plan. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Fix IP Whitelist parsing to avoid 500 errors (#2372) | ✅ |
Possibly related PRs
- #2103: Modifies the
KeyServiceclass, specifically the handling of rate limits, related to changes in the_verifyKeymethod. - #2130: Enhances error messages in the
KeyServiceclass, relevant to the changes made in the main PR that also focuses on theKeyServiceclass and its functionality. - #2062: Adjustments made to the
verifyKeyroute regarding response schemas and handling of rate limits, closely related to the changes in the main PR. - #2076: Introduces rate limiting functionality for TRPC procedures, aligning with the enhancements made in the
KeyService. - #2146: Changes in the
CreateKeycomponent regarding API key management context, relevant to modifications in theKeyService.
Suggested labels
Feature, :joystick: 150 points, hacktoberfest
Suggested reviewers
- mcstepp
- chronark
- perkinsjr
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL
📥 Commits
Files that changed from the base of the PR and between fb1752460c8b880f168dc029291d7a5c810b805a and 6915471b756c1e055a50afaa5868c1163e673740.
📒 Files selected for processing (1)
- apps/api/src/pkg/keys/service.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/api/src/pkg/keys/service.ts
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@Flo4604 is attempting to deploy a commit to the Unkey Team on Vercel.
A member of the Team first needs to authorize it.
Thank you for following the naming conventions for pull request titles! 🙏
I will fix the merge conflict.
Awarding Flo4604: 300 points 🕹️ Well done! Check out your new contribution on oss.gg/Flo4604