feat: implement UpdateCurrentUserPAT RPC by AmanGIT07 · Pull Request #1467 · raystack/frontier
Warning
Rate limit exceeded
@AmanGIT07 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 22 seconds before requesting another review.
⌛ How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.
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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8ebe78c1-5c98-4db6-bc0c-c3ad07b304ce
📒 Files selected for processing (1)
internal/api/v1beta1connect/user_pat_test.go
📝 Walkthrough
Walkthrough
This PR adds Personal Access Token (PAT) update functionality across the stack: repository interface and PostgreSQL implementation, service layer with validation and policy management, Connect RPC handler with error mapping, proto message validation, interface mocks, and audit event tracking. The Makefile's PROTON_COMMIT hash is updated to enable proto regeneration.
Changes
| Cohort / File(s) | Summary |
|---|---|
Core PAT Service Layer core/userpat/service.go, core/userpat/service_test.go, core/userpat/userpat.go, core/userpat/mocks/repository.go |
Added Service.Update() method with validation, role resolution, policy replacement, and audit logging. Introduced helper methods (getOwnedPAT, captureOldScope, replacePolicies, auditUpdate). Extended repository interface with Update() and added mock implementation. Comprehensive test coverage for success and error scenarios. |
API Handler & Interface Mocks internal/api/v1beta1connect/user_pat.go, internal/api/v1beta1connect/user_pat_test.go, internal/api/v1beta1connect/interfaces.go, internal/api/v1beta1connect/mocks/user_pat_service.go |
Added UpdateCurrentUserPAT RPC handler with authentication, validation, error mapping to Connect codes, and audit logging. Extended UserPATService interface and created mock implementation. Handler tests verify error cases and success flow with correct response transformation. |
Proto & Generated Code proto/v1beta1/frontier.pb.validate.go, proto/v1beta1/frontierv1beta1connect/frontier.connect.go |
Generated validation for UpdateCurrentUserPATRequest (UUID, title, role/project IDs) and UpdateCurrentUserPATResponse. Generated Connect RPC procedure constant, client/handler interfaces, and unimplemented handler stub. |
Database Layer internal/store/postgres/userpat_repository.go |
Added Update() method that persists PAT title and metadata changes, includes TOCTOU safety via RETURNING clause, and maps SQL errors to domain-specific error types (ErrNotFound, ErrConflict). |
Audit & Security Configuration pkg/auditrecord/consts.go, pkg/server/connect_interceptors/authorization.go, Makefile |
Added PATUpdatedEvent audit event constant. Added UpdateCurrentUserPAT endpoint to authorization skip list. Updated PROTON_COMMIT hash for proto regeneration. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs
- feat: CreateCurrentUserPAT RPC implementation #1401: Implements CreateCurrentUserPAT with overlapping PAT API surface, service layer patterns, and Connect handler design.
- feat: PAT authentication chain, token validation, and error handling #1442: Modifies PAT repository methods and mocks, sharing the same repository layer changes and mock patterns.
- feat: implement GetCurrentUserPAT RPC #1450: Updates PROTON_COMMIT variable and adds PAT-related RPC modifications in the same areas.
Suggested reviewers
- rohilsurana
- whoAbhishekSah
📝 Coding Plan
- Generate coding plan for human review comments
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 @coderabbitai help to get the list of available commands and usage tips.