Skip to content

[codex] add user token management contract - #36

Merged
klboke merged 4 commits into
apolloconfig:mainfrom
klboke:codex/user-token-management-contract
Jun 15, 2026
Merged

[codex] add user token management contract#36
klboke merged 4 commits into
apolloconfig:mainfrom
klboke:codex/user-token-management-contract

Conversation

@klboke

@klboke klboke commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What changed

This PR adds the Portal user token management endpoints to the OpenAPI contract:

  • GET /openapi/v1/user-tokens
  • POST /openapi/v1/user-tokens
  • DELETE /openapi/v1/user-tokens/{tokenId}
  • POST /openapi/v1/user-tokens/{tokenId}/revoke
  • POST /openapi/v1/user-tokens/{tokenId}/rotate
  • GET /openapi/v1/user-tokens/capabilities
  • GET /openapi/v1/user-tokens/admin
  • DELETE /openapi/v1/user-tokens/admin/{tokenId}
  • POST /openapi/v1/user-tokens/admin/{tokenId}/revoke

The endpoints are tagged as Portal Management so Apollo Portal can implement them through the generated PortalManagementApi interface instead of a separate hand-written web API contract.

Why

Apollo PR apolloconfig/apollo#5632 adds Portal user access tokens. The implementation needs these management endpoints to be represented in the shared OpenAPI contract before Apollo Portal can pin a released spec tag and add generated-interface overrides.

Validation

  • PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/tmp/codex-apollo-openapi-pyyaml python3 -m unittest discover tests
  • ./generate.sh --verify
  • git diff --check

Summary by CodeRabbit

  • New Features
    • Added Portal token management API endpoints to list, create, delete, revoke, rotate tokens, and view the current user’s token-creation capabilities.
    • Added admin-restricted endpoints to list and manage all users’ tokens, including revoke and delete with optional filtering.
    • Introduced Portal session authentication for these new endpoints.
  • Tests
    • Added contract tests to verify operation IDs, security settings, expected status codes, and core response/request schema shapes.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88edf471-6346-48af-9021-3f2aaf7e4152

📥 Commits

Reviewing files that changed from the base of the PR and between d4417a6 and 19472c7.

📒 Files selected for processing (2)
  • apollo-openapi.yaml
  • tests/test_user_token_contract.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • apollo-openapi.yaml
  • tests/test_user_token_contract.py

📝 Walkthrough

Walkthrough

The OpenAPI spec gains nine new endpoints under /openapi/v1/user-tokens for Portal Management: portal-login users can list, create, delete, revoke, rotate tokens, and query capabilities; super-admins get three additional admin endpoints. A PortalSessionAuth cookie-based security scheme is added, along with component schemas for token requests, summaries, and responses. Contract tests validate tags, operationIds, security configuration, and response/request body JSON schema types.

Changes

Portal Management Token Endpoints

Layer / File(s) Summary
Portal user and admin token endpoints with PortalSessionAuth security
apollo-openapi.yaml
Adds GET, POST on /openapi/v1/user-tokens; DELETE, POST /revoke, POST /rotate on /{tokenId}; and GET /capabilities — all tagged "Portal Management" with PortalSessionAuth and 401/403 responses. Also adds GET /admin, DELETE /admin/{tokenId}, and POST /admin/{tokenId}/revoke for super-admins. Defines PortalSessionAuth cookie-based security scheme.
Token operation request/response and capability schemas
apollo-openapi.yaml
Adds OpenCreateUserTokenRequest, OpenUserTokenSummary, OpenCreateUserTokenResponse (with returned tokenValue), OpenRotateUserTokenResponse, and OpenUserTokenCapability schemas used by endpoints.
Contract tests for Portal Management endpoints and schemas
tests/test_user_token_contract.py
Adds test_portal_user_token_management_paths_use_portal_management_contract to assert "Portal Management" tag, expected operationId values per path/method, PortalSessionAuth security requirement, 401/403 response schema refs, endpoint-specific response shapes, and component schema structural constraints.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • apolloconfig/apollo-openapi#35: Extends the same /openapi/v1/user-tokens... capability-related endpoints and schemas with additional portal-authenticated operations.

Suggested reviewers

  • nobodyiam

Poem

🐇 Hop hop, the tokens now dance,
Portal users get create, list, revoke at a glance!
Super-admins too, with filters in hand,
The spec grew longer, exactly as planned.
A contract test seals it, schemas in place—
The rabbit stamps ✅ with a smile on its face!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] add user token management contract' clearly and concisely summarizes the main change: adding user token management endpoints to the OpenAPI contract specification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@klboke
klboke marked this pull request as ready for review June 15, 2026 04:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/test_user_token_contract.py (1)

61-70: ⚡ Quick win

Assert the error contract and array wrapper too.

This test validates tags/operationIds, but it does not enforce the PR’s 403 response contract, and the list response check can pass without proving the top-level schema is an array.

Suggested test hardening
         for path, methods in expected_operations.items():
           for method, operation_id in methods:
             operation = spec["paths"][path][method]
             self.assertEqual(operation_id, operation["operationId"])
             self.assertEqual(["Portal Management"], operation["tags"])
+            self.assertEqual(
+                "`#/components/schemas/ExceptionResponse`",
+                operation["responses"]["403"]["content"]["application/json"]["schema"]["$ref"],
+            )
 
         list_tokens = spec["paths"]["/openapi/v1/user-tokens"]["get"]
+        list_tokens_schema = list_tokens["responses"]["200"]["content"]["application/json"]["schema"]
+        self.assertEqual("array", list_tokens_schema["type"])
         self.assertEqual(
             {"type": "object"},
-            list_tokens["responses"]["200"]["content"]["application/json"]["schema"]["items"],
+            list_tokens_schema["items"],
         )
🤖 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 `@tests/test_user_token_contract.py` around lines 61 - 70, The test validates
operationIds and tags but is missing two important assertions. First, add
assertions to verify the 403 response contract for the error handling introduced
in the PR. Second, strengthen the list_tokens response validation by asserting
not only the items schema but also that the top-level schema itself is an array
type wrapper, so the test cannot pass without proving the complete response
structure matches the contract. Modify the assertions starting from where
list_tokens is defined to include both the 403 error response validation and the
top-level array schema validation for the 200 response.
apollo-openapi.yaml (1)

4907-4910: 🏗️ Heavy lift

Use named schemas instead of anonymous object payloads.

The PR goal is a generated PortalManagementApi contract, but these bodies will generate raw Object/map-like signatures and do not document required token fields. Add reusable component schemas for token summaries, create/rotate responses, create requests, and capabilities, then update tests/test_user_token_contract.py Lines 67-80 to assert those $refs.

Example shape for the contract refactor
                 type: array
                 items:
-                  type: object
+                  $ref: '`#/components/schemas/OpenUserTokenSummary`'
@@
             schema:
-              type: object
+              $ref: '`#/components/schemas/OpenCreateUserTokenRequest`'
@@
               schema:
-                type: object
+                $ref: '`#/components/schemas/OpenCreateUserTokenResponse`'

Also applies to: 4927-4928, 4935-4936, 5011-5012, 5032-5033, 5065-5068

🤖 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 `@apollo-openapi.yaml` around lines 4907 - 4910, Replace the anonymous `type:
object` schema declarations in apollo-openapi.yaml with named reusable component
schemas to properly document the PortalManagementApi contract. Create new
component schemas for token summaries, create/rotate responses, create requests,
and capabilities in the components/schemas section, then replace all instances
of anonymous object payloads (at the locations mentioned in the comment) with
$ref references pointing to these named schemas. Finally, update
tests/test_user_token_contract.py Lines 67-80 to assert that these $ref
references exist in the contract, ensuring the API documentation properly
specifies required token fields rather than generating raw Object/map-like
signatures.
🤖 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.

Inline comments:
In `@apollo-openapi.yaml`:
- Around line 4894-5122: The nine Portal Management operations (listUserTokens,
createUserToken, deleteUserToken, revokeUserToken, rotateUserToken,
getUserTokenCapabilities, adminListUserTokens, adminDeleteUserToken,
adminRevokeUserToken) are currently inheriting the global ApiKeyAuth security
scheme but their descriptions indicate they require Portal login-state access.
Define a new Portal session security scheme in the components/securitySchemes
section, then add an explicit security property to each of these nine operations
to override the inherited global security and apply the Portal session scheme
instead.

---

Nitpick comments:
In `@apollo-openapi.yaml`:
- Around line 4907-4910: Replace the anonymous `type: object` schema
declarations in apollo-openapi.yaml with named reusable component schemas to
properly document the PortalManagementApi contract. Create new component schemas
for token summaries, create/rotate responses, create requests, and capabilities
in the components/schemas section, then replace all instances of anonymous
object payloads (at the locations mentioned in the comment) with $ref references
pointing to these named schemas. Finally, update
tests/test_user_token_contract.py Lines 67-80 to assert that these $ref
references exist in the contract, ensuring the API documentation properly
specifies required token fields rather than generating raw Object/map-like
signatures.

In `@tests/test_user_token_contract.py`:
- Around line 61-70: The test validates operationIds and tags but is missing two
important assertions. First, add assertions to verify the 403 response contract
for the error handling introduced in the PR. Second, strengthen the list_tokens
response validation by asserting not only the items schema but also that the
top-level schema itself is an array type wrapper, so the test cannot pass
without proving the complete response structure matches the contract. Modify the
assertions starting from where list_tokens is defined to include both the 403
error response validation and the top-level array schema validation for the 200
response.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d1aaa551-9a77-43b4-8015-c3fa5edf4b31

📥 Commits

Reviewing files that changed from the base of the PR and between 8496ac6 and 1c8477d.

📒 Files selected for processing (2)
  • apollo-openapi.yaml
  • tests/test_user_token_contract.py

Comment thread apollo-openapi.yaml

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the shared OpenAPI spec to cover Apollo Portal “user access token” management so Apollo Portal can implement the endpoints via the generated PortalManagementApi interface.

Changes:

  • Added Portal-session-authenticated user-token management endpoints under /openapi/v1/user-tokens (including admin variants) tagged Portal Management.
  • Introduced a cookie-based PortalSessionAuth security scheme for Portal Management operations.
  • Added new request/response schemas for creating/rotating tokens and describing token capability/summary, plus contract tests to validate the new paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
apollo-openapi.yaml Adds the new Portal Management user-token endpoints, security scheme, and related schemas.
tests/test_user_token_contract.py Adds contract assertions for operationIds/tags/security and key schema shapes for the new endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apollo-openapi.yaml
Comment thread apollo-openapi.yaml
Comment thread apollo-openapi.yaml
Comment thread tests/test_user_token_contract.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@klboke
klboke merged commit b0b48a0 into apolloconfig:main Jun 15, 2026
5 checks passed
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.

2 participants