Skip to content

Comments

feat: add CreateCurrentUserPersonalToken RPC#443

Open
AmanGIT07 wants to merge 2 commits intomainfrom
feat/create-pat-rpc-proto
Open

feat: add CreateCurrentUserPersonalToken RPC#443
AmanGIT07 wants to merge 2 commits intomainfrom
feat/create-pat-rpc-proto

Conversation

@AmanGIT07
Copy link
Contributor

@AmanGIT07 AmanGIT07 commented Feb 19, 2026

Summary by CodeRabbit

  • New Features
    • Users can create personal access tokens with configurable expiration and role-based permissions.
    • Tokens surface usage tracking (last-used) and creation timestamps for improved security and auditing.
    • Tokens support associated metadata and scoped project access for finer-grained control.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

📝 Walkthrough

Walkthrough

Adds a Personal Access Token flow to Frontier: a new RPC CreateCurrentUserPersonalToken(CreateCurrentUserPersonalTokenRequest) returns (CreateCurrentUserPersonalTokenResponse) and a PersonalAccessToken message with identity, token, metadata, expiry, last-used, and creation timestamps.

Changes

Cohort / File(s) Summary
Frontier service API
raystack/frontier/v1beta1/frontier.proto
Adds RPC CreateCurrentUserPersonalToken(CreateCurrentUserPersonalTokenRequest) returns (CreateCurrentUserPersonalTokenResponse) and the new request/response message types (fields: title, org_id, roles, project_ids, expires_at, metadata; response contains PersonalAccessToken).
Models
raystack/frontier/v1beta1/models.proto
Introduces PersonalAccessToken message with id, title, token (OUTPUT_ONLY), expires_at, last_used_at, created_at, and metadata (google.protobuf.Struct).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇✨ I hopped in with a nibble and a note,
A token tucked under my coat,
With title, time, and metadata true,
I guard the burrow — just for you.
Hop, click, create — the keys anew! 🔐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a new CreateCurrentUserPersonalToken RPC endpoint to the Frontier API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/create-pat-rpc-proto

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
raystack/frontier/v1beta1/frontier.proto (1)

4264-4268: name has only a length floor; no pattern constraint for a machine-friendly identifier.

The inline comment says this is a "Machine-friendly identifier, unique per user per org", yet the only validation is min_len = 1, which permits arbitrary whitespace, special characters, and single-character names. Every comparable name field for machine identifiers in this codebase enforces a pattern (e.g., ^[A-Za-z0-9-_]+$ for User, Group, Organization, etc.).

✏️ Suggested constraint
  string name = 1 [
-   (validate.rules).string.min_len = 1,
+   (validate.rules).string = {
+     min_len: 2,
+     pattern: "^[A-Za-z0-9-_]+$"
+   },
    (google.api.field_behavior) = REQUIRED
  ];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@raystack/frontier/v1beta1/frontier.proto` around lines 4264 - 4268, The
`name` field in frontier.proto currently only enforces min_len and should also
include a pattern to restrict it to machine-friendly characters; update the
`name` field's validation (the same field named "name" in frontier.proto) to add
a regex constraint such as `^[A-Za-z0-9-_]+$` (while keeping or adjusting
min_len as needed) so it matches other machine identifier fields in the
codebase; ensure the `(validate.rules).string.pattern` is added alongside the
existing `(validate.rules).string.min_len` and keep the
`(google.api.field_behavior) = REQUIRED` intact.
raystack/frontier/v1beta1/models.proto (1)

443-444: Consider adding an OpenAPI description and validation hint for name.

The name field (field 2) has no openapiv2_field description or validation annotation, unlike comparable name fields across every other model in this file (e.g., User.name, Group.name). API consumers won't know what format/constraints to expect.

✏️ Suggested addition
- string name = 2;
+ string name = 2 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
+   description: "Machine-friendly identifier for the token. Must be unique per user per organization.",
+   example: "\"my-ci-token\""
+ }];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@raystack/frontier/v1beta1/models.proto` around lines 443 - 444, Add an
OpenAPI description and validation hint for the message's `name` field (field 2)
similar to other models like `User.name` and `Group.name`: update the `name`
field to include an openapiv2_field description explaining expected format
(e.g., display name, allowed chars/length) and add proto validation rules (e.g.,
non-empty, max length, and optional pattern) so API consumers know constraints;
target the `name` field (field number 2) and mirror the same description and
validate.rules options used by `User.name`/`Group.name`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@raystack/frontier/v1beta1/frontier.proto`:
- Line 4278: The repeated field project_ids currently accepts arbitrary strings;
add the same UUID validation used elsewhere by attaching a validate.rules option
to project_ids (e.g., on the repeated string field declaration for project_ids)
so each item is required to be a UUID; update the field definition for
project_ids to include (validate.rules).string.uuid = true for each element to
ensure boundary validation consistent with org_id and other ID fields.
- Around line 4275-4276: The repeated field roles (repeated string roles = 4) is
annotated as (google.api.field_behavior) = REQUIRED but that does not enforce a
non-empty list at runtime; update the field to add a validator rule by adding
(validate.rules).repeated = { min_items: 1 } to the roles field so the proto
validator enforces at least one role (mirror the user_ids validation pattern
used in CreateOrganizationInvitationRequest).
- Around line 1891-1892: CreateCurrentUserPersonalToken is missing the
grpc-gateway HTTP binding and openapiv2_operation annotations, so add a
google.api.http POST binding and an openapiv2_operation block analogous to other
CurrentUser RPCs (e.g., use POST "/v1beta1/users/me/personal_tokens" with body
"*" or the appropriate request field) and include openapiv2_operation with
operation_id "CreateCurrentUserPersonalToken" plus a short summary/description;
update the RPC declaration for CreateCurrentUserPersonalToken to include these
annotations so it is reachable via REST and appears in the OpenAPI spec.

---

Nitpick comments:
In `@raystack/frontier/v1beta1/frontier.proto`:
- Around line 4264-4268: The `name` field in frontier.proto currently only
enforces min_len and should also include a pattern to restrict it to
machine-friendly characters; update the `name` field's validation (the same
field named "name" in frontier.proto) to add a regex constraint such as
`^[A-Za-z0-9-_]+$` (while keeping or adjusting min_len as needed) so it matches
other machine identifier fields in the codebase; ensure the
`(validate.rules).string.pattern` is added alongside the existing
`(validate.rules).string.min_len` and keep the `(google.api.field_behavior) =
REQUIRED` intact.

In `@raystack/frontier/v1beta1/models.proto`:
- Around line 443-444: Add an OpenAPI description and validation hint for the
message's `name` field (field 2) similar to other models like `User.name` and
`Group.name`: update the `name` field to include an openapiv2_field description
explaining expected format (e.g., display name, allowed chars/length) and add
proto validation rules (e.g., non-empty, max length, and optional pattern) so
API consumers know constraints; target the `name` field (field number 2) and
mirror the same description and validate.rules options used by
`User.name`/`Group.name`.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
raystack/frontier/v1beta1/models.proto (1)

442-466: Consider adding reserved for intentionally skipped field numbers.

The message has deliberate gaps — 3-4 (between title and token), 6-9 (between token and expires_at), and 13-19 (between created_at and metadata) — with no reserved statement to document them. Without reserved, future contributors can silently reuse those numbers, causing silent wire-format collisions with any data serialized against later versions of this message.

♻️ Proposed addition
 message PersonalAccessToken {
   string id = 1;
   string title = 2;
+
+  reserved 3, 4;
+
   // token will only be returned once as part of the create process
   // this value is never persisted in the system so if lost, can't be recovered
   string token = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
+
+  reserved 6 to 9;

   google.protobuf.Timestamp expires_at = 10 [...];
   google.protobuf.Timestamp last_used_at = 11 [...];
   google.protobuf.Timestamp created_at = 12 [...];
+
+  reserved 13 to 19;

   google.protobuf.Struct metadata = 20;
 }

The rest of the message — the OUTPUT_ONLY annotation on token, the expires_at/last_used_at/created_at grouping, and metadata = 20 — all follow established file conventions and look correct.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@raystack/frontier/v1beta1/models.proto` around lines 442 - 466, The
PersonalAccessToken message is missing reserved declarations for the
intentionally skipped field numbers; add a reserved statement in the
PersonalAccessToken message reserving the numeric ranges 3 to 4, 6 to 9, and 13
to 19 (e.g., reserved 3 to 4, 6 to 9, 13 to 19;) so future changes cannot reuse
those tags and cause wire-format collisions; place this reserved line near the
top of the message alongside the field declarations for clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@raystack/frontier/v1beta1/models.proto`:
- Around line 442-466: The PersonalAccessToken message is missing reserved
declarations for the intentionally skipped field numbers; add a reserved
statement in the PersonalAccessToken message reserving the numeric ranges 3 to
4, 6 to 9, and 13 to 19 (e.g., reserved 3 to 4, 6 to 9, 13 to 19;) so future
changes cannot reuse those tags and cause wire-format collisions; place this
reserved line near the top of the message alongside the field declarations for
clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant